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.

2
  • 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. Commented Jun 25, 2015 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
    Commented Apr 30, 2021 at 5:47

2 Answers 2

19

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

1
  • Then what would the command gv looks like using your answer? Commented Jan 7, 2022 at 5: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).

2
  • 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
    Commented Jun 25, 2015 at 15:34
  • 1
    Yes, the ! added to normal bypasses user defined mappings. Commented Jun 23, 2019 at 16:22

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.