botbotbot 's blog

Vim

Tutorial

$ vimtutor

Enter to Vim

  vim . # open with file browse
  vim -c "h quickref | only"
  vim -O < file1 > < file2 > ... # open in verticle
  vim -o < file1 > < file2 > ... # open in honzital

Normal Mode

Save, Exit

Keys Description
ZZ save and quit
ZQ save without quit

Movements

Keys Description
w[ord] {letters, numbers, underscore}
W[ORD] {non-blank characters}
g{motion} work with display line ex. gj down one line, g$ go to end of display line
f{char} move to next char
t{char} move to before next char
; repeat last search
, repeat last search backward

Jump

Keys Description
% jump between open/close parentheses
<C-o>, <C-i> toggle jump position
{num}|(pipe) Go to Column
<number>G go to line number

Visual

Keys Description
v{motion} visual mode select in line
V{motion} visual mode select line
<C-v>{motion}{cIA} change/insert/append in multiple lines
<C-v>{motion}: command with multiple lines

Indent

Keys Description
== Auto Indent
= Auto Indent in selected on visual mode
J join the current line and next line together

Edit

Keys Description
cw change word
gu{motion}, gU{motion} lower/upper letter

Delete

Keys Description
daw delete a word
das delete a sentence
dap delete a paragraph
dW delete until space
dG delete until end of file
d$ delete until last of line
dbw , <C-w> in insert mode delete back one word
d^ , <C-u> in insert mode delete back to start of line

Undo

Keys Description
u redo
<C-r> Redo
Keys Description
\<word>\c search word with ignore case

Repeat

Keys Description
. repeat last action (not include any move action)

ETC

Keys Description
* highlight word
<C-a>,<C-x> addition and subtraction on numbers that also find next number automatically if current cursor not a number
<C-I> Tab
<C-[> Esc
<C-M> Enter
<C-H> Backspace

In Insert Mode

Keys Description
<C-r>=55*10<Cr> in insert mode calculate can print it

Windows Managements

Windows Split

Keys Description
<C-ws> Split windows
<C-wv> Split windows vertically
<C-wq> Quit windows
<C-ww> switch between windows

You split navigations with

nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

Tab

Command Description
:tabe[dit] {filename} open file in new tab use gt, gT to move to next, previous tab
:tabc[lose] close all tabs
:tabo[nly] keep current tab and closing all others

Vim spell

Command Description
:set spell enable spell checker
[s, ]s jump to miss spelling work
z= fix miss spelling word
zg add current word into spell dictionary
zw remove current word from spell dictionary

Repositioning the screen

Command Description
zt Move current line to top screen
zz Move current line to mid screen
zb Move current line to bottom screen

Scroll Screen

Keys Description
<C-f> scroll down one screen
<C-b> scroll up one screen
<C-d> scroll down half screen
<C-u> scroll up half screen

Text object <need to combine with cmd>

Keys Description
iw/aw inside/around word
is/as inside/around sentences
ip/ap inside/around paragraph
it/at inside/around tag ex. html tag
i” inside double quote
i) inside parents

Register

# update vim version
$ brew install vim
$ brew install reattach-to-user-namespace
Command Description
:reg[ister] check buffer register
”<register>p paste buffer
”<register>yy yank to buffer
”*yy yank to system clipboard

Vim Command

Vim Plugins

Vim Script

  1. autocmd group

Vim Performances

Open vim without plugin no settings from your .vimrc

$ vim -u NONE -N

Open vim without plugin

$ vim --noplugin

Reference:

  1. A vim Tutorial and Primer
  2. วิธีใช้ Vi และ Vim
  3. How to Use Vim’s Spell checker
  4. Vi/Vim Cheat Sheet
  5. Vim Cheat Sheet Graphical
  6. Vim & Tmux & System Clipboard
  7. vim.rc & vim plugin (video th)
  8. John Crepezzi’s Vim (video)
  9. Vi and Vim Macro Tutorial: How To Record and Play
  10. VIM Grammar-Jaa-LGyagRA
  11. Vim tips: Folding fun
  12. Learn Vimscript the Hard Way
  13. Vim as an IDE
  14. How to jump directly to a column number in Vim 17.Coming Home to Vim
  15. Vim-LanguageTool
  16. Vim Tips (KKLUG)
  17. Vim multiline editing like in sublimetext?
  18. A Good Vimrc
  19. THE VIM PRESENTATION
  20. Vim Cast
  21. vim-galore - Everything you need to know about Vim.
  22. Converting tabs to spaces