Start, Save, and Quit
- Start:
vi {filename}
- Save:
Esc + :w
- Quit:
Esc + :q
- Quit w. Saving:
Esc + :wq
- Quit w.o. Saving:
Esc + :q!
Moving the Cursor w.o. mouse
- Left:
h
or ←
- Right:
l
or →
- Down:
j
or ↓
- Up:
k
or ↑
- Move Left/Right/Down/Up {n} times (Operation Pending Mode):
{n}h/j/k/l
Move the Cursor by word
- Forward:
w
(word)
- Backward:
b
(backward)
- End:
e
(end of word)
- Fowrard by space:
W
- Backwrad by space:
B
Move the Cursor by line
- Start of the line:
0
- Start of the line (except spaces):
^
- Find the first match of a {char} in the line:
f + {char}
- Then, type
;
to find the next match and ,
for the previous match.
- End of the line:
$
Search
- Search a {word}:
/{word} + Enter
- Then, type
n
for the next match and N
for the previous match.
- Search the word at the current position:
*
- Scroll up a line:
Ctrl + e
- Scroll up a half page:
Ctrl + u
- Scroll down a line:
Ctrl + y
- Scroll down a half page:
Ctrl + d
- Move to the start of the file:
gg
- Move to the end of the file:
G
Shift between Modes
- Command Mode -> Instert Mode:
a/i/o/A/I/O
- Command Mode -> Command-line Mode:
:
- Insert Mode -> Command Mode:
Esc
or Ctrl + [
- Command Mode -> Visual Mode:
v/V/Ctrl+v
Undo & Redo (IMPORTANTTT)
- Undo:
u
- Redo:
Ctrl + R
- Repeat the last action:
.
Delete, Yank (Copy), and Paste in Visual Mode
- Delete:
d
- Yank (Copy):
y
- Paste:
p
Select words w. Visual Mode
- Select a word:
viw
(visual in word)
- Select words in ():
vi(
- Select words in {}:
vi{
- Select words in []:
vi[
- Select words in ‘’:
vi'
- Select words in “”:
vi"
- Yank words:
yiw
(yank in word)
Replace words w. Visual Mode
- Ask each match:
:%s/{before}/{after}/c
- Without asking:
:%s/{before}/{after}/g
Control Windows
- Split:
:sp
- Vertical Split:
:vs
- Shift between Windows:
Ctrl + w + h/j/k/l
- Quit the current Window:
:q
- Open a new file in the current Window:
:enew
Edit multiple files
- Open the file explorer:
:E
- Show the open files (buffers):
:ls
- Move to the next file (buffer):
:bn
(buffer next)
- Move to the previous file (buffer):
:bp
(buffer previous)
- Close the current file (buffer):
:bd
(buffer delete)
Example .vimrc
set nocompatible
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8,cp949
set termguicolors
set background=dark
set number
set relativenumber
set cursorline
set ruler
set showcmd
set wildmenu
set wildmode=longest:list,full
set title
set showmatch
set matchtime=2
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set smartindent
set hlsearch
set incsearch
set ignorecase
set smartcase
nnoremap <Space> :noh<CR>
nnoremap <C-s> :w<CR>
inoremap <C-s> <Esc>:w<CR>
vnoremap <C-c> "+y
nnoremap <C-v> "+p
inoremap <C-v> <C-r>+
nnoremap <C-a> ggVG
autocmd FileType python setlocal expandtab shiftwidth=4 softtabstop=4
autocmd FileType python setlocal tabstop=4
autocmd FileType python setlocal autoindent
autocmd FileType python setlocal smartindent
autocmd FileType python setlocal foldmethod=indent
autocmd FileType python setlocal colorcolumn=80
autocmd FileType python setlocal textwidth=80
autocmd FileType python nnoremap <buffer> <F5> :w<CR>:!python3 %<CR>
autocmd FileType sh setlocal expandtab shiftwidth=4 softtabstop=4
autocmd FileType sh setlocal tabstop=4
autocmd FileType sh setlocal autoindent
autocmd FileType sh setlocal smartindent
autocmd FileType sh setlocal foldmethod=marker
autocmd FileType sh nnoremap <buffer> <F5> :w<CR>:!bash %<CR>
autocmd BufWritePost * silent! call delete(expand('<afile>') . '~')
set autoread
set clipboard=unnamedplus
set backup
set undofile
set history=1000
set lazyredraw
set ttyfast
set synmaxcol=200
set updatetime=300
Leave a comment