Vincent Touache - Character TD
/tutos/16_vim_cheatsheet/content.php
data=================:ArrayVim cheat sheet

Table of Contents

  1. Bread & Butter
  2. Vim Diff
  3. Marks
  4. Folding
    1. Manual folding
    2. Marker folding
    3. Indent folding
    4. Syntax folding
    5. Diff folding



Bread & Butter

i insert mode
a insert mode after the cursor
A insert mode at the end of the line
o insert mode in a new line below the current line
O insert mode in a new line above the current line
x delete the character under the cursor
r replace the character under the cursor
d delete whatever motion comes next, e.g. dw will delete a word
diw delete the name under the cursor even if cursor in the middle of the name
di( delete the content of what's between the current parentheses. Works with {, etc...
dd delete the full current line
c delete and insert (change) whatever motion comes next, e.g. cw will delete a word and put you in insert mode
ciw delete and insert (change) the name under the cursor even if cursor in the middle of the name
ci( delete and insert (change) the content of what's between the current parentheses. Works with {, etc...
cc delete and insert (change) the current line
u undo
ctrl+r redo
:early 1m move 1 minute earlier in the document history
:later 1m move 1 minute later in the document history
/search_text search for "search_text" in the document (forward)
?search_text search for "search_text" in the document (backward)
n next occurrence
N previous occurrence
* search word under cursor
# search word under cursor (backward)
]d Go to next lsp error (requires a LSP setup). Equivalent to :lua vim.diagnostic.goto_next()
]d Go to previous lsp error (requires a LSP setup). Equivalent to :lua vim.diagnostic.goto_prev()
:%s/{searchFor}/{replaceBy} search for searchFor and replace it with replaceBy only for the first occurrence found
:%s/{searchFor}/{replaceBy}/g same but for the entire document (globally)
:%s/{searchFor}/{replaceBy}/gc same but with confirmation before replacing
y yank (copy) the current selection
yy yank (copy) the current line
p paste what's been yanked after cursor
P paste what's been yanked before cursor
gU change the case to uppercase. E.g. gUw will switch all the word to uppercase
gu change the case to lowercase. E.g. gUw will switch all the word to lowercase
~ toggle case between lower and upper
>> indent right the current line
<< indent left the current line
> indent right the selected line or block
< indent left the selected line or block
v visual mode
$ end of line
0 beginning of line
^ first non-blank character
w move to the beginning of the next word
w move to the end of the current word
b move to the beginning of the previous word
G move to the end of the file
gg move to the beginning of the file
{ previous paragraph (block of text separated by an empty line)
} next paragraph (block of text separated by an empty line)
gw{direction} reformat the current line to not exceed 80 lines of width

Vim Diff

You can run vim in diff mode (like a git diff) using:

vim -d {file1} {file2}

Marks

Marks allow to jump directly to a specific line and column within the same document

If you don't want to user :marks to list your current marks, you can use the plugin vim-signature

More info about marks here

Folding

Manual folding

let you select manually your folding. E.g. zf, then you select 4 lines. Those 4 lines will become foldable. Likewise, zf5j will make the 5 rows below foldable together

Marker folding

Uses predefined markers that you set everywhere. By default, it's {{{ and }}} ("set foldmarker" to see it yourself). If you want to change it, "set foldmarker={opening_pattern}, {closing_pattern}, although not recommended. The idea behind the marker folding is to have a shortcut to add those markers where you want them, but it's very "vim" oriented and may bother other developers working on your project.

Indent folding

Groups lines with the same indent

Syntax folding

Close to indent, but will follow language logics, e.g. folding if blocks regardless of the indent below

Diff folding

Used when opening vim in diff mode, collapse everything similar between fileA and fileB