linux vi vim - ghdrako/doc_snipets GitHub Wiki
:se number
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
" set tab to 4 space
set tabstop=4
" automatic convert tab to space
set expandtab
" Make it so searches wrap around at the end of the file
set wrapscan
" Show the current mode in the command linΔ 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
" Show line numbers
set number