13

I like the - and <C-M> normal-mode keys for going to the first non-whitespace character of the previous/next line.

Are there coresponding keys for going to the last non-whitespace character on the previous/next line?

2 Answers 2

16

g_ moves the cursor to the last non-blank character of the current line. From Vim's :help g_:

g_          To the last non-blank character of the line and
            [count - 1] lines downward |inclusive|. {not in Vi}

Unfortunately, I think the only options you have to move to the non-blank character of the previous/next line is kg_ or jg_ respectively or using a count to move downwards.

However, it is easy to map them to something easier:

nnoremap <F3> kg_
nnoremap <F4> jg_
4
  • 1
    Also note that 2g_ will also work if you want to go to the last non whitespace character on the next line. However, this can't be used for the previous line. The advantage of 2g_ is that it can be repeated with . Commented May 17, 2015 at 13:27
  • 1
    Motions (like g_) are not repeatable with .. Generally, only things that change the state of the buffer can be repeated.
    – tommcdo
    Commented May 17, 2015 at 22:01
  • Though, when combined with an operator, repeating works. Perhaps that's what you were referring to
    – tommcdo
    Commented May 17, 2015 at 22:04
  • Ah, I didn't realize motions weren't repeatable. I should look at the docs before I say things. Commented May 18, 2015 at 0:13
0

If you mean the next non-whitespace character of the previous/next lines (by going vertically), then try:

map <C-k> :call search('\%' . virtcol('.') . 'v\S', 'bW')<CR>
map <C-j> :call search('\%' . virtcol('.') . 'v\S', 'wW')<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.