vim learning notes

Last update: 25. 8. 2023


Show help in top window or left window

help leader
vert help leader

change window focus


change ordering


.vimrc quicky




apt install vim-gtk # vim-gtk3
ctrl+alt+v < should now work to paste stuff from other clipboard, or
middle-mouse-button < paste behaves differently
"+p < paste from other clipboard 
"+gp < this horror should paste as well
"+yy < copy current line
"+y20 < copy this and 20 lines below
:help "+ < actually finds clipboard related help


Open multiple files in tabs:

vim -p one.txt two.txt three.txt

shortkeys in normal mode

gt < next
gT < previous
{i}gt < go to tab at position i


:e filename < opens file
:tabe filename < opens file in new tab
:qall < close all and exit

make each buffer appear in tab

:tab sball


:buffers or :ls < list buffers
:bi < jump to buffer i, where i is buffer number
:bn :bp < next, previous buffer

Buffers, windows, and tabs

netrw - default dir browser can do a lot

:Sexplore or :Sex < in horizontal split
:Vexplore < in vertical split
:Texplore < in new tab

configure explorer in .vimrc


?pattern < backward
n N < repeat
* < search for word under cursor
:%s/old/new/g < replace
:%s/old/new/gc < with confirmations



gg < goto start of file
G < goto end of file
end, home < end, start of line (also 0 and $)
i, o < insert or insert on next line
a < insert after selected char
dw < delete word
ci+brackets < delete stuff inside brackets
:w < write
:wq < write and quit
:q < quit
:q! < quit without saving
di( < delete inside ()

b < to go to beginning of current or previous word
w < to go the beginning of next word
e < to go to the end of current or next word
ge < to go the end of the previous word
# Try :h word-motions for more details and how to combine them with operations.

less obvious

ggVG < select contents of entire file
U < selected text to UPPERCASE                                           
u < selected text to lowercase                                     
:retab < convert tabs to spaces 


In insert mode start typing something and then



In insert mode

ctrl+t < insert indent at start of line
ctrl+d < remove indent at start of line

In normal mode

>> < indent line by shiftwidth spaces
<< < deindent line 
3>> < indent 3 lines

In visual mode, select lines and »

Click for more


:split < horizontal
:vsplit < vertical    
ctrl+w+j < move down a screen
ctrl+w+k < up
ctrl+w+h < left
ctrl+w+l < right    
:only < close others

read/insert a file or command output into current

:0r !ls < insert output of ls before 0 line
:0r !head ~/bin/somescript < similar
:r < below the cursor
:$r !pwd < below the last line


not a snippet

Just insert head part of say previous file that will now act as a template

:r !head previous_file

to shell and back again

ctrl+z, fg < will push vim to bg, fg in shell will bring it back



:shell or just :sh "do your shell stuff" then 

insert output of the shell command to the current document

:r ! ls


One can also execute commands directly from the editor

:! python %

will run the active (must be saved) file with python interpreter.


vi and vim are the same, they are symbolic links to


vi and vim are the same on OSX as well.

latest vim on OSX

brew install vim # brew update && brew upgrade # before that if needed
# should install in /usr/local/bin/vim
# do a softlink in user bin if defined and on $PATH, like
cd $HOME/bin
ln -s /usr/local/bin/vim vim # that should now call brew installed vim in the future sessions

vim 8 and plugins



q: a: Your problem with Vim is that you don’t grok vi.