Hi, inspired by this answer, I wanted to inquire what other useful movement/editing commands are available in insert mode. For instance, are beginning-of-line, end-of-line, or other such commands accessible without switching to normal mode? Still new to vim so I'm used to jumping around after typing a few characters or so... vim makes me think before I type ;).
Try first :h Insert-Mode
.
Then, you can have a look at :imap
to have the list of insert-mode mappings defined in your vim session.
:h i_
CTRL+D will also list you all the documented keybindings active in insert-mode. (use c_
for command mode)
In addition to what Luc says, try :h insert-index
. This puts you on the index help page at the section for insert mode keys.
The index page is very useful since it lists on one page all the default key bindings and all the :ex commands.
There is also the :h quickref
page which gives a slightly more detailed description of the more common keys and also all the options that you can change with the :set
command.
If you type Ctrl-o you can then use a normal-mode command, after which you'll be put back in insert mode.
Some other things I have found useful are Ctrl-p and Ctrl-n which do auto-complete based on what you've typed before. Very handy, though it's just string-based and thus not as 'clever' as an IDE that can look up methods of an object or variable names, for example.
Finally, as others have mentioned, :imap is useful for defining insert-mode maps. For example, if you're programming in Java, you might do :imap $sop System.out.println(. Then whenever you type '$sop' it will be replaced with the actual method call. You can also use arbitrary command sequences, as you would type them. Example:
:imap $top <ESC>ggO
(literally type "<ESC>
")
This puts you in normal mode [<ESC>
], goes to the top of the page [gg
] and puts you in insert mode on a new line above the current position [O
].
As a parting thought, when you're starting out in VIM it is tempting to stay mostly in insert mode. However, I have read, and also started to learn myself, that you can be much more efficient by doing small edits and using the tools for repeating actions, searching, and search/replace.
My favorite VIM commands: * = search for all occurrences of the word under the cursor. The cursor doesn't have to be at the beginning of the word. c = Change... takes a positioning command. For example, cfn deletes all the text on the current line from the current position to the first occurrence of the letter 'n' and puts you in insert mode. cw changes the current word, from the cursor to the end of the word. And much more.
d, y, p - delete, yank, put (ie, cut, copy, paste respectively) Very useful for moving bits of code around.