vim move to first non-blank in same column

You could use the following mappings to do this. (There might be some edge cases I didn't think of)

nnoremap <leader>d m':exec '/\%' . col(".") . 'c\S'<CR>``n
nnoremap <leader>u m':exec '?\%' . col(".") . 'c\S'<CR>``n

The important part is :exec '/\%' . col(".") . 'c' This matches the current column. This is taken directly from :h %c. Then I added a \S to match non whitespace. m' and `` is used to store the current position and restore it around the execute statement. This is necessary since using the execute places us at the start of the line which could lead to erratic behavior (skipping too many lines in some cases). After executing this I go to the first match with n. The only difference between the up and down version is which direction we search / for down and ? for up.

If you instead wanted to do this with virtual columns (i.e. tabs) replace \%c with \%v.


My JumpToVerticalOccurrence plugin provides ]| and [| mappings that provide just that, supporting [count] and without clobbering the current search pattern.

Tags:

Vim