User Tools

Site Tools


user:afassett:hcp_projects:vimtut

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

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

user/afassett/hcp_projects/vimtut.txt · Last modified: 2010/12/16 22:24 by afassett