Vim

move

  • h,j,k,l
  • w,b,e
  • G: go to top
  • gg: go to end
  • { }, skip a block of code
  • V: select line
  • ctrl-v: select block of code (same column)
  • ^: begin line, $: end of line
  • t/f + char: go to the specific char in the line
  • %: go to specific parenthese
  • *: search for other instance

change

  • u: undo
  • ctrl+r: redo
  • yy: Copy line
  • p: paste below
  • P: paste above
  • dd
  • dw
  • D: delete to the end of line
  • o: insert line below
  • O: insert line above
  • c: change
  • x: delete char
  • ~: change the case of char
  • r: replace char
  • < : 增加缩小缩进

  • yt+char:复制到那个char

search

替换改行的第一个old单词为new :s/old/new

替换改行的所有old单词为new :s/old/new/g

替换两个# 之间的单词 :#,#s/old/new/g

替换文件中所有的单词 :%s/old/new/g

每一个替换之前都需要确认的话,在命令末尾加一个 c :%s/old/new/gc

Config

basic

  • filetype on
    • " Enable type file detection. Vim will be able to try to detect the type of file in use.
  • filetype plugin on
  • filetype indent on
  • syntax on
  • set number
    • show line number
  • set cursorline
    • Highlight cursor line underneath the cursor horizontally.
  • set shiftwidth=4
  • set tabstop=4
  • set hlsearch
  • set incsearch
    • While searching though a file incrementally highlight matching characters as you type.
  • set showmatch
    • Show matching words during a search.
  • set history=1000
    • Set the commands to save in history default number is 20.
  • set wildmenu
    • Enable auto completion menu after pressing TAB.
  • set wildmode=list:longest
  • set wildignore=.docx,.jpg,.png,.gif,.pdf,.pyc,.exe,.flv,.img,.xlsx
  • set ttyfast
  • set showmode
  • set encoding=utf-8

status bar

" STATUS LINE ------------------------------------------------------------ {{{

" Clear status line when vimrc is reloaded.
set statusline=

" Status line left side.
set statusline+=\ %F\ %M\ %Y\ %R

" Use a divider to separate the left side from the right side.
set statusline+=%=

" Status line right side.
set statusline+=\ ascii:\ %b\ hex:\ 0x%B\ row:\ %l\ col:\ %c\ percent:\ %p%%

" Show the status on the second to last line.
set laststatus=2

" }}}

%F – Display the full path of the current file.

%M – Modified flag shows if file is unsaved.

%Y – Type of file in the buffer.

%R – Displays the read-only flag.

%b – Shows the ASCII/Unicode character under cursor.

0x%B – Shows the hexadecimal character under cursor.

%l – Display the row number.

%c – Display the column number.

%p%% – Show the cursor percentage from the top of the file.

key mapping

map_mode <what_you_type> <what_is_executed>

nnoremap – Allows you to map keys in normal mode. inoremap – Allows you to map keys in insert mode. vnoremap – Allows you to map keys in visual mode.

use

  • add ~/.vimrc
  • load :so %