If you’ve been following me for a while, you might know my editor of choice is VIM, it’s very clean. There’s nothing there to get in your way, except your own limitations, and those limitations can be destroyed through practice. Haven’t tried vim yet? What are you waiting for?
Vim is a text editor written by Bram Moolenaar and first released publicly in 1991. It is commonly found on unix-based operating systems. VIM is based off an older text editor, vi, and it’s name is an acronym for Vi-Improved. With vim Your fingers never have to leave the keyboard to command great power. The learning curve is a little steep but you can very quickly pick up new skills as you need them. The basic premise is that there is an Input mode and a Command mode. By default you start in command mode, here you can move around the document, search, and do a fair bit of editing quickly. Insert mode is designed for adding (and removing) text, it’s just like a normal text editor.
Vim commands are more of a language than a list of commands you need to use.
vim file1.txt file2.sh
they’re placed into buffers
:bn
, or the previous one with :bp
, to move to the next or previous buffer.vim -o file.type file2.type file3.type
(lower case “o” for horizontal, uppercase for vertical split)vim +10 file.type
for the 10th line (+
alone will jump to the end of the file)vim +FunctionName +qall
(qall
tries to quit all, but refers to the user to accept or reject changes made with a standard :w
/q!
)vim -c "/searchstring" file.type
(you can execute other commands with the -c
flag too)vim -d file.v1 file.v2
(this works like vimdiff)note: ‘i’ doesn’t mean “enter insert mode” so much as it is a command to “insert the following text until you hit ESC” Also, “command mode” is often referred to as “normal mode,” because for a lot of tasks, you will probably want to use a bunch of commands, instead of writing a bunch of stuff in input mode.
j
move down one linek
move up one lineh
move left one characterl
move right one character88G
or 88gg
gg
G
w
b
$
0
^
%
while the cursor is on a bracket like [({})]
will find the matching bracketx
dd
yy
5dd
p
to paste after the current lineP
to pase before the current lined$
, for example, or any other movement key (wbhjkl…)apple
type /apple
and hit enter
n
:s/original/replacement/g
:%s/original/replacement/g
q:
q/
or q?
):help
there’s a wealth of information there
:help help
:help index
I’m not sure how useful these are in gvim, but these should work if you’re running in a terminal.
alt+hjkl
offers the standard movementsalt+o
opens a new line below the current onealt+A
appends to the end of the current linealt+p
to pastealt+R"
to paste from register "
, for example, or use and other register.:w !sudo tee %
:r /path/to/file.txt
or if you don’t supply a file it will insert the current file below the cursor.:s
doesn’t have to be /
you can try %
or \_
if you want to avoid fences like in :s/\/usr\/local\/bin/\/common\/bin/
you can use :s#/user/local/bin#/common/bin#
equalprg
in your vimrc, you can auto-indent with =
gg=G
(could have “unexpected” results)==
=j
where j
is a movement key=
m
followed by a letter like ma
, it accepts [A-Za-z] so you get 52 different marks.
'
(single quote) command 'a
moves to the line containing the mark labeled a
`
(backquote) command `a
moves to the mark labeled a
d`a
to cut text from the cursor’s location to the mark labeled a
q
command,
qa
to create a macro named a
(should show a record indicator) enter a series of commands and hit q
again to stop recording.@a
to execute the macro named a
, you can execute the command multiple times in the standard way 23@a
will repeat it 23 times.@A
for register A
, for example, or use any other register.:@A
for register A
, for example, or use any other register.Vim is highly customizable, you can set shortcuts and preferences in the .vimrc
file, usually located in your home directory. There are a ton of plugins (aka scripts) available too. They’re easy to manage with other scripts like Pathogen, Vundle, or vim-plug. I just switch from vundle to vim-plug because it makes it easier to configure your plugins and does it a lot faster.
If you want to get a headstart, my dotfiles are available on github, but there are a lot of people doing that lately, so look around. Also there’s a few very nice VIM Distributions like Janus, SPF13-vim, and dotvim that have a lot of plugins and a nice vimrc right out of the box, definitely worth a look.
:godmode: