Insert at line number with 1 command in VIM

Is there a shortcut in vim for :20 followed by i, i.e. one command for inserting at a line number?


Solution 1:

You can use nmap vim command like this:

:nmap ~! 20Gi

And then every time you will press keystrokes ~! (or you can choose any other key combination) it will move cursor on line # 20 in insert mode.

Solution 2:

You can type :20i<enter>Text you want to insert including newlines...<esc>

Solution 3:

another way to do what you ask is 20Gi in normal mode. it may not be faster, but it may be easier to remember. if you want to do it without the shift try 20ggi

thinking about it more, and this wont work in obvious cases, but I like to do the following

:set mouse=a
:nmap <2-LeftMouse> i

which, in normal mode (note nmap), will bring me to that line and when I double click it will change to insert on the specified line. The usefulness could be trivial, but if you are used to using the mouse this map help.

http://www.viemu.com/vi-vim-cheat-sheet.gif

viemu.comhas a half decent cheatsheet, if you like