linux vi usage
You can go to a particular line or word in a file using vi in several ways:
- To make vi start at a particular line in a file, add
+line_num
to the command you use to start vi. Replaceline_num
with the line number, for example:vi +36 foo.c
- If you're already in vi, you can use the goto command. To do this, press
Esc
, type the line number, and then pressShift-g
. If you pressEsc
and thenShift-g
without specifying a line number, it will take you to the last line in the file. - You can also use the ex command line to go to a line. For instance, if you wanted to go to line 14, you could press
Esc
and then enter::14
- To search forward for some text, use the
/
(forward slash) command. PressEsc
and then enter/pattern
, replacingpattern
with the text for which you want to search forward. For example, to find every instance of the word "blimp", enter:/blimp
To look for the next occurrence after the first, either pressn
or press/
again and then pressEnter
. To go back to a previous occurrence, pressShift-n
. To search backwards in a file, use the?
command. - To see what line you're on at any time, press
Ctrl-Shift-g
. To number all lines, pressEsc
and enter::set number