====== Vim Tutorial ====== ===== Opening Vim ===== A plain ol' vim opening lab46:~$ vim To open a file in vim with the filename file lab46:~$ vim file The -o option adds the ability to open mutliple windows at once. N is the number of windows to open. Replace -o with -O if you want to open the windows vertically. This can also be done with previously saved files. Omit the N and enter the file names after the -o. lab46:~$ vim -oN ===== Saving in Vim ===== * :q - exit with file unchaged * :q! - exit and discard any changes to file * :wq or :zz - save and quit - If you didn't specify a filename upon opening vim add the desired filename to either of these. ===== Switching Modes ===== *esc - enters command mode *i - input mode - cursor at current position *a - append - cursor at next character position *o - places the cursor on the next line *O - places the cursor on the previous line ===== Command Mode ===== ==== Moving Around ==== *h - move left *j - move down *k - move up *l - move right *w - skip forward by word (punctuation considered) *W - skip forward by word (punctuation not considered) *b - skip backward by word (punctuation considered) *B - skip backward by word (punctuation not considered) *^ - move to the beginning of a line *$ - move to the end of a line *G - move to the last line of file *nG- move to line number N *v - begin selecting text for highlighting *dd- cut the current line *dw- cut the current word *x - delete the current character *yy- copy current line *y$ - copy from current position to end of current line *p - paste after cursor *P - paste before cursor *u - undo */ - search *n - move to next word in a search *N - move to previous word in a search *Ctrl+W,W - Move to next window ==== Random Commands ==== *:set number - display all line numbers *:syntax on - turns on syntax highlighting for scripting/programming *:set cursorline - places a bar under the current line *:set autoindent - turns on auto indentation *:%s/textToReplace/replaceTextWithThis/gc - search and replace. Remove the c to remove confirmations. % searches the entire file. This can be replace with nothing (current line only) or n (line number n). The gc can be any of the following: g (replace all occurences within the line), i (ignore character casing), I (don't ignore character casing), or c (confirm each substitution.).