Thomson
Thomson

Reputation: 21625

Move to the next row which has non-white space character in the same column in VIM?

As source code is usually indented, it will help navigate source code quickly if I can move to the next/previous row which has non-empty white character in the same column. Using below code snippet as example and the cursor in on the last }, is there a way to navigate the cursor to i which starts if?

if (condition) {
    //  some code
}

Upvotes: 7

Views: 818

Answers (4)

Harry
Harry

Reputation: 3412

If your code has a defined indentation system, jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.

Upvotes: 1

Ingo Karkat
Ingo Karkat

Reputation: 172590

I've now implemented this motion in my JumpToVerticalOccurrence plugin; by default mapped to ]| / [|. There are other, related mappings like a ]V{char} mapping that works just like f, but vertically.

So if you don't mind installing a plugin (plus dependencies), this is more robust and functional (it supports [count] as well).

Upvotes: 2

Ingo Karkat
Ingo Karkat

Reputation: 172590

To search for the same screen column, you can use the special /\%v atom; the current column can be queried with virtcol('.'). Assert a non-whitespace (\S) at that position, and trigger a backwards search() for it:

:call search('\%' . virtcol('.') . 'v\S', 'bW')

You can easily turn this into a normal-mode mapping.

Upvotes: 7

ales_t
ales_t

Reputation: 2017

Not exactly what you're asking for, but if you start at } and hit %, the cursor moves to the matching {.

Upvotes: 1

Related Questions