Vim Basics
Published: 2022-11-07
Vim has been my text editor of choice for a couple of years. Vim (a contraction of vi improved) is a CLI text editor based on vi. It does have a learning curve as it's keyboard driven rather than menus or icons. I've been using for the entirety of this website, for posts (including this one), for editing configs, and also for to do lists. Although running vimtutor
has been helpful in learning Vim, here are some basics for navigation and other functionality.
Navigation
Command |
Description |
j |
move down |
k |
move up |
h |
move left |
l |
move right |
L |
move to bottom of screen |
H |
move to top of screen |
$ |
move to end of the line |
0 |
move to beginning of the line |
i |
insert text |
I |
insert text at the beginning of the line |
gg |
move to very top of document |
G |
move to very bottom of document |
shift+left/right arrow |
next word/previous word |
Saving & Exiting
Command |
Description |
:w |
write/save file |
:q |
quit |
:q! |
force quit without saving |
:wq |
write/save and quit |
Copy/Paste/Delete
Command |
Description |
yy |
yank/copy |
dd |
cut line |
p |
paste text after cursor |
P |
paste text before cursor |
x |
delete |
X |
backspace |
u |
undo |
:redo |
redo |
Other Useful Commands
Command |
Description |
gq |
reformat line to paragraph |
:set spell spelllang=en_us |
enables English spellcheck |
:%s/value1/value2/g |
Find and replace 'value1' with 'value2' |
:set linebreak |
Creates linebreaks after word rather than character. Useful for writing. |
:colorscheme [space] [tab] |
Cycle through the different preinstalled vim color themes. |
:w !wc -w |
Display wordcount |
Useful websites
Vim Tips and Tricks
vim.org
Thanks for reading. Feel free to send comments, questions, or recommendations to hey@chuck.is.