- Write to a new file
-
:w FileName
- To search a file
-
/ThingToLookFor
- To search and replace
-
:s/ThingToReplace/ThingToWrite
- - globally
-
:%s/ThingToReplace/ThingToWrite/g
- - globally with confirmation
-
:%s/ThingToReplace/ThingToWrite/gc
Useful configuration:
syntax on- enables syntax highlighting
colorscheme desert- my favorite colorsheme
set bg=dark- makes the background dark (and the text bright enough to stand out on it)
set hlsearch- highlights search results in the file
let fortran_free_source=1- Ignores the rule that lines in Fortran files should stop after a certain number of characters
set wrap linebreak nolist- Enable graphical line wrapping without breaking words
set nowrap- Disable line wrapping
Macros
Recording macros allows you to repeat certain tasks much more efficiently. To record a macro, type q char where char is a character that the macro will be tied to (a letter, a number), ex.: q 2 to tie a macro to the 2 key. Once that is done, a message appears at the bottom of the window, showing recording, indicating that vi is recording your actions so it can reproduce them later. Performing the actions as usual, followed by pressing q again once out of insert/replace mode, will create the macro. To use it, type @char where char is the same as previously, ex.: @2.
Alternatively, to perform the macro multiple times in a row, you can first time the number of reps, then @ char: 10@2