Go to n-th symbol in line

Vim

Vim Problem Overview


How to move cursor to the n-th symbol from the left in Vim?

One of the solutions I see is press 0n<right-arrow>, it will move to the n+1 position. Is there any more natural way to do it?

Vim Solutions


Solution 1 - Vim

The pipe '|' character may be what you want:

To go to 25th column in a line in normal mode press 25|

To go to 37th column in a line in normal mode press 37|

and so on. . .

Solution 2 - Vim

EDIT: misread your question.

you can move forward to a particular symbol by typing f followed by the symbol in question:

if you want to move to the third $, you'd type:

3f$

in order to go backwards, you use capital "F"

F$

to get to the end of the line first, you use "$"

so your keystrokes for finding the third $ from the end of a line is:

$3F$

i like to keep something like this handy when using Vim:
http://www.lagmonster.org/docs/vi.html

Solution 3 - Vim

I'm not sure if you mean the nth character or nth occurrence of a character; the second has been answered so I will answer the first.

^ will take you to the start of the line excluding whitespace (so to the first non-white column) and | (pipe) or 0 (zero) will take you to the first character. Then l (lowercase L) will take you to the right; and 7l will take you seven characters to the right. So all together, to go to the (n+1)th character on the line, for n=7, 07l.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNutelView Question on Stackoverflow
Solution 1 - VimHerbert SitzView Answer on Stackoverflow
Solution 2 - VimRamyView Answer on Stackoverflow
Solution 3 - VimChris MorganView Answer on Stackoverflow