Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swap didn't work #17

Open
edte opened this issue May 30, 2024 · 9 comments
Open

swap didn't work #17

edte opened this issue May 30, 2024 · 9 comments

Comments

@edte
Copy link

edte commented May 30, 2024

nvim version

$ nvim -v
NVIM v0.10.0
Build type: Release
LuaJIT 2.1.1713773202
Run "nvim -V1 -v" for more info

plugin version

image

plugin configuration

i use lazy.nvim plugin manager

	{
		"Wansmer/sibling-swap.nvim",
		dependencies = { "nvim-treesitter" },
		config = function()
			require("sibling-swap").setup({
				allowed_separators = {
					",",
					":",
					";",
					"and",
					"or",
					"&&",
					"&",
					"||",
					"|",
					"==",
					"===",
					"!=",
					"!==",
					"-",
					"+",
					["<"] = ">",
					["<="] = ">=",
					[">"] = "<",
					[">="] = "<=",
				},
				use_default_keymaps = true,
				-- Highlight recently swapped node. Can be boolean or table
				-- If table: { ms = 500, hl_opts = { link = 'IncSearch' } }
				-- `hl_opts` is a `val` from `nvim_set_hl()`
				highlight_node_at_cursor = true,
				-- keybinding for movements to right or left (and up or down, if `allow_interline_swaps` is true)
				-- (`<C-,>` and `<C-.>` may not map to control chars at system level, so are sent by certain terminals as just `,` and `.`. In this case, just add the mappings you want.)
				keymaps = {
					["<C-.>"] = "swap_with_right",
					["<C-,>"] = "swap_with_left",
					["<space>."] = "swap_with_right_with_opp",
					["<space>,"] = "swap_with_left_with_opp",
				},
				ignore_injected_langs = false,
				-- allow swaps across lines
				allow_interline_swaps = true,
				-- swaps interline siblings without separators (no recommended, helpful for swaps html-like attributes)
				interline_swaps_without_separator = false,
				-- Fallbacs for tiny settings for langs and nodes. See #fallback
				fallback = {},
			})
		end,
	},

Swap doesn't work

2024-05-30.11.54.22.mov
@Wansmer
Copy link
Owner

Wansmer commented May 30, 2024

I can't reproduce it.

Did this happen with minimal config (just clean nvim and sibling-spaw only)?
What is the output of :map <C-.>/:map <C-,>?

@edte
Copy link
Author

edte commented May 30, 2024

minimal config

-- **DO NOT change the paths and don't remove the colorscheme**
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
	vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
	vim.fn.system({ "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", lazypath })
end
vim.opt.runtimepath:prepend(lazypath)

vim.cmd.color("elflord")
--------------------------------------------------------------------------------
local plugins = {
	{
		"Wansmer/sibling-swap.nvim",
		dependencies = "nvim-treesitter/nvim-treesitter",
		config = function()
			require("sibling-swap").setup({
				allowed_separators = {
					",",
					":",
					";",
					"and",
					"or",
					"&&",
					"&",
					"||",
					"|",
					"==",
					"===",
					"!=",
					"!==",
					"-",
					"+",
					["<"] = ">",
					["<="] = ">=",
					[">"] = "<",
					[">="] = "<=",
				},
				use_default_keymaps = true,
				-- Highlight recently swapped node. Can be boolean or table
				-- If table: { ms = 500, hl_opts = { link = 'IncSearch' } }
				-- `hl_opts` is a `val` from `nvim_set_hl()`
				highlight_node_at_cursor = true,
				-- keybinding for movements to right or left (and up or down, if `allow_interline_swaps` is true)
				-- (`<C-,>` and `<C-.>` may not map to control chars at system level, so are sent by certain terminals as just `,` and `.`. In this case, just add the mappings you want.)
				keymaps = {
					["<C-.>"] = "swap_with_right",
					["<C-,>"] = "swap_with_left",
					["<space>."] = "swap_with_right_with_opp",
					["<space>,"] = "swap_with_left_with_opp",
				},
				ignore_injected_langs = false,
				-- allow swaps across lines
				allow_interline_swaps = true,
				-- swaps interline siblings without separators (no recommended, helpful for swaps html-like attributes)
				interline_swaps_without_separator = false,
				-- Fallbacs for tiny settings for langs and nodes. See #fallback
				fallback = {},
			})
		end,
	},
}

require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

output:

image image

not work

nvim -u a.lua main.go
2024-05-30.18.27.22.mov

@Wansmer
Copy link
Owner

Wansmer commented May 30, 2024

Looks like you just did not install the parser for go. Run :TSInstall go.

@edte
Copy link
Author

edte commented May 30, 2024

actually I have already installed it,Already restarted

2024-05-30.20.21.34.mov

@Wansmer
Copy link
Owner

Wansmer commented May 30, 2024

Does this happen if you change the mappings? Some terminals may not handle CTRL keys correctly.

I run minimal config with the same Neovim version and everything works correct. (kitty/iTerm2)

@edte
Copy link
Author

edte commented May 31, 2024

I use kitty terminal then I tried changing the shortcut key to ctrl+1 or alt+1 but it didn't work.

@Wansmer
Copy link
Owner

Wansmer commented May 31, 2024

So far I have no idea why plugin doesn't work. I can't reproduce this bug under the same conditions.

Try calling the plugin directly: lua require('sibling-swap').swap_with_right() being on the first argument in fmt.Println. If it works, then the problem is in the mappings on your system. If it doesn't, we'll look into it further.

@dlyongemallo
Copy link

I also had trouble with the keymaps field in the config, but I was able to get the keymaps to work using nvim_set_keymap.

@edte Can you try the following?

vim.api.nvim_set_keymap("n", "<a-2>", "<cmd>lua require('sibling-swap').swap_with_right()<CR>")
vim.api.nvim_set_keymap("n", "<a-1>", "<cmd>lua require('sibling-swap').swap_with_left()<CR>")

(Another useful thing to try is the WhichKey plugin. Running ":WhichKey" will let you know if your keymapping was successful or not, so you can rule out if that's the cause of the problem.)

@mario-amazing
Copy link

@edte if you are using iTerm, then you need to turn off this setting
Screenshot 2024-11-27 at 13 51 08
Or use mapping above:

vim.api.nvim_set_keymap("n", "<a-2>", "<cmd>lua require('sibling-swap').swap_with_right()<CR>")
vim.api.nvim_set_keymap("n", "<a-1>", "<cmd>lua require('sibling-swap').swap_with_left()<CR>")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants