Reputation: 21625
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
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
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
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 b
ackwards search()
for it:
:call search('\%' . virtcol('.') . 'v\S', 'bW')
You can easily turn this into a normal-mode mapping.
Upvotes: 7
Reputation: 2017
Not exactly what you're asking for, but if you start at }
and hit %
, the cursor moves to the matching {
.
Upvotes: 1