85

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.

6
  • 1
    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
    Commented Sep 28, 2015 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
    Commented Sep 28, 2015 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
    Commented Sep 28, 2015 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
    Commented Sep 28, 2015 at 2:40
  • 3
    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
    Commented Sep 28, 2015 at 2:54

1 Answer 1

47

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> . @.
11
  • 3
    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
    Commented Sep 28, 2015 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
    Commented Sep 28, 2015 at 14:14
  • 1
    I still don't get it. In what way is the selection behavior more like conventional editors? Commented Jul 11, 2016 at 15:33
  • 17
    @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
    Commented Jul 11, 2016 at 15:53
  • 3
    @romainl what is that "double S" character you are typing? How do you type that character?
    – Michael
    Commented Jul 23, 2019 at 13:18

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.