Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Vim: How do I treat wrapped lines as a separate line so that I can navigate to it with j or k?

Currently if my vim tab is small enough it will wrap the text like so. When I press j I want it to go to the line I visually see as the next line, which doesn’t have it’s own line number.

enter image description here

However, vim just goes to the next line with a line number, so in this case it just goes to line 7 vim.cmd ...

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is there a way to make it treat the wrapped line as a separate line when pressing j or k?

>Solution :

You’re looking for the gj, gk, etc. commands, which navigate "display lines" rather than actual file lines.

I have the following in my vimrc so that the arrow keys navigate by display lines, but j and k continue to navigate file lines:

nnoremap <Down> gj
nnoremap <Up> gk
vnoremap <Down> gj
vnoremap <Up> gk

But if you want you could remap j and k instead:

nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading