I would like to map <End>
and <Home>
to go to the end or beginning of the current line (not the screen), even if the cursor is on a wrapped line:
|1 First line. |
|2 This is some very| <- Wrapped line
| long text |
|3 |
So here what should be the mappings:
<Home> Cursor go to the first letter of visible line (wrapped or not).
<End> Cursor go beyond the last letter of visible line (wrapped or not).
An important thing is that I use virtualedit
:
set virtualedit=all
noremap <Up> gk
noremap <Down> gj
noremap k gk
noremap j gj
For a normal line, this can be solved using these mappings:
noremap <End> $l
noremap <Home> 0
"i_<End> already mapped
"i_<Home> already mapped
However on a wrapped line none of the above mappings work.
Here below the cases that must work:
|1 First line. | Initial
^
|1 First line. | <Home> (1)
^
|1 First line. | <End> (2)
^
|1 First line. | <Home>
^ l<Down>
|2 This is some very |
^
|2 This is some very | <End> (3)
^
|2 This is some very | <Home> (4)
^ l<Down>
| long text |
^
| long text | <Home> (5)
^
| long text | <End> (6)
^
The solution proposed by statox in his answer works for <Home>
, but not really for <End>
. So, I added a l
to the <End>
mapping. Then all the cases pass, but (3) that goes on the next line.
nnoremap <silent> <End> :set virtualedit=<CR>g$:set virtualedit=all<CR>l
nnoremap <silent> <Home> :set virtualedit=<CR>g0:set virtualedit=all<CR>
Most editors solve case (3) by adding a virtual blank column at the end of the screen, so the cursor can be virtually placed here in this particular case.
How can I achieve the same behavior in Vim?