Skip to content

feat: add keymaps for moving lines#9

Open
kexposito wants to merge 5 commits intomainfrom
add-keymaps
Open

feat: add keymaps for moving lines#9
kexposito wants to merge 5 commits intomainfrom
add-keymaps

Conversation

@kexposito
Copy link
Copy Markdown
Collaborator

@kexposito kexposito commented Mar 22, 2024

This pull request includes:

  • Removing vim-unpaired keymaps override for moving lines and use commands for it

Comment thread lua/keymaps.lua Outdated
Comment on lines +1 to +5
-- 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" })
Copy link
Copy Markdown
Collaborator Author

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

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Collaborator

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 ?

Copy link
Copy Markdown
Collaborator Author

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

alacritty/alacritty#4048

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Collaborator

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>.

Copy link
Copy Markdown
Collaborator Author

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 for K
  • <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

Copy link
Copy Markdown
Collaborator

@grzuy grzuy Apr 5, 2024

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>.

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kexposito thoughts about my last comment?

@kexposito kexposito changed the title Add keymaps feat: add keymaps Mar 22, 2024
Copy link
Copy Markdown
Collaborator

@grzuy grzuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you!

Comment thread lua/keymaps.lua Outdated
Comment on lines +1 to +5
-- 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" })
Copy link
Copy Markdown
Collaborator

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.

Comment thread 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" })
Copy link
Copy Markdown
Collaborator

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.

Comment thread lua/keymaps.lua Outdated
Comment thread init.lua Outdated
@grzuy
Copy link
Copy Markdown
Collaborator

grzuy commented Mar 22, 2024

Conflicts in README after I merged #4 , sorry bout that 😝

@kexposito kexposito changed the title feat: add keymaps feat: add keymaps for moving lines Mar 24, 2024
@grzuy
Copy link
Copy Markdown
Collaborator

grzuy commented Nov 24, 2025

solved conflits with main

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

Successfully merging this pull request may close these issues.

2 participants