| Command | Description |
|---|---|
| :help | Learn how to navigate vim's help system. |
| :help vim-modes | Learn more about vim's modes. |
| Toggle between help and editor window. | |
| :q | Quit help. |
| :help windows | Learn how to use multiple windows. |
1966 QED (Quick EDitor)
:
1969 ed (Pronounced "E D", not "ed".)
:
1975 em (Editor for Mortals)
:
1976 ex (EXtended)
:
1979 vi (VIsual mode for ex)
:
1990 :.... elvis
:
1991 vim (Vi IMproved) <--- WE ARE HERE
:
2015 neovim
1 #!/usr/bin/bash
2 echo $RANDOM
1 #!/usr/bin/env bash
2 let n=${1:-1}
3 for (( i=0; i<n; i++ ))
4 do
5 echo $[$RANDOM*6/32768+1]
6 done
1 #!/usr/bin/env bash
2 let n=${1:-1}
3 echo $(
4 for (( i=0; i<n; i++ ))
5 do
6 echo $[$RANDOM*6/32768+1]
7 done | sort -n
8 )
4,7s/^/ /
6s/^/ /
1 #!/usr/bin/env bash
2 let n=${1:-1}
3 echo $(
4 for (( i=0; i<n; i++ ))
5 do
6 echo $[$RANDOM*6/32768+1]
7 done | sort -n
8 )
| ed | ex | vim | Description |
|---|---|---|---|
| ,n | set nu[mber] %p |
:set nu[mber] | Display entire buffer with line numbers. |
| i | i | O | Insert above current line. |
| a | a | o | Append below current line. |
| . | . | Exit insert mode. | |
| s/^/text/ | s/^/text/ | 0itext | Insert text at beginning line. |
| s/$/text/ | s/$/text/ | Atext | Append text to end of line. |
| d | d | dd | Delete current line. |
| j | j | J | Join current and next line. |
| /re | /re | /re | Search for regular expression re. |
| ?re | ?re | ?re | Search backward for re. |
| g/re/p | g/re/p | :g/re/p | Print every line matching re. |
| s/re/replacement/ | s/re/replacement/ | :s/re/replacement/ | Replace first re match with replacement in current line. |
| s/re/replacement/g | s/re/replacement/g | :s/re/replacement/g | Replace all re matches in current line. |
| %s/re/replacement/g | %s/re/replacement/g | :%s/re/replacement/g | Replace all re matches in document. |
| u | u | u | Undo last command. |
| w [filename] | w [filename] | :w [filename] | Write buffer to filename. |
| q | q | :q | Quit (exit) editor. |
| Q | Q | :q! | Quit without writing buffer. |
| wq [filename] | wq [filename] | :wq [filename] | Write and quit. |
| Command | Description |
|---|---|
| set nocompatible | 50 levels of undo/redo, ex command line recall, and more! |
| set showmode | Show when vim is in INSERT, REPLACE, or VISUAL mode. |
| set number | Show line numbers. |
| set ruler | Show line and column where cursor is at all times. |
| set incsearch | Enable incremental search. |
| set nohlsearch | Disable search highlighting. |
| set ignorecase smartcase | Ignore case if search pattern is all lowercase. |
| set tabstop=8 | Place tabs at proper location. |
| set shiftwidth=4 | Set indent level to 4 spaces. |
| set expandtab | Insert spaces, not actual characters. |
| set autoindent | Enable autoindent. |
| set smartindent | Indents correctly in code. Mostly... |
| set cindent | Stricter rules for C code. |
| set showmatch | Highlight matching parentheses and braces. |
| syntax off | Turn off syntax highlighting. |
| Normal mode command | Description |
|---|---|
| Lowercase | Begin character-wise visual selection mode. |
| Uppercase | Begin line-wise visual selection mode. |
| Begin block-wise visual selection mode. |
| Visual mode command | Description |
|---|---|
| Lowercase | Delete selection. |
| Lowercase | Yank (copy) selection. |
| Lowercase | Put (paste over) selection. |
| Uppercase | Convert selection to uppercase. |
| Lowercase | Convert selection to lowercase. |
| , | Shift selection left, or right. |
| Exit visual mode. |
| Command | Description |
|---|---|
| :help visual-mode | Learn about vim's visual mode. |
| mode | modes the macro is active for |
|---|---|
|   | normal and visual |
| n | normal only |
| v | visual only |
| i | insert only |
| c | cmdline only |
| Command | Description |
|---|---|
| :help Q | Show what uppercase should do in normal mode. |
| :map Q | Show normal and visual mode mappings for uppercase . |
| :unmap Q | Remove normal and visual mode mappings for uppercase . |
| :map <c-a> 0 | Map to move to beginning of line (in normal mode),
or select to beginning of line (in visual mode). |
| :map <c-e> $ | Map to move to end of line (in normal mode),
or select to end of line (in visual mode). |
| :nmap x dd | Map to delete current line (in normal mode). |
| :nnoremap \ x | Non-recursively map to delete current character (in normal mode). |
| :nmap # 0i# <esc>0j | Map to comment out a line. |
| :map | Show key mappings for normal and visual modes. |
| :help map-modes | Learn about vim's map commands and modes. |
| :help map-examples | Get some more inspiration! |
| Register | Usage |
|---|---|
| "" | The "unnamed" register receives text from delete, change, and yank commands, even when another register was explicitly specified, and provides text for put commands where a register was not explicitly specified. |
| "0 | Receives or provides text from the last yank command. |
| "1 .. "9 | The "numbered" registers receive or provide text from the last 9 delete or change commands that did not explicitly specify a register.
(See :help quote9 for exceptions.) |
| "- | The "small delete" register recevies or provides text from the last command that deleted less than one line and did not explicitly specify a register. |
| "/ | Provides the last search pattern. (It is used by the n and N commands.) |
| ". | Provides the last text inserted. |
| "% | Provides the current filename. |
| "* | Provides the last X11 selection. |
| "+ | Receives or provides the current X11 clipboard. |
| "a .. "z
"A .. "Z |
The "named" registers receive or provide text only when explicitly specified.
The uppercase variants append to their previous contents. |
| "_ | The "black hole" register prevents delete and change commands from affecting other registers. |
| Command | Description |
|---|---|
| "%P | Put current file name. |
| "+3yy | Yank 3 lines to the X11 clipboard. |
| :reg[isters] | Dispay contents of all registers. |
| :help registers | Learn about vim's registers. |
$ vimtutor # Possibly the best half hour you could invest.
$ gvim # Pay particular attention to keyboard shortcuts in the menu.
$ man vimdiff # Recommended tool.
$ stat -c '%i %N' {/bin,/usr/bin,/etc/alternatives}/{ex,view,vi,vim*} 2>/dev/null | sort -n
Learn Vimscript the Hard Way by Steve Losh