obsidian-vimrc-support
obsidian-vimrc-support copied to clipboard
Have j and k navigate visual lines rather than logical lines unless preceded by a count
I have j and k set to navigate visual lines by default:
nmap j gj
nmap k gk
I use relative line numbers and navigating to a line with a count goes to the visual line, which doesn't correlate with the line number.
I want j and k to navigate visual lines rather than logical lines unless preceded by a count so I can make use of relative line numbers.
I've tried this (which I got from Vim Tips & Tricks, under: Smarter j and k navigation) but it doesn't work:
noremap <expr> j v:count ? 'j' : 'gj'
noremap <expr> k v:count ? 'k' : 'gk'
map
, nmap
, & nnoremap
haven't worked either.
Is there any way to do this?
The v:count
way works great in Vim (I use it myself too), but CodeMirror's Vim emulation is nowhere near this sophistication.
This bothers me too and I'm not aware of a solution at the moment. I might find a way to bake it into the plugin at some point, especially if it also bothers others.
It'd be awesome if you're able to do that. For now, I've found a workaround where you can navigate logical lines with J & K:
" Navigate visual lines with j & k
map j gj
map k gk
" Navigate logical lines with J & K
noremap J j
noremap K k