Skip to content

Instantly share code, notes, and snippets.

@VassilisPallas
Last active October 23, 2022 22:24
Show Gist options
  • Save VassilisPallas/0865b266f1354f2158605705aefa8043 to your computer and use it in GitHub Desktop.
Save VassilisPallas/0865b266f1354f2158605705aefa8043 to your computer and use it in GitHub Desktop.
vim cheat sheet
readlink -f `which vi`
If result == /usr/bin/vim.tiny
Install the full VIM:
sudo apt update
sudo apt install vim
Now you should have /usr/bin/vim.basic
Go to Command Mode: ESC
Move arround the file
k : Moves the cursor up one line.
j : Moves the cursor down one line.
0 or | : Moved the cursor at the beggining of the line.
$ : Moved the cursor at the end of line.
v : Opens visual (select) mode. Move with `k` or `j`. Pres SHIFT+v to select lines.
h : Moves the cursor to the left one character position.
I : moved the cursor to the right one character position.
W: Positions cursor to the next word.
B : Positions cursor to previous word.
( : Positions cursor to beggining of current sentence.
) : Positions cursot to beggining of next sentence.
H : Move to top of screen.
M : Move to middle of screen.
L : Move to bottom of screen.
nH : Moves to nth line from the top of the screen.
nL : Moved to nth line from the bottom of the screen.
:x : Colon followed by a number would position the cursor on line number represented by x.
Control commands (Moving around windows)
CTRL+ww : cycle through all windows
CTRL+wh : takes you left a window
CTRL+wl : takes you right a window
CTRL+wj : takes you down a window
CTRL+wk : takes you up a window
Control commands (Scrolling)
CTRL+d : Moves forward 1/2 screen.
CTRL+u : Moves backwards 1/2 screen.
CTRL+f : Moves forward one full file.
CTRL+b : Moves backwards one full screen.
CTRL+e : Moves screen up one line.
CTRL+y : Moves screen down one line.
CTRL+u : Moves screen up 1/2 page.
CTRL+d : Moves screen down 1/2 page.
CTRL+f : Moves screen down one page.
CTRL+b : Moves screen up one page.
CTRL+I: Redraws screen.
Editing and inserting in files
i : Inserts text before current cursor location.
I : Inserts text at beggining of current line.
a : Inserts text after current cursor location.
A: Inserts text at end of current line.
o : Creates a new line for text entry below cursor location.
O : Creates a new line for text entry above cursor location.
r : Replace single character under the cursor with the next character typed.
R : Replaces text from the cursor to right.
s : Replaces single character under the cursor with any number of characters.
S : Replaces entire line.
Deleting characters
x : Deleted the character under the cursor location.
X : Deletes the character before the cursor location.
Dw : Deleted from current cursor location to the next word.
d^ : Deletes from current cursor position to the beggining of the line.
d$ : Deleted from current cursor position to the end of the line.
dd : Deletes the line the cursor is on.
gg : Deletes the first line of the file.
dG : Deletes all the lines.
Copy and paste commands
Yy : Copies the current line.
nyy: Yank current line n lines below (n is a number).
p : Puts the copies text after the cursor.
P : Puts the yanked text before the cursor.
Save and exit
q : Quit.
q! : Quit without changes.
wq : Write and quit.
r fileName : Read data from file called fileName.
w fileName : Write to file called fileName.
w! fileName : Overwrite to file called fileName.
!cmd : Runs shell commands and retusn to Command mode.
Search and Replace
/string : Search forward to file. Press n to go the next word, or N to go to the previous one.
?string : Search backward to file. Press n to go the previous word, or N to go to the next one.
:s/pattern/replace : Find string and replace the first result.
:%s:pattern/replace: Find string and replace all the results.
(the first time create the folders). bundle is a name to directory to store all the plugins. It can be any name.
mkdir -p ~/.vim/pack/bundle/start
cd ~/.vim/pack/bundle/start
git clone ${PLUGIN}
1. fzf
https://github.com/junegunn/fzf.vim
Fuzzy finding for files
2. lightline
https://github.com/itchyny/lightline.vim
Colors status
3. vim-multiple-cursors
https://github.com/terryma/vim-multiple-cursors
Multiple selections.
4. surround
https://github.com/tpope/vim-surround
Surrounding selected text
5. NERDTree
https://github.com/scrooloose/nerdtree
Interactive file tree view in a side panel
6. ALE
https://github.com/w0rp/ale
Comprehensive code analysis plugin.
7. vim-gitgutter
https://github.com/airblade/vim-gitgutter
Adds a column to the left margin indicating lines changed in the active file since the last Git revision.
8. nerdtree-git-plugin
https://github.com/Xuyuanp/nerdtree-git-plugin
Showing git status flags on NERDTree window
echo "autocmd FileType yaml setlocal ai ts=2 sw=2 et" >> ~/.vimrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment