0

I'm working a lot with vim and have looked up the commands mapped below in the :help docs They don't appear to be in use. I'm using a Windows 10 os and running a centos VM.

I want to map:

clipboard copy - ctrl+[
clipboard paste - ctrl+]

My .vimrc looks like so.

vnoremap CTRL+[ "+y
vnoremap CTRL+] "+p

I need to diagnose if the issue is in my bindings or the communication between windows and the VM.

Any help is appreciated.

2
  • You most likely don't want to map <C-[>, which is usually equivalent to <esc>; it tends to cause all manner of problems
    – D. Ben Knoble
    Jan 18 at 15:53
  • A lot has been said about <C-[> but <C-]> also does something useful. It jumps to the tag below the cursor. There are other keys to do the same (see :help CTRL-]). I find this feature very powerful but, of course, you don't have to use it.
    – Friedrich
    Jan 18 at 18:02

2 Answers 2

2

A major downside of Vim is that it is not as discoverable as your run-of-the-mill GUI editor, which makes it a lot less intuitive for the newcomer.

A major upside of Vim is that it compensates the aforementioned downside by bundling THE BEST DOCUMENTATION OF EVERY TEXT EDITOR EVER, which makes learning it from first principles a quick, painless, and rather enjoyable job.

Case in point: mappings are introduced in chapter 5 of the user manual, :help 05.4, which links to the full mapping documentation at :help 40.1, where :help key-notation is linked to from the :help map-special-keys section, which tells you that the correct representations of CTRL+[ and CTRL+] in a mapping are:

<C-[>
<C-]>

Basically, spending just a few hours with the user manual, as everyone serious about using Vim should, would be enough to see that putting the following lines in your vimrc is not going to do anything useful, let alone give you the desired functionality:

vnoremap CTRL+[ "+y
vnoremap CTRL+] "+p

Now, using the correct notation:

vnoremap <C-[> "+y
vnoremap <C-]> "+p

won't keep you out of trouble because <C-[> happens to be synonymous with <Esc> in Vim (and ASCII, etc.) and Vim uses it for a lot things under and over the hood. Like leaving visual mode, for starters. That means two things:

  1. mapping <C-[> also maps <Esc> and vice-versa,
  2. mapping <C-[>, and therefore <Esc>, to do something else than what it is supposed to is going to have lots of unforeseen side-effects.

You should find different keys to map to, at least for <C-[>.

And start following the user manual ASAP: :help user-manual.

1
  • Thanks for this advice. Looking forward to digging in this weekend.
    – Lauro235
    Jan 19 at 9:07
0

When mapping CTRL+<key> you can use <C->, so in this case you can use:

vnoremap <C-]> "+y
vnoremap <C-]> "+y

to map it in visual mode, or use

noremap <C-]> "+y
noremap <C-]> "+y

to map it in both visual and operator-pending modes.

1
  • ...and in normal mode. See :help map-modes.
    – Friedrich
    Jan 18 at 18:04

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.