Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search a character backwards from the end of line in Vim

Tags:

vim

for the example text below, the curser is in the first space:

This is the sentence.

is it awesome that I can use command like

fe

to jump to the last e in the end of the line

but unfortunately f and F only can search according to the current cursor position, Is there a command that I can search a character backwards from the end of line?

like image 948
mko Avatar asked Aug 06 '13 02:08

mko


People also ask

How do you go backwards in Vim?

Use b to go back a word. You may also want to check out W and B to advance/go back a WORD (which consists of a sequence of non-blank characters separated with white space, according to :h WORD ).

How do you search for a string at the end of a line?

Use / followed by the appropriate regular expression. To search for a string at the start of a line, use ^string as the expression. To search for a string at the end of a line, use string$ as the expression.

How do I go to a specific character in Vim?

You can type f<character> to put the cursor on the next character and F<character> for the previous one. You can also use ; to repeat the operation and use , to repeat it in opposite direction.

What does F do in Vim?

If you press "F", Vim will move the cursor backwards instead of forward. Given the previous sentence, if pressed "Fq", and the cursor was at the end of the line, it would move to the "q" in "quick".


1 Answers

You can use $ to go to the end of the line. And then you can do a F from there to search backwards.

You can use 0 to go to the beginning of the line (first non whitespace). And then you can use f to search forwards.

$F search backwards from end of line.
0f search forwards from beginning of line.

like image 124
FDinoff Avatar answered Oct 10 '22 05:10

FDinoff