vim tips

change a variable name

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).

If 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.

change indentation of a code block

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):

run code from inside vim

Instead 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.

go to a specific line

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: