mizlan / iswap.nvim Goto Github PK
View Code? Open in Web Editor NEWInteractively select and swap function arguments, list elements, and much more. Powered by tree-sitter.
License: MIT License
Interactively select and swap function arguments, list elements, and much more. Powered by tree-sitter.
License: MIT License
As the title says. Technically the first/only other option is always going to be a
(or the first configured hint key), but we can still cut it out i think.
Hi, I'm using nvim-treesitter-textobjects
which allows to define mappings to swap with prev/next parameters. But it doesn't allow to swap in arbitrary list like iswap
does.
It would be nice if iswap
could support this feature.
It would be nice if the GIF showed keypresses. I think we'd have to use something other than asciicast for that to work.
See the screenshot below please
Nvim version I am using: the latest nightly
I think this issue is caused by this commit in nvim-treesitter nvim-treesitter/nvim-treesitter@c3848e7
Thank you.
Im getting this error when trying to use Iswap
E5108: Error executing lua vim/shared.lua:64: s: expected string, got nil
stack traceback:
vim/shared.lua:64: in function 'gsplit'
vim/shared.lua:111: in function 'split'
...cker/opt/nvim-treesitter/lua/nvim-treesitter/parsers.lua:719: in function 'ft_to_lang'
...m/site/pack/packer/opt/iswap.nvim/lua/iswap/internal.lua:19: in function 'find'
...m/site/pack/packer/opt/iswap.nvim/lua/iswap/internal.lua:37: in function 'get_list_node_at_cursor'
...share/nvim/site/pack/packer/opt/iswap.nvim/lua/iswap.lua:80: in function 'iswap_with'
[string ":lua"]:1: in main chunk
public function getAnswer(string $question, int $test)
{
return match ($question) {
'starships' => $this->getStarships()
};
}
If the cursor is on a character in string
or int
on either parameter, the entire parameter and type get swapped as expected. However, if the cursor is on the variable name (not the $
), then nothing happens.
Curiously, when the cursor is on the $
in int $test
and I swap right, nothing happens (makes sense), but if I swap left, then the it changes places with int
.
It would be nice if commands like :ISwapNodeWithLeft
could be made dot repeatable.
Part of packer.nvim
set up:
use {
"mizlan/iswap.nvim",
config = function()
require("iswap").setup {
-- The keys that will be used as a selection, in order
-- ('asdfghjklqwertyuiopzxcvbnm' by default)
keys = "qwertyuiop",
-- Grey out the rest of the text when making a selection
-- (enabled by default)
grey = "disable",
-- Highlight group for the sniping value (asdf etc.)
-- default 'Search'
hl_snipe = "ErrorMsg",
-- Highlight group for the visual selection of terms
-- default 'Visual'
hl_selection = "WarningMsg",
-- Highlight group for the greyed background
-- default 'Comment'
hl_grey = "LineNr",
-- Automatically swap with only two arguments
-- default nil
autoswap = true,
}
end,
requires = "nvim-treesitter/nvim-treesitter",
}
leads to, upon the start of neovim
:
Error detected while processing /home/derek/.local/share/nvim/site/pack/packer/start/iswap.n
vim/plugin/iswap.vim:
line 1:
E5108: Error executing lua [string ":lua"]:1: loop or previous error loading module 'iswap'
Press ENTER or type command to continue
Is this some sort of import cycle? If so, how does some start to debug?
Hi! thanks for the awesome plugin.
Could you add the ability to swap current item with next / previous without showing keystrokes? This is how it works in vim-swap.
It would be great if we could swap functions, classes too (depending on where cursor is) . Not sure how much work it would be.
BTW. love the UI for this. Reminds me of https://github.com/mfussenegger/nvim-treehopper which is my fav plug for treesitter nodes selections/management.
I'm rewriting the git history to remove the assets/
folder, which contained a nontrivially-sized video and GIFs. The fix should simply to delete the plugin folder and install again; nothing should break if you do that :)
If you have a fork of this for some reason, you should not have any trouble rebasing. I've only rewritten the history for assets/
.
I think the visual effect of a window with blend
is better than grey out. I am happy to do a PR for this feature.
Instead of having to use
ensure_installed = { 'bash', 'c', 'cpp', 'julia', 'lua', 'python', 'rust', 'typescript', 'vim', 'vimdoc', 'zig' },
auto_install = true,
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
..
disable = { 'c', 'cpp', 'zig' },
},
incremental_selection = {
enable = true,
keymaps = {
..
disable = { 'c', 'cpp', 'zig' }, -- slow, so opt-in
},
},
indent = {
enable = true,
disable = { 'c', 'cpp', 'python', 'zig' }, -- broken
},
}
require('iswap').setup {}
I would prefer
ensure_installed = { 'bash', 'c', 'cpp', 'julia', 'lua', 'python', 'rust', 'typescript', 'vim', 'vimdoc', 'zig' },
auto_install = true,
highlight = {
enable = true,
additional_vim_regex_highlighting = false,
..
disable = { 'c', 'cpp', 'zig' },
},
incremental_selection = {
enable = true,
keymaps = {
..
disable = { 'c', 'cpp', 'zig' }, -- slow, so opt-in
},
},
indent = {
enable = true,
disable = { 'c', 'cpp', 'python', 'zig' }, -- broken
},
iswap = {
enable = true,
disable = { 'c', 'cpp', 'zig' },
},
}
Justification:
nvim gcc/c-family/c-common.cc
from git://gcc.gnu.org/git/gcc.git freezes editor due to treesitter and generally one must be able to workaround not well written parsers via run-time opt-in until nvim-treesitter can handle those cases of treesitter misbehaving.
The user could hack around via checking file types, but that is a not good user experience.
The following option is set: move_cursor = true
Now I'm editing a lua
file with the following content (cursor is at the |
position):
cmd = {
'ISwap',
'ISwapWith',
'ISwapNode',
| 'ISwapNodeWith',
'ISwapWithLeft',
'ISwapWithRight',
'ISwapNodeWithLeft',
'ISwapNodeWithRight',
}
Then I run the ex command :ISwapNodeWithLeft
and I get the following error:
E5108: Error executing lua /Users/tummetott/Projects/iswap.nvim/lua/iswap/internal.lua:160: Column value outside range
stack traceback:
[C]: in function 'nvim_win_set_cursor'
/Users/tummetott/Projects/iswap.nvim/lua/iswap/internal.lua:160: in function 'swap_nodes_and_return_new_ranges'
/Users/tummetott/Projects/iswap.nvim/lua/iswap.lua:155: in function 'iswap_node_with'
[string ":lua"]:1: in main chunk
It seems like the nvim_win_set_cursor()
errors because the range is not sanity checked. Running it silent could also solve the error. What do you think?
x Tummetott
CI/lint
They probably updated the parser and now the nodes are named something different. I'll take a stab at fixing it tomorrow.
If autoswap = true
and the item size of the list is 2, I hardly know whether the items have been swapped.
I want to highlight the swapped items like vim.highlight.on_yank
. Maybe IncSearch
and Search
group for the swapped items are not bad:)
Would be cool to see a feature where you could sort the items rather than doing it manually.
highlight should be able to be array, which is colors to cycle (better to distinguish especially with iswapnode)
Sometimes my lsp serveur crash and I have to restart it with LspRestart
. When I do, I get this following error in my messages
.
Error executing vim.schedule lua callback: ...pack/paqs/start/nvim-lspconfig/lua/lspconfig/configs.lua:253: bad argument #1 to 'ipairs' (table expected, got
nil)
stack traceback:
[C]: in function 'ipairs'
...pack/paqs/start/nvim-lspconfig/lua/lspconfig/configs.lua:253: in function 'try_add_wrapper'
...pack/paqs/start/nvim-lspconfig/lua/lspconfig/configs.lua:103: in function 'launch'
...im/site/pack/paqs/start/nvim-lspconfig/lua/lspconfig.lua:58: in function 'fn'
vim.lua:415: in function 'cb'
vim.lua:285: in function <vim.lua:285>
Thanks for this great extension!
It would be nice if we could change the cursor position to the new position of the node. So for example when you start with:
a, b
( shows the cursor position)
and swap right, it would result in:
b, _a
instead of
_b, a
For reference vim-swap works like this.
I think it just makes sense, and I have found myself wanted to swap lines of code sometimes.
Could also fallback ISwap -> ISwapNode
and ISwapWith -> ISwapNodeWith
instead but I think this has much less utility.
I wonder if it would be possible to add an IMove
command that has a similar interface but moves the node before or after another node. We might want to add labels in between nodes rather than on, including on at the end and beginning of the 'list'
local blah = {
{ 2, 1, 6 },
{ 3, 4, 6 },
{ 3, 4, 6 },
}
If i have nested lists like this, I don't think there is anywhere to place the cursor that would make ISwapWith work with the outer list. In fact, placing the cursor on the braces of one of the inner lists makes iswap think we're trying to work on the inner list (because technically the cursor is contained within the inner list.
Even if this is fixed to work I think the nicer solution is to allow ISwapWith from visual mode and then ISwapWith will try its best to treat the visual range as the cur_node. Basically ignore lists that are contained within the visual range, or if the visual range covers multiple children of a list then we shouldn't operate within that list.
I've actually already started the implementation for a PR but I wanted to post this for discussion and if you agree with the solution?
Either add on to existing queries or add support for new languages. Relevant queries can be found using playground. See existing queries for examples (Rust is a good example).
I would like to use your plugin with R, but when calling :ISwapWith it tells me "Cannot query this filetype".
Is it possible to extend this to R?
When using move_cursor
option with :ISwap*With*
, it should be preferred to stick to the original cursor location of the node instead of going to the beginning.
It should be possible to remember to the relative location of the cursor of the node and apply that later on.
Leap has a good handling of jumps and labels, maybe use it as a dependency?
Hi. Thanks for this useful plugin.
I would like to have a similar functionality to delete an argument, element in the list or parameter.
Would it be possible to implement something like this ?
Thanks.
vim help doc
:ISwap
:ISwapWith
setup{}
Hello there,
Thanks for that plugin, I love it.
Only problem I have is I cannot execute the command more than once per line.
I have to reload the file every time I want to do a swap on the same line. Is that expected?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.