The highlighted text is the array in which I want to move. I have to press g before pressing j to move a line down. Is there some mapping for my .vimrc that I can just use hjkl to move in screen lines without pressing g every time.
Thanks for your help Matthias
You can remap the j
and k
keys (not sure if you really need h
and l
..)
:map j gj
:map k gk
Once you tried and liked them, add them to your .vimrc
without the leading :
I use the following snippet that helps with all forms of navigating, including things like $ to end of line and such.
" mapping to make movements operate on 1 screen line in wrap mode
function! ScreenMovement(movement)
if &wrap
return "g" . a:movement
else
return a:movement
endif
endfunction
onoremap <silent> <expr> j ScreenMovement("j")
onoremap <silent> <expr> k ScreenMovement("k")
onoremap <silent> <expr> 0 ScreenMovement("0")
onoremap <silent> <expr> ^ ScreenMovement("^")
onoremap <silent> <expr> $ ScreenMovement("$")
nnoremap <silent> <expr> j ScreenMovement("j")
nnoremap <silent> <expr> k ScreenMovement("k")
nnoremap <silent> <expr> 0 ScreenMovement("0")
nnoremap <silent> <expr> ^ ScreenMovement("^")
nnoremap <silent> <expr> $ ScreenMovement("$")
You can simply remap j and k (for example) to gj and gk:
" map j to gj and k to gk, so line navigation ignores line wrap
nmap j gj
nmap k gk
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With