Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check Visual mode

Tags:

vim

mode

What is the best way to check in a vimscript which visual mode is currently active (visual or visual block)?

I've read about mode() but I can't make it work.
echo mode() doesn't work for me
if mode() == "v" doesn't work for me as well.

like image 345
Reman Avatar asked Apr 09 '12 12:04

Reman


People also ask

What is VI visual mode?

vi (visual editor) is included with all (mt) Media Temple services. vi is a full screen editor and has two modes of operation. Command Mode - every character entered is a command. This is the default mode when you start vi. Insert Mode - this mode allows you to edit.

How do I exit visual mode?

If you're in character-wise visual mode, pressing v will exit visual mode. If you're in block-wise visual mode, pressing ctrl-v will exit visual mode.

What is V in vim?

Press the v key to enter visual character mode. The word VISUAL will appear at the bottom of the screen. Use the Arrow keys to highlight the desired text. You can use other navigation commands, such as w to highlight to the beginning of the next word or $ to include the rest of the line.


1 Answers

Look at the help for mode(). The relevant part:

          v       Visual by character
          V       Visual by line
          CTRL-V  Visual blockwise

You need to be checking mode() == "\<C-V>" (literal ^V character), not mode() == "v", to check for blockwise visual mode.

like image 52
Chris Morgan Avatar answered Oct 30 '22 14:10

Chris Morgan