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

feat: add keymaps for moving lines #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

feat: add keymaps for moving lines #9

wants to merge 4 commits into from

Conversation

kexposito
Copy link
Collaborator

@kexposito kexposito commented Mar 22, 2024

This pull request includes:

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

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

@kexposito kexposito changed the title Add keymaps feat: add keymaps Mar 22, 2024
Copy link
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!

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

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

lua/keymaps.lua Outdated Show resolved Hide resolved
init.lua Outdated Show resolved Hide resolved
@grzuy
Copy link
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
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.

None yet

2 participants