7

I've set up a bunch of key mappings that would cause many Vim users to cringe. Now I am unable to get into Visual Block mode using Ctrl-V (Ctrl-Q isn't mapped, but it doesn't work).

Is there any command that I can type to enter Visual Block mode?

Ideally I could set something up so that :vb would enter visual block mode.

  • 7
    Sidenote: <C-q> is the terminal "start" signal; Vim never sees it. Use stty start undef to disable it so that Vim sees it. You probably also want to disable the "stop" signal (<C-s>) with stty stop undef. – Martin Tournoij Jun 25 '15 at 15:21
12

There is no built in command to start visual block mode in vim, but you can define one yourself:

command! Vb normal! <C-v>

Here is a breakdown of how it works:

  • command! Vb - This creates a command called "Vb". The ! after command means that vim will not throw an error if the command is already defined.
  • normal! <C-v> - This command tells vim to take all characters after it and act like you had pressed them in normal mode. The ! makes it so that all user defined mappings are ignored. This means that if <C-v> is mapped to something else, it will still work the way it does by default.

Here are some relevant help topics:

  • :help :command
  • :help :normal

NOTE

User defined commands must start with a capital letter.

Also, there may be a conflicting mapping which prevents you from using <C-v> to enter visual block mode. To check for any conflicting mappings for <C-v>, you can run :verbose map <C-v>.

8

As far as I can find, there is no built-in command to start visual mode.

However, you can easily add these commands to Vim:

:command! Visual      normal! v
:command! VisualLine  normal! V
:command! VisualBlock execute "normal! \<C-v>"

You can change the names of these commands to whatever you want, but all user-defined commands must start with an upper-case letter (so you can't use :vb, but :Vb is okay).

  • You're the man. I was thinking that if I used <C-v> in a command, it would just call what I had remapped it to. Is that what the normal! is for? – Dan Jun 25 '15 at 15:34
  • Yes, the ! added to normal bypasses user defined mappings. – joeytwiddle Jun 23 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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