2

When navigating within a line, I find myself navigating one character or word at a time, which I feel it one of my greatest inefficiencies. Navigating to a particular line is easy, because we have line numbers displayed on the screen.

Is there a way to display column numbers so that I could navigate similarly within a line? Are there any other good techniques for quickly and accurately navigating within a line?

  • 3
    You might like easymotion – muru Jun 11 '16 at 2:31
  • Is there a particular feature of easymotion that addresses my specific concern? – w.brian Jun 11 '16 at 2:32
  • 1
    For moving within a line, f/F/t/T can be quite useful, and with easy motion, it becomes easier to use them. Have a look at the examples in the README. – muru Jun 11 '16 at 2:36
  • 2
    @w.brian easymotion enables you to toggle shortcuts to quickly jump to words, lines, and so on. This directly addresses your concern of not navigating one character or word at a time. – Tommy A Jun 11 '16 at 2:37
  • @w.brian Do you want a horizontal bar like appearance showing column number below every character? (This will be applicable only for current line where the cursor is) – SibiCoder Jun 11 '16 at 6:01
6

Is there a way to display column numbers so that I could navigate similarly within a line?

Not really. If you are looking for column precision, there is the | motion. 50| will jump to the 50th column (one column being a character). I don't see this being that helpful unless you're writing a script or dealing with a well known text format.

Are there any other good techniques for quickly and accurately navigating within a line?

Yes! You can find them in :help motion.txt.

Within the current line:

  • e or b - You're already familiar with these and their friends.
  • ^ - Move to the first character on the line.
  • 0 - Move to the first column on the line.
  • $ - Move to the last column of the line.
  • g_ - Move to the last character on the line.
  • f and F - Forward and backward, respectively. Press one of these, then the character you want to jump to. e.g. fb will jump to the next b in the line. If you press ;, you'll jump to the next one. Pressing , will go in the opposite direction.
  • t and T - The same as above, but the cursor will land just before the character.

It might not seem ideal at first, but if you know you need to get to the last b in the line, you can press $Fb to get to it instead of pressing fb and mashing ; a few times.

Move by searching:

You are looking at where you need to move your cursor, so searching is a valid way to get there. /abc will jump to the first occurrence of abc. Pressing n or N will move your cursor between all the matches. gn and gN will move the cursor and select the match in visual mode.

But, searching will move beyond the current line, which is not within the current line like you mentioned. To stay within the line, you can select it with shift-v and search with /\%Vabc. \%V causes the search to only happen within the visual selection.

Plugins:

  • easymotion - This gives you shortcuts based on the kind of text jump you want.
  • vim-sneak - Similar to easymotion, but is more like f, F mentioned above combined with searching.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.