linux vi vim - ghdrako/doc_snipets GitHub Wiki

Navigation

  • w – next word
  • b – beginning of the current word or previous word
  • ^ or 0 – go to the beginning of the line
  • $ – go to the end of the line
  • gg – go to the beginning of the file
  • G – go to the end of the file

Editing

  • i – enter insert mode (write actual text). I inserts at the beginning of the line.
  • a – insert text, appending after the cursor. A appends on the end of the current line.
  • o – open a new line (O opens a new line before the current one).
  • / – search for pattern (regexes work here; use ENTER to search and n and SHIFT+n to cycle forward or backward through search results).
  • dd – delete (and cut) the current line.
  • y – yank (copy) selected text.
  • yy – yank (copy) the current line.
  • p – put/paste text after the cursor.
  • u – undo the last change.
  • CTRL+R – redo.
  • nX – where n is a number and X is a command, will execute X n times. For example, 3dd will delete three lines.

Vim configuration

$cat $HOME/.vimrc:
"This breaks compatibility with vi, saying that we want to use the
benefits of vim
set nocompatible
" Enable syntax highlighting
syntax on
" Increase the command history to be very big
set history=10000
" Indent based on the previous line
set autoindent
" Make it so searches wrap around at the end of the file
set wrapscan
" Show the current mode in the command line
set showmode
" Displays partial commands in the last line
set showcmd
" Highlight searches
set hlsearch
" Use case insensitive search
set ignorecase
" Don't use case insensitive search use when using capital letters