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.
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
.
Command | Description |
---|---|
h | Move left by one character |
j | Move down by one line |
k | Move up by one line |
l | Move right by one character |
w | Move to the start of the next word |
e | Move to the end of the current word |
b | Move to the beginning of the previous word |
gg | Go to the beginning of the file |
G | Go to the end of the file |
Ctrl + f | Move one page forward |
Ctrl + b | Move one page backward |
H | Move to the top of the screen |
M | Move to the middle of the screen |
L | Move to the bottom of the screen |
i | Insert mode (before the cursor) |
I | Insert mode (at the beginning of the line) |
a | Append mode (after the cursor) |
A | Append mode (at the end of the line) |
o | Open a new line below the current line |
O | Open a new line above the current line |
Esc | Exit insert mode (back to normal mode) |
u | Undo the last change |
Ctrl + r | Redo the undone change |
dd | Delete the current line |
D | Delete from the cursor position to the end of the line |
x | Delete the character under the cursor |
yy | Copy (yank) the current line |
p | Paste the yanked or deleted text after the cursor |
P | Paste the yanked or deleted text before the cursor |
r | Replace a single character under the cursor |
cw | Change the current word |
C | Change the rest of the current line |
J | Join the current line with the next one |
/pattern | Search forward for pattern |
?pattern | Search backward for pattern |
n | Go to the next search result |
N | Go to the previous search result |
* or # | Search for the word under the cursor (forward/backward) |
Ctrl + f | Scroll forward one page |
Ctrl + b | Scroll backward one page |
v | Start visual mode (character-based selection) |
V | Start line-based visual mode |
Ctrl + v | Start block (column) visual mode |
y | Yank (copy) selected text |
d | Delete selected text |
> | Indent selected text |
< | Un-indent selected text |
:split or :sp | Split the window horizontally |
:vsplit or :vsp | Split the window vertically |
Ctrl + w + h/j/k/l | Move to the left, down, up, or right window |
Ctrl + w + w | Switch between open windows |
Ctrl + w + q | Close the current window |
Ctrl + w + o | Close all windows except the current one |
:tabnew | Open a new tab |
gt | Switch to the next tab |
gT | Switch to the previous tab |
:tabclose | Close the current tab |
:tabnext | Move to the next tab |
:tabprev | Move to the previous tab |
:NERDTreeToggle | Toggle the NERDTree panel |
Ctrl + w + n | Open NERDTree in a new split (if using splits) |
o | Open the file or folder under the cursor |
t | Open the file under the cursor in a new tab |
i | Open the file under the cursor in a vertical split |
s | Open the file under the cursor in a horizontal split |
m | Move a file or folder |
r | Rename a file or folder |
d | Delete a file or folder |
u | Go up one directory level |
:AirlineToggle | Toggle the display of the status line |
Ctrl + x + f | Show file finder (useful when combined with fzf.vim ) |
Tab | Trigger autocompletion suggestions |
Ctrl + n | Trigger autocompletion suggestions (alternative) |
Ctrl + p | Trigger autocompletion suggestions in reverse |
Enter | Accept the selected suggestion |
Ctrl + Space | Manually trigger autocompletion |
:CocInstall [extension] | Install an extension for Coc.nvim |
:CocConfig | Open the configuration file for Coc.nvim |
:CocList extensions | List installed extensions for Coc.nvim |
:CocRename | Rename the symbol under the cursor |
:CocDiagnostics | Show diagnostics for the current file |
:Autoformat | Format the current file |
:Autoformat! | Format the file forcefully, ignoring any errors |
autocmd BufWritePre * :Autoformat | Automatically format on file save (optional, add to .vimrc ) |
:w | Save the file |
:q | Quit Vim |
:wq | Save and quit Vim |
:x | Save and quit Vim (same as :wq ) |
:q! | Quit without saving |
ZZ | Save and quit (same as :wq ) |
u | Undo the last change |
Ctrl + r | Redo 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/g | Replace all occurrences of “old” with “new” in the entire file |
:s/old/new/g | Replace all occurrences of “old” with “new” in the current line |