berkes
berkes

Reputation: 27603

How to navigate horizontally

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.

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

Answers (4)

vireulgr
vireulgr

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

romainl
romainl

Reputation: 196876

I solved this problem with:

$vT";;c } }

Upvotes: 1

dkrikun
dkrikun

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

Ingo Karkat
Ingo Karkat

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

  • they are difficult to comprehend (visually, especially because different editors soft-break them differently)
  • most tools have a line-based understanding of changes (e.g. when viewing diffs in source control), and long lines disrupt that (e.g. the "blame" output of who changed which line last).

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

Related Questions