Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remapping vim end of line key

One of the big annoyances when using vim in mac keyboard is the absence of Home and End keys. Although there is a work around in vim namely

$ for  End of line 
0 for Beginning of line (both in <Esc> mode)

I find it unintuitive as $ is on the left side of the keyboard and takes you to the rightmost line of text whereas 0 being on the right side takes you to the beginning of the line. Is there a way to remap the keys with 9 for beginning of line and 0 for end of line?

I tried the following in my ~/.vimrc

inoremap <Esc>9 <Esc>0
inoremap <Esc>0 <Esc>$

but it doesn't seem to take effect and the old key combinations are still in place. Help me out! Also let me know the drawbacks of doing this (if any)? Thanks!

like image 725
crazyim5 Avatar asked Apr 22 '13 18:04

crazyim5


1 Answers

inoremap is meant for insert mode mappings. What you're looking for is nnoremap. For example, you could try this:

nnoremap 0 $
nnoremap 9 0
inoremap <C-A> <Home>
inoremap <C-E> <End>

However, personally I would not remap the 9 as you might randomly need it someday (for say 9gg or 9j). Instead I'd go for Q, K, U or S as they are hardly used.

In fact, I would probably recommend just leaving it the way it is. $ is actually quite intuitive when you learn about regular expressions. It is a bit hard to hit, but in general you won't need it that much because you have many commands such as D that map to d$. And it will also be easier when you ever have to work with a vanilla vim.

like image 74
Daan Bakker Avatar answered Sep 27 '22 22:09

Daan Bakker