Problem: When writing prose scrolling works in unexpected way when using j
to scroll down. As I scroll between two long paragraphs (wrapped lines in vim) of text using j
, when reaching the next long paragraph (line) the text "jumps" from the bottom of the screen to the top, aligning the first word of the paragraph (line) with the top of the screen (see screenshots bellow).
Affected: Folks who love Vim and want to use it to write prose.
Expected: I would like the paragraph (line) to jump to the middle of the screen OR to continue scrolling with the cursor at the bottom. The jump is too jarring otherwise--I am losing context. Two questions: 1) Is it possible to change the default behavior in .vimrc? 2) If not, how feasible would it be to write a plug-in altering the behavior?
Related Resources:
For example: here I am scrolling down some dummy text: .
After jj
the next paragraph has moved up to the top of the screen:
My .vimrc is here. Prose mode is:
command! Prose setlocal linebreak nolist wrap wrapmargin=0
nnoremap k gk
nnoremap j gj
It will help to brief yourself on VIM's motion commands {
and }
are good ones with literary text. However in the case you describe these are not paragraphs they are lines. VIM manages them as lines. As such you had to go so far as to remap j
and k
which is the reverse of usual. My suggestion is to break the lines into paragraphs by way of textwidth
.
Finally VIM has screen commands to manipulate the viewable area. Since VIM is attempting to show you as much context as possible (in your case a extremely long line) it takes up the whole screen and you see the "jump" To reverse this use the zz
(AKA z<Enter>
) command to move the screen viewable area to match the cursor in the center. The others are zt
to place the viewable area to the top and zb
to place the viable area to the bottom.
Hope these suggestions help and happy VIMing.
As mentioned by @denten they are not paragraphs they are long lines.
When you navigate using j
or k
; you are moving vertically through the same column. But with your mapping (j
to gj
and k
to gk
) you are moving vertically as visually wrapped by the editor.
I suggest to remove that mapping and use gj
& gk
manually as required.
Additionally if scrolling is your requirement, consider mapping PageUp
& PageDown
with the following:
" Slow PageUp/PageDown
nnoremap <silent> <PageUp> <c-y>
nnoremap <silent> <PageDown> <c-e>
Or if the idea of using PageUp
or PageDown
feel awkward, feel free to go with the actual keys to scroll: Control
and y
for up; and Control
and e
for down.
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