Showing posts with label Select Mode. Show all posts
Showing posts with label Select Mode. Show all posts

Tuesday, February 23, 2021

Vim - Select Mode

When learning Vim, it's important to understand its modes, of which, one of the least know is Select Mode.
Photo by Alex Knight on Unsplash

Once you installed Vim, learned the basics of Vim Modes and understood Normal mode, it's time to learn yet another Vim mode: Select Mode. This mode is similar (but different) from the more common Visual mode. Let's take a look

Select Mode

Select mode looks like Visual mode, but the commands accepted are quite different. It was created to be similar to Windows' selection mode but with time has been less and less used.

Entering Select mode

All the following are ways you can enter the select mode:

  • gh or gH or g_CTRL-H - commands in Normal mode
  • Using the mouse to select an area, and 'selectmode' contains "mouse". 'mouse' must also contain a flag for the current mode.
  • Using a non-printable movement command, with the Shift key pressed, and 'selectmode' contains "key".  For example: <S-Left> and <S-End>
  • v, V or CTRL-V - if 'selectmode' is set to "cmd".
  • CTRL-G from Visual mode, 
If the showmode option is set, as soon as you enter the Select mode, should see a message in the bottom line such as:
Press gh to enter Select mode

Important considerations regarding the Select mode

  • Printable characters, <NL> and <CR> cause the selection to be deleted, and Vim enters Insert mode.  The typed character is inserted.
  • Non-printable movement commands, with the Shift key pressed, extend the selection. 'keymodel' must include "startsel".
  • Non-printable movement commands, with the Shift key NOT pressed, stop Select mode. 'keymodel' must include "stopsel".
  • <ESC> stops Select mode.
  • CTRL-O - switches to Visual mode for the duration of one command
  • CTRL-G - switches to Visual mode.

Operators in Select Mode

When using an operator in Select mode, and the selection is linewise, the selected lines are operated upon, but like in characterwise selection.  For example, when a whole line is deleted, it can later be pasted halfway a line.

Why/When use Select Mode?

At a first sight, the Select mode is similar albeit more restrict than Visual mode so when to use it?

The first thing to understand is that the Select mode was created to provide a selection behavior similar to the one used in conventional editors as explains in the documentation:

Select mode looks like Visual mode, but the commands accepted are quite different.  This resembles the selection mode in Microsoft Windows.

That said, today that Vim is widely available in all platforms and pretty popular in Windows too, given its restrictions over the more popular (and feature-rich) Visual mode, there's no real reason to use it.

Getting back to Normal Mode

To get back to Normal mode from select mode (or one of Vim's other modes), press <Esc> or <Ctrl-C> or <Ctrl-[>.

Learning More

Ready to learn more about the Select mode? Open its dedicated manual with:

:h select-mode

Mode-specific help

If you want to know more about specific keys, Vim also has an intelligent mechanism to get you to the help quickly. It follows this pattern:

What Prepend Example
Normal mode command :help x
Visual mode command v_ :help v_u
Insert mode command i_ :help i_<Esc>
Command-line command : :help :quit
Command-line editing c_ :help c_<del>
Vim command argument - :help -r
Option ' :help 'textwidth'
Regular expression / :help /[

We hope you get used to the above syntax and use it regularly in you your Vim journey. It will not only help you learn more about Vim but also to memorize the commands better.

Conclusion

On this post we continued in our Vim journey by learning a bit more about Vim's Select mode. If it seems complicated, don't be concerned. It takes years to master Vim but be sure that the more you learn, the more you realize that time is that secret ingredient in getting comfortable, becoming proficient and efficient with Vim.

Learning Vim is like learning a musical instrument. It takes time, effort and discipline but once you master it, the gains are endless. You definitely won't regret.

See Also

Any comment about this page? Please contact us on Twitter

Featured Article

Vim - Ex Mode

When learning Vim, it's important to understand its modes, including the  Ex Mode  where you can continually type your commands u...

Popular Posts