Post

Vim setup journey

Vim setup journey

I really wanted to fully learn Vim and be able to use it comfortably. I guess its time. On my way for setting it up I’ll leave here notes how and where.

Vim showcase

Setup

So, first of all, I had to install python3 support for Autocomplete to work first:

1
sudo apt install vim-gtk3

Next, I configured a few plugins ChatGPT suggested. Each plugin adds some functionality to the Vim. To use install and use those plugins, here is what I did:

1
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Then I edited config file. It is a place where you specify which plugins you want to install and use. So mine config file ~/.vimrc looks something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
call plug#begin('~/.vim/plugged')

" Place plugins here, e.g.:
Plug 'sheerun/vim-polyglot'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

Plug 'preservim/nerdtree'
Plug 'vim-airline/vim-airline'
Plug 'tpope/vim-fugitive'
Plug 'neoclide/coc.nvim', {'branch': 'release'}

Plug 'tpope/vim-surround'
Plug 'Chiel92/vim-autoformat'
let g:formatdef_python = '"black --quiet -"'
let g:formatters_python = ['python']
" autocmd BufWritePre * :Autoformat

" Making it pretty XD
Plug 'joshdick/onedark.vim'
Plug 'ryanoasis/vim-devicons'

call plug#end()
syntax enable
colorscheme onedark

For icons to display I had to download and install font: nerd-fonts

By the way, while looking for Vim plugins, I stumbled upon this website: vimawesome.com

Usage

So now let’s talk about usage. To open file explorer, type :NERDTree.

CommandDescription
hMove left by one character
jMove down by one line
kMove up by one line
lMove right by one character
wMove to the start of the next word
eMove to the end of the current word
bMove to the beginning of the previous word
ggGo to the beginning of the file
GGo to the end of the file
Ctrl + fMove one page forward
Ctrl + bMove one page backward
HMove to the top of the screen
MMove to the middle of the screen
LMove to the bottom of the screen
iInsert mode (before the cursor)
IInsert mode (at the beginning of the line)
aAppend mode (after the cursor)
AAppend mode (at the end of the line)
oOpen a new line below the current line
OOpen a new line above the current line
EscExit insert mode (back to normal mode)
uUndo the last change
Ctrl + rRedo the undone change
ddDelete the current line
DDelete from the cursor position to the end of the line
xDelete the character under the cursor
yyCopy (yank) the current line
pPaste the yanked or deleted text after the cursor
PPaste the yanked or deleted text before the cursor
rReplace a single character under the cursor
cwChange the current word
CChange the rest of the current line
JJoin the current line with the next one
/patternSearch forward for pattern
?patternSearch backward for pattern
nGo to the next search result
NGo to the previous search result
* or #Search for the word under the cursor (forward/backward)
Ctrl + fScroll forward one page
Ctrl + bScroll backward one page
vStart visual mode (character-based selection)
VStart line-based visual mode
Ctrl + vStart block (column) visual mode
yYank (copy) selected text
dDelete selected text
>Indent selected text
<Un-indent selected text
:split or :spSplit the window horizontally
:vsplit or :vspSplit the window vertically
Ctrl + w + h/j/k/lMove to the left, down, up, or right window
Ctrl + w + wSwitch between open windows
Ctrl + w + qClose the current window
Ctrl + w + oClose all windows except the current one
:tabnewOpen a new tab
gtSwitch to the next tab
gTSwitch to the previous tab
:tabcloseClose the current tab
:tabnextMove to the next tab
:tabprevMove to the previous tab
:NERDTreeToggleToggle the NERDTree panel
Ctrl + w + nOpen NERDTree in a new split (if using splits)
oOpen the file or folder under the cursor
tOpen the file under the cursor in a new tab
iOpen the file under the cursor in a vertical split
sOpen the file under the cursor in a horizontal split
mMove a file or folder
rRename a file or folder
dDelete a file or folder
uGo up one directory level
:AirlineToggleToggle the display of the status line
Ctrl + x + fShow file finder (useful when combined with fzf.vim)
TabTrigger autocompletion suggestions
Ctrl + nTrigger autocompletion suggestions (alternative)
Ctrl + pTrigger autocompletion suggestions in reverse
EnterAccept the selected suggestion
Ctrl + SpaceManually trigger autocompletion
:CocInstall [extension]Install an extension for Coc.nvim
:CocConfigOpen the configuration file for Coc.nvim
:CocList extensionsList installed extensions for Coc.nvim
:CocRenameRename the symbol under the cursor
:CocDiagnosticsShow diagnostics for the current file
:AutoformatFormat the current file
:Autoformat!Format the file forcefully, ignoring any errors
autocmd BufWritePre * :AutoformatAutomatically format on file save (optional, add to .vimrc)
:wSave the file
:qQuit Vim
:wqSave and quit Vim
:xSave and quit Vim (same as :wq)
:q!Quit without saving
ZZSave and quit (same as :wq)
uUndo the last change
Ctrl + rRedo the undone change
.Repeat the last command (great for repeating edits)
m[char]Set a mark at the current position (e.g., ma sets a mark at position “a”)
'[char]Jump to the position of mark [char] (e.g., 'a jumps to mark “a”)
:%s/old/new/gReplace all occurrences of “old” with “new” in the entire file
:s/old/new/gReplace all occurrences of “old” with “new” in the current line
This post is licensed under CC BY 4.0 by the author.