3

In terminal I use:

Ctrl+Shift+c and Ctrl+Shift+v

to copy & paste.

I would like Ctrl+c, Ctrl+v in gVim to have standard Vim behaviour.

How to configure gVim, so Ctrl+Shift+c and Ctrl+Shift+v become shortcuts for default clipboard ( i.e. "+gP "+y), while Ctrl+c, Ctrl+v stay unaffected ?

1 Answer 1

1

Note:

It was brought to my attention by Matt that Vim keybindings involving Ctrl are case insensitive, making it impossible to have a keybind C-S-c or C-S-v independently of C-c and C-v - along with further testing revealing that any C-c based binding gets caught by the terminal as C-c - meaning that unless you wish to override the default uses - or wish to use it at all in the cace of C-S-c - you would have to instead use M-S-c and M-S-v/C-M-v or some other alternative.


GVim uses vim's default .vimrc file (~/.vimrc) so you need to add mappings there. In this case, depending on which mode(s) you want the mapping to be available in, you would add one or more of the following (excluding comments) to your .vimrc:

Copy:

nnoremap <M-S-c> "+y  " Normal (must follow with an operator)
xnoremap <M-S-c> "+y  " Visual

Paste:

nnoremap <M-S-v> "+p  " Normal
noremap! <M-S-v> <C-r>+  " Insert and Command line
inoremap <M-S-v> <C-r>+  " Insert

If you want these mappings to only occur in gVim and not in normal vim, then add the following:

if has("gui_running")  " Check if running in a GUI (gVim)
  [Insert mappings here]
endif

Edit: Thanks to Rich in the comments for mentioning, instead of checking if a GUI is running you can put the mappings in the .gvimrc file (~/.gvimrc), a .vimrc used specifically by gVim.

5
  • you may want to check up on mswin.vim, see :h mswin.vim Jul 28, 2022 at 8:08
  • You could also put the settings in .gvimrc instead of checking gui_running.
    – Rich
    Jul 28, 2022 at 8:27
  • Please, before suggesting some piece of code go check it yourself first and fix the bugs: comments are not allowed after maps; normal map switches into operator-pending mode making it pretty much unusable; select map does not work at all; "shifted key" does not work on many platforms including Windows, etc.etc.
    – Matt
    Jul 28, 2022 at 18:14
  • Apologies, the comments were more meant to indicate which mode each one works in than to be actually included and with normal mode a operator would be required to indicate what to copy (and I will admit I've never encountered select mode outside of seeing it in the docs next to visual mode), but I did forget that control commands are for the most part case insensitive and will edit the answer to explain that. Jul 28, 2022 at 23:54
  • Hmm, that's interesting, I have <C-c> set up to yank to "+ in terminal vim (for visual selection), which works fine, my terminal doesn't catch it (but outside vim it still works as expected, so it's definitely vim stealing it from the terminal).
    – fbence
    Aug 1, 2022 at 21:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.