Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's a common use case of "selection mode" in vim?

Tags:

vim

It's the first time i noticed about the selection mode in vim when i accidentally triggered it from visual-line mode by <c-g>.

Vim already has visual mode for text selection what's the use case of selection mode, can anyone give me a hint on this?

(note: i've checked the manual page which describes it as

a resemblance of MS Windows text selection

but i still cannot quite understand why do we need any mouse actions in vim)

like image 990
lxyyz Avatar asked Aug 17 '16 02:08

lxyyz


2 Answers

Select-mode is commonly used in snippet plugins such as vim-snipmate. Mappings can be created that are unique to select-mode so as not to interfere with regular visual mode behaviour.

Here is an excerpt from Practical Vim by Drew Neil:

If you are happy to embrace the modal nature of Vim, then you should find little use for Select mode, which holds the hand of users who want to make Vim behave more like other text editors. I can think of only one place where I consistently use Select mode: when using a plugin that emulates TextMate's snippet functionality, Select mode highlights the active placeholder.

like image 69
zarak Avatar answered Oct 18 '22 18:10

zarak


As the documentation suggests, select mode is a bit different from visual mode. Here's the commands you can do in it:

Commands in 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. *v_CTRL-O*
- CTRL-G switches to Visual mode.

Otherwise, typed characters are handled as in Visual 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.

You can see the docs here.

What they mean by "resembles MS Windows selection" is probably that you can extend the selection with Shift+Arrows, and also that any printable characters entered will substitute the selected text and enter insert mode.

Also, see this question/answer at the vi.SE.

like image 29
rgoliveira Avatar answered Oct 18 '22 17:10

rgoliveira