33

I accidentally pressed gh in normal mode and started a selection, so I looked up the doc and found :h Select-mode.

From what I understand the select mode is close to the visual mode excepted that:

  • Typing a printable character, <CR> or <BS> will delete the selection, start insert mode and replace the selection with the input.
  • hjkl and other normal or visual mode movement won't extend the selection unless they're prefixed with <Shift>
  • <CTRL-O> and <CTRL-G> will switch to visual mode.
  • The doc also says the following, which if I understand correctly means that it is possible to do linewise selection which are then treated characterwise:

    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.

I am a little confused because I don't understand why this mode was created: all I can see is that it is less convenient than visual mode and doesn't provide more features.

Also, the searches that I have made all give results about doing selection in visual mode but do not treat select mode.

So my questions are:

  • Why was the select mode created?
  • What are its advantage compared to visual mode?
  • What is a use case where it is more interesting to use select mode?

MetaNote I have no idea which tag is relevant to this question, feel free to retag if needed.

  • To me, this sounds like what you'd expect from most GUI editors. (Selecting a line doesn't mean that it will go to a new line when pasting, shift+arrows extend it, typing replaces selection, all what I'd expect from, say, notepad). – muru Sep 28 '15 at 2:20
  • @muru: I agree that it reminds of this kind of editor but does it means that this mode would have been implemented just to please some users who would want to use Vim as a poor text editor? That seems pretty weird to me actually. – statox Sep 28 '15 at 2:23
  • actually, that pasting property is useful in some cases. I'm sure someone has posted a question about pasting like that here. And as for overwriting, that saves a keystroke (you don't have to press c), so depending on what you want to do, select mode could be useful. Pity I keep forgetting about it. – muru Sep 28 '15 at 2:29
  • I'll try to find this question then. For the overwriting I don't really feel like the c is a saved keystroke because the selection is not as convenient as in visual mode (since you can't use e or iw directly). – statox Sep 28 '15 at 2:40
  • 1
    You're right: when 'selectmode' contains mouse and 'mouse' contains a flag for the current mode, selecting with the mouse will start select-mode (according to the doc). – statox Sep 28 '15 at 2:54
19

The whole point of select mode is to provide a selection behavior similar to the one used in conventional editors.

On the same note, there's mswin.vim which changes a bunch of options and mappings to make Vim feel like a conventional editor.

I can only assume those were added to please a subset of Vim users, probably at the time Vim was ported to Windows (I can feel some disdain for Windows in the doc).

Anyway, select mode is essential to snippet expansion plugins and can be abused for fun and profit:

nnoremap § *``gn<C-g>
inoremap § <C-o>gn<C-g>
snoremap <expr> . @.
  • 2
    I think it is pretty surprising to port Vim on Windows and to create this kind of mode to please the users: If they wanted a "classical" editor why would they use Vim then? But it seems to be the only explaination so... Also I don't really understand the profit of your mappings: as far as I understand they select the word under the cursor in select mode, once you've done that why is it useful? – statox Sep 28 '15 at 13:31
  • 1
    Once the word is selected, type something then press § to select the next occurrence, type something else then press § again to select the next occurrence, and so on. You can press . to repeat the last insertion. It's a variant of "the dot formula". – romainl Sep 28 '15 at 14:14
  • 1
    Oh I see. Nice trick :-) – statox Sep 28 '15 at 14:19
  • I still don't get it. In what way is the selection behavior more like conventional editors? – still_dreaming_1 Jul 11 '16 at 15:33
  • 7
    @still_dreaming_1, in a conventional editor, type foo and select it. You don't need press any key to replace what was selected, do you? That's what select mode emulates. – romainl Jul 11 '16 at 15:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.