Minimal setup.
-
Vim should be installed.
-
Git should be installed.
-
If you run
vim --versionand don't see+clipboard, you need to install thevim-gtk3package. You can research how to enable it for your specific OS. This is required in order to copy text to the OS clipboard with"+y. -
Configuration lives in
~/.vimrcor~/.vim/vimrc. -
Run
git config --global merge.tool vimdiffto set vimdiff as the merge tool. -
Run
git config --global mergetool.keepBackup falseto disable backup files. -
LSP requires plugin installation. If you want LSP support, see the LSP section. Otherwise, remove the 'Language specific settings' section from your .vimrc file.
Leader key: Space. The Leader key is pressed before a keybinding combination.
To open the Netrw file explorer from a file, run: Leader e.
Run these commands from the file explorer:
-
Create a file:
f f. -
Create a directory:
f d. -
Edit the name of the file/directory under the cursor:
f e. -
Delete the file or empty directory under the cursor:
f r.
Run these commands from the file explorer:
-
Mark a directory as the target:
Shift Tab. This is required when moving or copying files to that directory. -
Mark/unmark a file or directory:
Tab. -
Unmark all marked files and directories:
Leader Tab. -
Copy marked files/directories to the target directory:
f c. -
Copy marked files/directories to the directory under the cursor:
f C. -
Move marked files/directories to the target directory:
f x. -
Move marked files/directories to the directory under the cursor:
f X. -
Run a shell command on marked files/directories:
f ;. For example, mark a non-empty directory, use f ;, then type rm -r to delete it.
Run these commands from the file explorer:
-
Bookmark the current directory:
f b. -
Remove the most recent bookmark:
f b r. -
Go to the previous bookmarked directory:
f b g. -
Show a list of marked files:
f l m. -
Move up one directory:
-. -
Open a file in a new tab: place the cursor on a file/directory and press
t. -
Navigate to an open tab by number:
Ngt, where N is the tab number.
-
Search in files:
Leader s f. -
Search in files by specifying a path:
Leader s p. -
Search in files using grep:
Leader s g, type something, then press Enter. -
Search for the word under the cursor across all files:
Leader s g c, then press Enter. -
Show a list of recently opened files:
Leader ?.
-
Search for the word under the cursor:
*. -
Go to a specific line in the file:
:<line number>. -
Scroll down:
Ctrl d. -
Scroll up:
Ctrl u. -
Copy to clipboard:
" + y. -
Add a multi-line prefix:
Leader a a, add text to the beginning of the first line,Esc. -
Remove a multi-line prefix:
Leader a r, select all of the lines with prefix in a way that the last line selection covers all prefix, pressx. -
Go to definition:
g d. -
Follow the path under the cursor:
g f. -
Split vertically: press
von a file in the file explorer. -
Split vertically:
Leader vfrom a file. -
Open the current file in a new tab:
Leader tfrom a file. -
Toggle autocomplete in insert mode:
Shift Tab. -
Increase split window width:
Leader >. -
Decrease split window width:
Leader <. -
Equalize split sizes:
Leader =. -
Refresh the current file:
Leader rr.
-
console.log()alias:Ctrl lfrom insert mode. -
println!()alias:Ctrl pfrom insert mode.
If a merge has conflicts:
-
Open vim.
-
Press
Leader d v mto open diffview. -
Jump to the start of the next change:
]c. -
Jump to the start of the previous change:
[c. -
Obtain the difference from the other buffer. Place your cursor on the conflict and run:
do. -
Put the difference to the other buffer. Place your cursor on the conflict and run:
dp. -
Use
:diffget N, where N is the number of the buffer with the desired changes, to accept those changes.
List uncommitted files:
- Use
Leader d vto open a list of files that have been changed but not yet committed.
Diffs:
-
Show diff for the current file:
Leader d v f. -
Revert all changes for the current file:
Leader d v r.
This configuration provides LSP support for Rust, JavaScript, and TypeScript. You can see it in .vimrc by searching for Language specific settings.
Since Vim does not support LSP out of the box for all languages, you need to install LSP for your desired language. You can do this without a plugin manager:
-
mkdir -p ~/.vim/pack/vendor/start. -
cd ~/.vim/pack/vendor/start. -
git clone https://github.com/prabirshrestha/vim-lsp.git.
This is how you can install any plugin — simply clone its repository into that directory. You can name "vendor" whatever you like.
How to install LSP for Rust and JS/TS:
-
rustup component add rust-analyzer. -
npm install -g typescript typescript-language-server.
For more information about LSP configuration, see vim-lsp.
Keybindings
-
Go to definition:
g d. -
Show type information for the word under the cursor (hover):
K. -
Show code actions:
Leader c a. -
Show LSP errors in the current file:
Leader s i. -
Apply formatting:
Leader f m.
See the vim-lsp plugin documentation for additional actions.
e - jump forwards to the end of a word.
b - jump backward to the end of a word.
% - move the cursor to a matching character (default supported pairs: (), {}, [] — use :h matchpairs in Vim for more info).
0 - jump to the start of the line.
^ - jump to the first non-blank character of the line.
$ - jump to the end of the line.
g_ - jump to the last non-blank character of the line.
gg - go to the first line of the document.
G - go to the last line of the document.
} - jump to the next paragraph (or function/block when editing code).
{ - jump to the previous paragraph (or function/block when editing code).
i - insert before the cursor.
I - insert at the beginning of the line.
a - insert (append) after the cursor.
A - insert (append) at the end of the line.
o - append (open) a new line below the current line.
O - append (open) a new line above the current line.
ea - insert (append) at the end of the word.
Ctrl + w - delete the word before the cursor.
Ctrl + t - indent (move right) the line one shiftwidth.
Ctrl + d - de-indent (move left) the line one shiftwidth.
Ctrl + n - insert the next autocomplete match before the cursor.
Ctrl + p - insert the previous autocomplete match before the cursor.
r - replace a single character.
R - replace more than one character until ESC is pressed.
J - join the line below to the current one with one space in between.
cc - change (replace) the entire line.
c$ or C - change (replace) to the end of the line.
cw or ce - change (replace) to the end of the word.
s - delete the character and substitute text (same as cl).
S - delete the line and substitute text (same as cc).
u - undo.
Ctrl + r - redo.
. - repeat the last command.
v - start visual mode; mark lines, then run a command (e.g. y to yank).
V - start linewise visual mode.
Ctrl + v - start visual block mode.
a( - a block with ().
a{ - a block with {}.
at - a block with <> tags.
i( - inner block with ().
i{ - inner block with {}.
it - inner block with <> tags.
> - shift text right.
< - shift text left.
y - yank (copy) marked text.
d - delete marked text.
~ - switch case.
u - change marked text to lowercase.
U - change marked text to uppercase.
ma - set the current position as mark A.
`a - jump to the position of mark A.
`. - go to the position of the last change in this file.
qa - record macro a.
q - stop recording the macro.
@a - run macro a.
@@ - rerun the last run macro.
yy - yank (copy) a line.
Nyy - yank (copy) N lines downward.
Ny<up|down> - yank (copy) N lines up or down.
yw - yank (copy) characters from the cursor position to the start of the next word.
yiw - yank (copy) the word under the cursor.
y$ or Y - yank (copy) to the end of the line.
p - put (paste) clipboard contents after the cursor.
P - put (paste) before the cursor.
dd - delete (cut) a line.
Ndd - delete (cut) N lines downward.
Nd<up|down> - delete (cut) N lines up or down.
dw - delete (cut) characters from the cursor position to the start of the next word.
:g/{pattern}/d - delete all lines containing a pattern.
:g!/{pattern}/d - delete all lines not containing a pattern.
d$ or D - delete (cut) to the end of the line.
x - delete (cut) a character.
>> - indent (move right) the line one shiftwidth.
<< - de-indent (move left) the line one shiftwidth.
>% - indent a block with () or {} (cursor on brace).
<% - de-indent a block with () or {} (cursor on brace).
:w - write (save) the file without exiting.
:wq - write (save) and quit.
:q - quit (fails if there are unsaved changes).
:qa - quit all (fails if there are unsaved changes).
:q! - quit and discard unsaved changes.
:wqa - write (save) and quit all tabs.
/pattern - search for a pattern.
?pattern - search backward for a pattern.
n - go to the next match.
N - go to the previous match.
:%s/old/new/g - replace all occurrences of old with new throughout the file.
:%s/old/new/gc - replace all occurrences with confirmation.
:%s/old/new/gi - replace all occurrences, case-insensitive.
:%s/old/new/gI - replace all occurrences, case-sensitive.
:%s/old/new/gIc - replace all occurrences, case-sensitive, with confirmation.
You can find more Vim commands here.