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


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_
  • 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 . 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
    May 17, 2015 at 22:01
  • Though, when combined with an operator, repeating works. Perhaps that's what you were referring to
    – tommcdo
    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. May 18, 2015 at 0:13

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 that you have read and understand our privacy policy and code of conduct.

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