vim
PLEASE NOTE:
I am in the process of making my notes public. This docs section is still work in progress. It currently is a summary of random tips for various things.
Found a mistake? Want to add something? Feel free to open an issue, send a pull request or an e-mail.
- General info:
- Homepage
- Wikipedia
- Source code
- Documentation
- Manual
- Blog posts
- Usefull links:
- Fandom Wiki
- Vimhelp.org - FAQ
Basics
How to exit VIM
:q
# Quit
:q!
# Quit and discard changes
w
# Save
:x
# Save & Exit
ZZ
# Save & Exit
:wq
# Save & Exit
Config files
- Linux:
-
~/.vimrc
- for current user -
/etc/vim/vimrc
- All users - Windows:
-
$HOME/_vimrc
- current user - macOS:
-
$HOME/.vimrc
- current user -
/usr/share/vim/.vimrc
- All users
Note: system wide config file will be ignored, if you have one in your $HOME
directory.
- Find out, what config file you are currently using:
:echo($MYVIMRC)
- Comment for the .vimrc file can be added with
"
: - e.x.
"that is a comment for the .vimcr file.
Undo/ Redo
u
- undo
ctrl
+ r
- redo
Navigation/ Movement
Move cursor within screen
- Move within the screen:
-
H
to the top of the screen -
M
to the middle of the screen -
L
to the bottom of the screen - Jump to the next character with
f
and previous character withF
: -
fd
# jump to the nextd
-
f%
# jump to the next%
-
F%
# jump to the previous%
Move screen around
Ctrl
+ b
# Move up a full screen
Ctrl
+ u
# Move up a half a screen
Ctrl
+ f
# Move down a full screen
Ctrl
+ d
# Move down a half a screen
Split screen
- Vertical split:
-
ctrl
+w
, thenv
:vs /dir/file
:Vexplore
- Horizontal split:
-
ctrl
+w
, thens
:sp /dir/file
:Sexplore
- Opens file manager:
:ex
- Navigate to another screen:
-
ctrl
+w
, thenh
,j
,k
orl
Searching
- Searching without regard to the case (uppercase or lowercase):
-
:set ignorecase
# for this session or add to config file -
/\c<pineapple>
# ignore case a single time - Searching:
-
/pineapple
# Searching forward -
?pineapple
# Searching backwords - Jumping to the next result:
-
n
#jumps to the next result -
N
#jumps to the previous result - Highlighing the current work under the cursor:
-
*
# Searching forward -
#
# Searching backwards - Remove highlights:
:noh
Changing/ Deleting content
The following commands in this section also work with y
and c
- Delete content between certain chars:
di"
di<
-
diB
# between brackets - and so on
- Delete content between HTML tags:
-
dit
# inner HTML tag -
dat
# with other HTML tag
Miscellaneous
- Insert output of commands into vim, e.x.::
r!<CMD>
:r!date
:r!ip -br a
- Execute command within vim:
:! ping 127.0.0.1
- Change type of the file temporary:
-
:set ft=py
# e.x. switch .md syntax highlighting to .py - Inser content from another file to cursor position:
-
:r /dir/file
# Using it for snippets and templates - Use auto completion in insert mode. Useful for variables and long words:
-
C-n
orC-p
(in front or after the cursor) - Whole-line auto completion (inser mode)
-
C-x
+C-l
(+C-l
) to jump to next enrty - Auto completion for file path on your system (insert mode):
-
C-x
+C-f
- Execute normal commands without leaving the insert mode:
C-o
Marks and jumps
- Set mark for key
a
: -
m
+a
- Jump to mark
a
: -
`
+a
- Show all marks:
:marks
- Clear all marks:
delm! | delm A-Z0-9:
Visual mode
- Select whole line:
-
Shift
+v
- Re-select previous selection:
-
g
+v
E-Mail
hello
- TODO:
- auto complete
- .vim folder
- vimrc
- marcos
- bookmarks
- marks
- test it without my own config