[NCLUG] Stupid VIM advice on the net. How to do it right?

John Gilmore j.arthur.gilmore at gmail.com
Fri Sep 13 11:00:10 MDT 2013


How do I access normal mode (or command mode) stuff from withing an
insert mode keymapping?


For example, I want to remap the HOME key to respect display lines
instead of visual lines. The following works mostly:

map <Down> gj

Fine, but what about insert mode? The best advice seems to be something like:

imap <Down> <esc>gji

And that works, but only sortof. It doesn't preserve insert vs.
replace mode, and it doesn't correctly deal with cursor position. In
insert mode the cursor can be one place beyond the end of the line.
There's no way (that I know of) to exit insert mode and re-enter it
without losing this information. Isn't there a way to map an insert
mode key to normal mode stuff directly instead of exiting and
re-entering insert mode? I haven't found one.


More information about the NCLUG mailing list