vi editor is case sensitive (Example: vi prog.c)

  Two modes: command (type ESC) and insertion mode (type i, a, …)

  commands in command mode

=  h/j/k/l: cursor moves ¬/¯/­/®

=  i (insert): insert before cursor, I: insert at the beginning of the line

=  a/A (append): insert after cursor/the end of a line

=  dw (delete word): delete a word and x: delete a character

=  yy(dd): 9 yy(dd) means copy(delete) 9 lines

words copied(deleted) are put in a buffer

=  p and P: paste the words stored in the buffer

=  rC: replace a character pointed to by the cursor with character C

=  .(dot)/u: redo/undo previous command

=  0/$: cursor moves to the beginning/end of a line

=  w/e: goes to next word/go to the end of the word

=  G: G goes to the end of file, nG goes to the nth line of the file

=  cwNewWord: replace the word pointed to by the cursor with NewWord

=  /Word: find the Word

=  n: find next Word

=  J: the line pointed to by the cursor is appended with the following line

=  cntl g: display file name and the number of lines in the file, etc.

=  :1,ns/int/INT/c: replace int with INT in lines 1 to n with confirmation, if c is replaced with g, it means no confirmation

=  :wq (write the file and quit),

=  :w (save):q! quit without save

=  :s prog1.c (save to file prog1.c)

=  mc: to mark a place named c and 'c to go to the marked place

=  "a5yy: to yank 5 lines to a named buffer a, and "ap to paste

=  d'a:delete from current cursor position to marker a

=  y'a: yank from current cursor position to marker a

disable vi color: ‘:syntax off’ (or edit .vimrc file in root directory)

remove the problem of Chinese characters inside vi

iconv -f big5 -t utf-8 InFilename-o OutFilename

Put .vimrc in user’s $HOME directory as the following example

set cindent

set smartindent

set hls

set nocompatible

set sw=3

set showmatch

set background=light

colorscheme desert

set hlsearch

highlight Search term=reverse ctermbg=4 ctermfg=7

highlight Normal ctermbg=black ctermfg=white

""""set color 1"""" darkcyan, blue, Green

"hi Comment ctermfg=Green

""""set color 2""""

highlight Comment ctermfg=darkcyan

%: (toggle braces)

The % key can be used for the following:

To jump to a matching opening or closing parenthesis, square bracket or a curly brace: ([{}])

To jump to start or end of a C-style comment: /* */.

To jump to a matching C/C++ preprocessor conditional: #if, #ifdef, #else, #elif, #endif.

To jump between appropriate keywords, if supported by the ftplugin file, for example, between begin and end in a Pascal program.

Restart a stopped process after accidentally pressing “CTL-Z”(undo in Word): Use commands ps, kill -19 PID, and fg (or fg PID)

gdb, ulimit -c unlimited, gdb ./mytest core, bt,list

gcc -D name: Predefine name as a macro, with definition 1.

-D name=definition

The contents of definition are tokenized and processed as if they appeared during translation phase three in a ‘#define’ directive. In particular, the definition will be truncated by embedded newline characters.