4

I've been using vim for not that long and got stuck with marking when I'm in the insert mode. I do it as follows:

  1. <ESC>v
  2. Mark the text I need
  3. Do something with it
  4. Enter to the insert mode again

Now I think that the approach taken by classical editors (hold CTRL+SHIFT and then press LEFT or RIGHT) is a little bit convenient. Especially if we need to select just one word we just typed (I'm not talking here about compilicated visual blocks). I think so because we don't press <ESC>v.

Maybe there is a simpler way to mark while we are in insert mode?

  • 10
    It allows us to use text objects which are much more flexible and quick then just using <left><left><left><left>. Try <Esc>viw for highlighting the current word and check out :h text-objects for more and better ways to select text. – Tumbler41 Sep 28 '16 at 18:55
1

If you just want to copy the function "use ctrl-[left/right] to select direction-wise until word bound you can bind

:inoremap <c-left> <esc>vb
:inoremap <c-right> <esc>ve

or <esc>viw to instead visual around the entire word you're currently inside (or right at the end of.)

I use a similar technique in my .vimrc to be able to quickly uppercase my entire last word (e.g. if i wrote max_timeout but wanted MAX_TIMEOUT). My binding for this is :inoremap <c-u> <esc>vawUea. The idea is the same - you bind something(<c-u>) to exit insert mode(<esc>), go into visual(v), do what you need to do(U), and then jump back into insert mode again(ea).

If you're worried about overwriting a predefined binding when you map on something like <c-u> or <c-left>, you can look it up with :help <c-left>.

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.