Reputation: 27603
Say, I have a (HAML/ruby) line that is being edited in Vim, like this:
%img{ src: (@image.presence || 'http://placehold.it/60x80/'), alt: "", data: { "snippet-image" => "image" "<150x<80" alt="alt" />
I now need to remove alt="alt" />
and replace that with } }
turning the line into
%img{ src: (@image.presence || 'http://placehold.it/60x80/'), alt: "", data: { "snippet-image" => "image" "<150x<80" } }
I am at,for example, the first {
. When I am have navigated to just before "alt=" I can replace that just fine, with C} }
. The problem lies in efficiently getting to the alt=
part.
13W
, count, or guess the amount of Words, and move that amount. This is very inefficient, it takes me nearly half a minute of pointing at my screen to count the thirteen words.$2B
, move to the end of the line, move two Words back. In this very case, more efficient, but still requires counting, and breaks when I had to be at, say, the middle of the line./alt=<cr>h
Search for alt=
. Then move one character backward. Again: works in this case, but this breaks when searching for more common things. For example I want to move to the 14th "
. I think I am missing some simple modifier of concept to navigate more efficiently in horizontal direction, with long lines. Vertically, there are many things (text-objects) to navigate by, and there are helpers like relative-numbering. The example here is code. But I get the same kind of problems when navigating long paragraphs of text in a report or article.
How do you normally navigate horizontally?
Upvotes: 0
Views: 340
Reputation: 25
A little improvement to romainl answer:
$3T"C } }
I had to leave a comment to an answer, but I didn't have enough reputation
Upvotes: 0
Reputation: 1328
I usually use f<char>
/F<char>
and then ;
till I get to the right place. If I see there are many instances of the character I go for some unique character nearby or fallback to /
search command. It is also a matter of taste.
Upvotes: 1
Reputation: 172758
I think at least part of the answer is that (at least in my opinion) long lines are a code smell; not just for the navigation problems you've brought up, but also because
Most languages / syntaxes allow to "break" lines (e.g. with the \
line-continuation character in Bash, C, etc.), and I would advocate use of that to avoid such overly long lines as much as possible.
That said, I mostly stick to WORD-wise W
movements to the (coarse) location, or alternatively f
/ t
if there's a discernible unique {char}
in the vicinity.
Upvotes: 1