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

docs(faq): Clean up cmd-c/cmd-v keymap examples #2101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lkhphuc
Copy link

@lkhphuc lkhphuc commented Nov 4, 2023

What kind of change does this PR introduce?

  • Documentation

Did this PR introduce a breaking change?

  • No

Clean up the mapping for copy and paste, also add the terminal mode mapping.

@fredizzimo
Copy link
Member

fredizzimo commented Nov 4, 2023

Thanks, yes there seem to have been some unnecessary duplication there.

But I think we should make this section "cross-platform", currently it's only targeted to mac users, but on Windows and Linux you might want to use either C-c (native mapping in most applications) or S-C-c (the console usually requires shift) for copying and similarly C-v or S-C-v for pasting.

For example this question was asked yesterday #2099

@9mm
Copy link
Contributor

9mm commented Dec 23, 2023

I don't have the mental bandwidth to verify what's written here, but when I did this myself I spent WEEKS trying to sort it out.. but here's what I ultimately ended up with if this helps...

I actually was going to edit the docs myself, but theres so many subtle special cases that I actually abandoned that idea. I figured maybe it's better to leave at something simple rather than trying to make it more advanced but with more edge cases.

These are OSX only

  -- command mapping
  vim.keymap.set({ "i", "n" }, "<D-a>", "<Esc>ggVG")                              -- select all
  vim.keymap.set({ "i", "n" }, "<D-w>", function() confirm_close_tab() end)       -- close tab
  vim.keymap.set({ "i", "n" }, "<D-[>", function() vim.cmd("BufferPrevious") end) -- previous tab
  vim.keymap.set({ "i", "n" }, "<D-]>", function() vim.cmd("BufferNext") end)     -- next tab
  vim.keymap.set("i", "<D-t>", "<C-o>:tabnew<CR><Esc>")                           -- new tab (insert)
  vim.keymap.set("n", "<D-t>", ":tabnew<CR>")                                     -- new tab (insert)
  vim.keymap.set("i", "<D-s>", "<C-o>:w<CR>")                                     -- save (insert)
  vim.keymap.set("n", "<D-s>", ":w<CR>")                                          -- save (normal)
  vim.keymap.set("x", "<D-x>", '"+dm0i<Esc>`0')                                   -- cut (include insert hack to fix whichkey issue #518)
  vim.keymap.set("x", "<D-c>", '"+y')                                             -- copy
  vim.keymap.set("i", "<D-v>", "<C-r><C-o>+")                                     -- paste (insert)
  vim.keymap.set("n", "<D-v>", "i<C-r><C-o>+<Esc>l")                              -- paste (normal)
  vim.keymap.set("x", "<D-v>", '"+P')                                             -- paste (visual)
  vim.keymap.set("c", "<D-v>", "<C-r>+")                                          -- paste (command)
  vim.keymap.set("n", "<D-z>", "u")                                               -- undo
  vim.keymap.set({ "i", "n" }, "<D-q>", function() vim.cmd("confirm qa") end)     -- quit

@falcucci
Copy link
Member

vim.keymap.set("i", "<D-v>", "<C-r><C-o>+")                                     -- paste (insert)
vim.keymap.set("n", "<D-v>", "i<C-r><C-o>+<Esc>l")                              -- paste (normal)
vim.keymap.set("x", "<D-v>", '"+P')                                             -- paste (visual)
vim.keymap.set("c", "<D-v>", "<C-r>+")                                          -- paste (command)

@9mm did you manage to paste on terminal and float window mode using these?

@9mm
Copy link
Contributor

9mm commented Jan 29, 2024

@falcucci no, but i think that might be solved by changing the "i" and "n" stuff, because i forgot what it is but I think terminal mode has its own mode... t perhaps? i cant remember off top of head, but you could make it {"x", "t"}, maybe try that

@falcucci
Copy link
Member

@9mm thank you, but didn't work. gonna look better in the docs

@lkhphuc
Copy link
Author

lkhphuc commented Jan 30, 2024

did you manage to paste on terminal and float window mode using these?

@falcucci Have you tried the one in my PR?
vim.keymap.set('t', '<D-v>', [[<C-\><C-N>"+P]]) -- Paste terminal mode

@falcucci
Copy link
Member

@lkhphuc thank you, works like a charm!

@jaekyeom
Copy link

Please consider using vim.api.nvim_paste for the paste example (relevant comment here).

@fredizzimo
Copy link
Member

Also for the reference, these are the old gvim implementations for Windows and Mac
https://github.com/neovim/neovim/blob/6ab0876f51e8ff5debdff03b36508fe7279032b7/runtime/mswin.vim#L30-L62 https://github.com/neovim/neovim/blob/6ab0876f51e8ff5debdff03b36508fe7279032b7/runtime/macmap.vim#L48-L57

We should still use nvim_paste for proper bracketed paste though, although I think it should actually be implemented in Neovide itself.

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

5 participants