5

When I'm entering some text in vim, sometimes I need to jump to some other place and enter more text. I know there are some shortcuts with ctrl key to simplify the movement.

What are the most useful keyboard shortcuts in insert mode?

e.g.

I have:

'text_sample'

The cursor is in _ position. I want to jump to the end of line without having to press ESC and ctrl + A.

1
  • 1
    "most useful" or "favorite" type questions tend to be too vague for this site. I'd suggest revising your question to be more specific, e.g. "what's the fastest way to get to the end of the line in insert mode?". Also, I think you meant esc A (A = shift a), not esc ctrl a.
    – jw013
    Dec 22, 2011 at 16:23

5 Answers 5

10
  • End (1 key) the only suggestion that has fewer keystrokes than
  • Esc A (2 keys + use of shift), the one you have suggested.
  • Ctrl-o $ OR Ctrl-o A (2 keys + control and shift), the most keystrokes yet.

The last one illustrates the use of Ctrl-o in Insert mode, which lets you interrupt insert mode to use exactly one normal mode command before returning.

1
  • That's awesome. I never knew about ctrl-o, despite having used Vim for years.
    – Bill B
    Jan 28, 2012 at 21:01
2

Does your keyboard not have an End key?

This is what I use in insert mode to jump to the end of the line. There is a Home key to jump to the beginning of the line. Also, in insert mode, pageup and pagedown move up and down the page. Otherwise, no vim movement bindings are applicable in insert mode.

(Clearly, for instance, if you type f5w, you will not go to the 5th w, but will type in the characters, "f5w", or } won't go to the next paragraph, but will just type "}", etc.)

1
  • 1) There are "short" keyboards without Insert/Delete/Home/End/PgUp/PgDn keys 2) It's too far away to move your hand from typing position
    – yahol
    Jul 1, 2018 at 16:44
1

Here is a link that has some commands, http://www.vmunix.com/~gabor/vi.html

There aren't that many like you've described [ ctrl - ...] in insert mode

but you can read it as ^ mean type control

1

Vim offers kind of a 'get out of (insert-mode) jail free card', and it's the Alt key.

While in insert mode - just press it while executing a normal mode command. This will get you out of insert mode and then execute the normal mode command.

That said, a couple of solutions for your specific scenario are:

  1. Alt + % - Goes into normal mode and put cursor at the end of the line.
  2. Alt + A - Same as above but goes back into insert mode afterwards.

Important note: This does not accept a repetition-number.

Have fun.

1
  • I am new to vim and came here from google. It seems <kbd>Alt</kbd> + <kbd>%</kbd> only works with delimiters. Isn't the <kbd>Alt</kbd> + <kbd>0</kbd> what you mean?
    – Celdor
    Oct 13 at 10:09
0

if your using vim in the command line alt will send and esc before passing an command. for example if you press alt+shift+a you will exit insert mode and and re-enter insert mode at the end of the line.

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.