13

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.

SibiCoder
  • 3,372
  • 5
  • 20
  • 40
Dan
  • 485
  • 2
  • 5
  • 8
  • 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
  • added the stty start undef to my .bashrc and it's working. I can use CTRL-Q for Visual Block now when vim is running in an terminal – Lusk116 Apr 30 '21 at 05:47

2 Answers2

18

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

EvergreenTree
  • 8,180
  • 2
  • 37
  • 59
10

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

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
  • 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
  • 1
    Yes, the ! added to normal bypasses user defined mappings. – joeytwiddle Jun 23 '19 at 16:22