tags:

views:

104

answers:

3

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 ;).

+3  A: 

Try first :h Insert-Mode.

Then, you can have a look at :imapto 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)

Luc Hermitte
oh yeah, that's great!
Stephen
:imap - No mapping found :(
Stephen
Oh well, so no beginning-of-line or end-of-line it seems. Sad.
Stephen
:/ I see a `:h i_<End>` -- even If I remapped it: http://code.google.com/p/lh-vim/source/browse/cpp/trunk/plugin/homeLikeVC%2B%2B.vim
Luc Hermitte
Regarding imap, it'll list you non standard keybindings. Standard ones are not implemented as mappings.
Luc Hermitte
Oh I see... thanks
Stephen
+3  A: 

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.

Dave Kirby
Very helpful! Thanks
Stephen
+1  A: 

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.

Aidan Brumsickle
Thanks!! Very nice - especially `Ctrl-o` - wow, that's a great one. I will play around with the rest. I make my own keybindings in Emacs sometimes so imap seems to provide similar functionality.
Stephen
Just to be clear, you don't have to have the $ in there.. I just use it since Java doesn't use $, so I don't have to worry about restricting which variable names, etc I can type.
Aidan Brumsickle
Oh I see. I thought it was using like a shell variable syntax, but thanks for clearing that up.
Stephen