User Tools

Site Tools


user:afassett:hcp_projects:vimtut

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
user:afassett:hcp_projects:vimtut [2010/12/17 00:19] – created afassettuser:afassett:hcp_projects:vimtut [2010/12/17 03:24] (current) afassett
Line 1: Line 1:
 +====== Vim Tutorial ======
 +===== Opening Vim =====
 +A plain ol' vim opening
 +<cli> lab46:~$ vim </cli>
 +
 +To open a file in vim with the filename file
 +<cli> lab46:~$ vim file </cli>
 +
 +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.
 +<cli> lab46:~$ vim -oN </cli>
 +
 +===== 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
 +
 +==== 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.).
 +====Advance====
 +(Split screening)
 +Vim viewport keybinding quick reference
 +
 +  * :sp will split the Vim window horizontally. Can be written out entirely as :split .
 +  * 
 +  * :vsp will split the Vim window vertically. Can be written out as :vsplit .
 +  * 
 +  * Ctrl-w Ctrl-w moves between Vim viewports.
 +  * 
 +  * Ctrl-w j moves one viewport down.
 +  * 
 +  * Ctrl-w k moves one viewport up.
 +  * 
 +  * Ctrl-w h moves one viewport to the left.
 +  * 
 +  * Ctrl-w l moves one viewport to the right.
 +  * 
 +  * Ctrl-w = tells Vim to resize viewports to be of equal size.
 +  * 
 +  * Ctrl-w - reduce active viewport by one line.
 +  * 
 +  * Ctrl-w + increase active viewport by one line.
 +  * 
 +  * Ctrl-w q will close the active window.
 +  * 
 +  * Ctrl-w r will rotate windows to the right.
 +  * 
 +  * Ctrl-w R will rotate windows to the left.
 +
 +====Original source====
 +[[http://lab46.corning-cc.edu/user/bh011695/start/vimtutorial?do=show|by bh011695]]