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
feat: add keymaps for moving lines #9
base: main
Are you sure you want to change the base?
Conversation
…oving around windows
lua/keymaps.lua
Outdated
-- Move current line/s under cursor up or down | ||
vim.keymap.set("n", "J", ":m .+1<CR>==", { desc = "Move current line down" }) | ||
vim.keymap.set("n", "K", ":m .-2<CR>==", { desc = "Move current line up" }) | ||
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv", { desc = "Move current line down" }) | ||
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv", { desc = "Move current line up" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@grzuy Tried this using <C-up/donw>
but seems that this it's a mac keybinding. We should check which behavior do we want here, Overriding mac's keybindings or use another one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, good call.
We need to find some other mapping though, K
is now default for LSP hover documention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can go with <A-j>
and <A-k>
like in the examples in https://vim.fandom.com/wiki/Moving_lines_up_or_down#Mappings_to_move_lines ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found that using "Alt" on Mac can be really tricky, and we should allow some terminal emulators (iterm2, kitty, etc) to allow the use of it, Im thinking which others kemaps we can use for these
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related LazyVim/LazyVim#2571?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://stackoverflow.com/questions/9450905/how-to-bind-vim-through-tmux-to-cmd-key/9451636#9451636
If we can't find a good workaround, maybe the most sane option is to use <Leader>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since seems that we can't use
<C-Up/Down>
because of terminal remaps.J/K
because we have already a remap forK
<C-j/k>
because we have another PR that introduce moving around windows with those remaps
Another alternative can be <S-Up/Down>
. We can also try with leader as you mentioned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<S-Up/Down>
is already taken by nvim to scroll window.
Can be seen with :help <S-Up>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would the same workaround from LazyVim/LazyVim#2571 make <A-j>
and <A-k>
work for you also?
If so, maybe we can go with that and use the same keymaps LazyVim uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thank you!
lua/keymaps.lua
Outdated
-- Move current line/s under cursor up or down | ||
vim.keymap.set("n", "J", ":m .+1<CR>==", { desc = "Move current line down" }) | ||
vim.keymap.set("n", "K", ":m .-2<CR>==", { desc = "Move current line up" }) | ||
vim.keymap.set("v", "J", ":m '>+1<CR>gv=gv", { desc = "Move current line down" }) | ||
vim.keymap.set("v", "K", ":m '<-2<CR>gv=gv", { desc = "Move current line up" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha, good call.
We need to find some other mapping though, K
is now default for LSP hover documention.
lua/keymaps.lua
Outdated
@@ -0,0 +1,11 @@ | |||
-- Move current line/s under cursor up or down | |||
vim.keymap.set("n", "J", ":m .+1<CR>==", { desc = "Move current line down" }) | |||
vim.keymap.set("n", "K", ":m .-2<CR>==", { desc = "Move current line up" }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice!
This coming from https://vim.fandom.com/wiki/Moving_lines_up_or_down?
We could add the source in a comment, given it has good explanation for the mappings.
Conflicts in README after I merged #4 , sorry bout that 😝 |
This pull request includes: