Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| computer:software:cheatsheets:vim [2026/09/05 18:16] – admin | computer:software:cheatsheets:vim [2026/09/06 17:43] (current) – [Line Numbers] neotek | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Vi / Vim Cheatsheet | + | ===== Vi / Vim ===== |
| ==== Open Files, save and exit ==== | ==== Open Files, save and exit ==== | ||
| Line 14: | Line 14: | ||
| === Navigation === | === Navigation === | ||
| < | < | ||
| - | h # cursor left | + | h |
| - | j # cursor down | + | j |
| - | k # cursor up | + | k |
| - | l # cursor right | + | l |
| - | 0 # (zero) move to beginning of the line | + | 0 |
| - | $ # move to the end of the line | + | $ |
| - | w # move to the beginning of the next word | + | w |
| - | } # skip to next section | + | } |
| - | H # Jump to the beginning of the displayed screen | + | H |
| - | M # Jump to the center of the displayed screen | + | M |
| - | L # Jump to the bottommost line shown | + | L |
| - | CTRL-f | + | CTRL-f |
| - | CTRL-b | + | CTRL-b |
| - | CTRL-d | + | CTRL-d |
| - | CTRL-u | + | CTRL-u |
| - | gj | + | gj # For very long lines that wrap at the screen edge, jump up one line. |
| - | gk | + | gk # For very long lines that wrap at the screen edge, jump down one line. |
| - | % # Jump to the next bracket character (){}[] | + | % |
| </ | </ | ||
| Line 41: | Line 41: | ||
| O # insert a line above | O # insert a line above | ||
| 12i < | 12i < | ||
| - | y # yank text (copy) | + | y |
| - | d # delete | + | d |
| - | dt' | + | dt' |
| - | df' | + | df' |
| - | c | + | c |
| - | y$ | + | y$ # copy to the end of the line (yank) |
| - | y5l | + | y5l |
| - | yt( # copy everything to the round bracket | + | yt( |
| - | d2w # delete two words | + | d2w |
| - | c2j | + | c2j |
| :undo or u | :undo or u | ||
| :redo or CTRL-R | :redo or CTRL-R | ||
| </ | </ | ||
| + | |||
| + | ==== complex editing ==== | ||
| + | === Commenting 1 === | ||
| + | < | ||
| + | CTRL-q | ||
| + | SHIFT-i | ||
| + | # type '#' | ||
| + | ESC Press ESC | ||
| + | </ | ||
| + | |||
| + | === Commenting 2 === | ||
| + | Add '# ' in the beginning of line 5 to 12 | ||
| + | < | ||
| + | :5,12s/^/# / | ||
| + | </ | ||
| + | |||
| + | === Uncomment 1 === | ||
| + | < | ||
| + | CTRL-q | ||
| + | q press q | ||
| + | </ | ||
| + | |||
| + | === Uncomment 2 === | ||
| + | remove '# ' from the beginning of line 5 to 12 | ||
| + | < | ||
| + | :5,12s/^# // | ||
| + | </ | ||
| + | |||
| + | ==== Split window ==== | ||
| + | < | ||
| + | $ vi file1.txt | ||
| + | :split file2.txt | ||
| + | :q # close file2.txt | ||
| + | :vsplit file2.txt | ||
| + | :CTRL-w l # change to the right window | ||
| + | :CTRL-w h # change to the left window | ||
| + | :CTRL-w j # change to the bottom window | ||
| + | :CTRL-w k # change to the top window | ||
| + | </ | ||
| + | |||
| + | ==== Line Numbers ==== | ||
| + | < | ||
| + | :set nu # show line numbers | ||
| + | :set nonu # hide line numbers | ||
| + | :set ruler # show horizontal and vertical cursor position at the bottom right of the terminal | ||
| + | :set rnu # show relative line numbers | ||
| + | :set nornu # hide relative line numbers | ||
| + | </ | ||
| + | |||
| + | ==== .vimrc example file ==== | ||
| + | < | ||
| + | set hidden | ||
| + | set ruler | ||
| + | set tabstop=4 | ||
| + | set mouse=r | ||
| + | set number | ||
| + | set relativenumber | ||
| + | set relativenumber number | ||
| + | set ruler | ||
| + | set nocp | ||
| + | filetype plugin on | ||
| + | set background=dark | ||
| + | hi Comment cterm=italic ctermfg=69 gui=italic guifg=# | ||
| + | hi Constant ctermfg=172 | ||
| + | hi Function ctermfg=9 | ||
| + | </ | ||
| + | |||
| + | |||
| + | |||
| + | |||