To search and replace, here's a sequence I use a lot. Suppose we wanted to change a variable name, and it's used more than once in the file. Start in COMMAND mode (hit Escape to get to COMMAND mode).
/variable
to search for variable
in your filecw
to change the word (hit Escape after typing in new variable name)n
to search for next instance of variable.
(just hit the dot/period key) to repeat the last cw
commandIf there are a lot to change, you just keep hitting n
followed by .
,
over and over. If that gets annoying, there are ways to do global-search-and-replace
all in one shot, but I often prefer the above sequence.
In python, I often add a loop or if/else
around an existing code block,
so the whole block needs to be indented. Here's how to do that (hit Escape
to start in command mode):
shift-v
to visually select text>
to indent the highlighted block, or <
to unindentInstead of saving and quitting the editor to run your code, you should be
able (on the CS computers) to just hit the F9
key. We set up vim
so that
hitting F9
(might have to hit Escape
first, to get out of insert mode)
should run the code without exiting the editor. When the program is finished,
press ENTER
to get back to editing.
In command mode, it is often useful to jump to a specific line.
Hit Escape
to make sure you are in command mode, then try these:
G
go to last line of filegg
go to first line of file20G
go to line 20H
go to top of screen (high)L
go to bottom of screen (low)M
go to middle of screen (middle)