# vim makefile
or
# vim +52 makefile
or
# vim +/getIPAdr ui_task.c
# vim -u NONE -N
vim -x file.txt
:ver
:Exp
or
:E
or
:Sex
or
:S (Type i to toggle thin/long/wide/tree view)
:e
:args ./subfolder/**/*.am
:cd %:p:h
:set autochdir
ctrl + w then n
or
:enew
:set all
:set tabstop=4
==
:set number
or
:set nu
:set nonumber
:set nu!
:set relativenumber!
:%! nl -ba
or
:%!cat -n
:set list
:set nolist
or
:set list!
:set listchars=tab:\»\ ,trail:.,extends:\>,precedes:\<
or
:set lcs=tab:\»\ ,trail:\.,extends:\>,precedes:\<
:set showmode
:set noshowmode
or
:set showmode!
:set encoding=utf-8
then open the file.
:e! ++enc=utf-8
:w ++ff=unix
or
:set ff=unix
:%s/\r//g
:g/^\s*$/d
qaq:g/pattern/y A
:v/./,/./-j
:set hlsearch
/<space>
/<tab>
/asdf (just search anything else to clear highlight)
:nohlsearch
or
:set hls!
Ctrl + -
Ctrl + +
1 then Ctrl + g (Or :f)
mk
'k
`k
:marks
]'
['
]`
[`
`.
or
g;
:115
:reg
:set foldmethod=indent
:scriptnames
:ab
:set paste
:%!xxd
or
:%!xxd -s 0x650 (offset to 0x650)
or
:%!hexdump -C
:%!xxd -r
or
u
:%!od -t u1
or
:%!od -t u2
za
zi
zc
zo
q
@q (the first time)
@@ (after that)
20@@ (Repeat 20 times)
$ ctags -R -f ~/test.ctags ~/Project/src/test
:set tags=~/test.ctags
:ta func = go to func definition
:ts = shows the list.
:tn = go to the next tag in that list.
:tp = go to the previous tag in that list.
:tf = go to the function which is in the first of the list.
:tl = go to the function which is in the last of the list.
$ cscope -Rqbk -f ~/test.cscope
or
$ cscope -Rb
or
$ find . -name '*.{c,h}' > ./cscope.files (csh shell)
$ find . -name "*.c" -o -name "*.h" > ./cscope.files (bash shell)
$ cscope -Rb
:cscope add =~/test.cscope ~/Project/src
:cs kill 0
:cs add cscope.out
:cs f g = find all global definition (Or Ctrl + \ g)
:cs f c = find function calling this function (Or Ctrl + \ c)
:cs f d = find function called by this function (Or Ctrl + \ d)
:cs f e = egrep (Or Ctrl + \ e)
:cs f f = open file (Or Ctrl + \ f)
:cs f s = find C symbol (Or Ctrl + \ s)
Ctrl + ]
or
:ta
Ctrl + t
or
:pop
Ctrl + o
Ctrl + i
:changes
g,
:jumps or :ju
:Ctrl + f
or
q:
q/
a
or i
or o
escape
or Ctrl + c
or Ctrl + [
h = left
j = down
l = up
k = right
0 = Go to beginning of line
$ = Go to end of line
w = forward one word (or Ctrl + right)
b = backward one word (or Ctrl + left)
B = to beginning of white space delimited word
e = to end of word
E = to end of white space delimited word
:124 = Go to line 124 (Or 124G)
% = jump to matching #if, #else {}, (), [], /* */
Ctrl + b = page up
Ctrl + f = page down
H = high (top of screen)
M = mid (medium of screen)
L = low (bottom of screen)
gg = go to beginning of file(Or 1G) (Or [[)
G = go to end of file(Or ]])
Ctrl + o = navi forward one old cursor position
Ctrl + i = navi backward one old cursor position
Ctrl + w then s = split the current window horizontally (Or :sp)
Ctrl + w then v = split the current window vertically (Or :vs)
Ctrl + w then c = close the current window
Switch two or more windows to vertically or horizontally
Ctrl + w then H = to vertically
:windo wincmd H = to vertically
Ctrl + w then K = to horizontally
:windo wincmd K = to horizontally
Ctrl + w then down = navigate to window below current window (Or Ctrl + w j)
Ctrl + w then up = navigate to window above current window (Or Ctrl + w k)
Ctrl + w then left = navigate to window left to current window
Ctrl + w then right = navigate to window right to current window
Ctrl + w then w = navigate to window above (wrap)
Ctrl + w then Ctrl + w = navigate to window below (wrap)
Ctrl + w then p = navigate to previous window
Ctrl + w then o = close other window except this (only)
Ctrl + w then < = make window wider
Ctrl + w then > = make window narrower
Ctrl + w then + = make window higher
Ctrl + w then - = make window lower
:30winc >
:30winc <
:set lines+=4
:set lines-=4
:vertical resize 150 = make window size 150 character wide
:resize +50 = make window horizontal size 50 character more
Ctrl + w then H = move window vertically split at right
Ctrl + w then L = move window vertically split at left
Ctrl + w then J = move window horizontally split at bottom
Ctrl + w then K = move window horizontally split at top
:e ../myFile.c = edit/open a file (Or edit in new filetab :tabe ../myFile.c)
:b myFile.c = to switch between filetab
:b <tab-key> = providing auto-completion (awesome !!)
:sp ../myFile.c = edit/open a file as horizontal split
:vsp ../myFile.c = edit/open a file as vertical split
:ls = to list buffer(filetab)
:3b = to switch to 3rd buffer(filetab)
:3sb = to switch to 3rd buffer(filetab) with split window
:3bd = to delete 3rd buffer(filetab)
:3bw = to wipe 3rd buffer(really freed memory)
:bw% = to wipe current buffer(really freed memory)
Ctrl + 6 = to toggle between now and previous buffer(filetab)
:%bd = to close all buffer
:bufdo bdelete = to close all buffer
:tabe <filename> = opens new file in filetab
:tabn = go to next filetab (Or Ctrl + pageup)
:tabp = go to previous filetab (Or Ctrl + pagedown)
:tabc = close current filetab
:tab sball = opens a new tab for each open buffer (Or :tab sba)
gt = go to next filetab
gT = go to previous filetab
`. = go back to previous modification spot
Indicators (chars in the same column are mutually exclusive):
u an unlisted buffer (only displayed when [!] is used)
|unlisted-buffer|
% the buffer in the current window
# the alternate buffer for ":e #" and CTRL-^
a an active buffer: it is loaded and visible
h a hidden buffer: It is loaded, but currently not
displayed in a window |hidden-buffer|
- a buffer with 'modifiable' off
= a readonly buffer
+ a modified buffer
x a buffer with read errors
/searchstring
or
?searchstring (search backward)
# = search the word under cursor, previous
* = search the word under cursor, next
n
N
/\csearchstring
/\<searchstring\>
:g/searchstring/
[I
/<C-R><C-W>
:g/searhstring
:set noignorecase or :set noic
:set ignorecase or :set ic
:bufdo vimgrepadd "searchstring" %
:copen or :cw
:grep -Hrn "searchstring" ~/Project/src
:copen or :cw
(first plan the cursor at 1st location)
v = character selection
V = line selection
Ctrl + v = column mode selection
(then copy or cut)
y = copy the selection
d = cut the selection
(then paste)
p = paste selection after cursor
P = paste selection before cursor
(then find and replace)
:%s/find/replace/gc
:%s#find#replace#gc
:%s_find_replace_
:%s:find:replace:
:%s%find%replace%
:%s!find!replace!
(then sort, after visual line selection)
!sort
:%!sort -u
viw = got to visual mode and select inner word
o = exchange cursor position in the highlight
g Ctrl-G
V = Line selection mode
cursor up, down = Line selection
< = unindent
. = repeat the unindent
> = indent
>aB = indent a block
>iB = indent inner block
yw (Or inner word yiw)
yy
5yy
or
y5y
p
v
V
Ctrl + v
gv
Ctrl + v
Select the columns and rows where you want to enter your text
Shift + i = go into insert mode in column mode
Type in the text you want to enter. Don't be discouraged by the fact that only the first row is changed.
Esc = apply your change (or alternately Ctrl+c)
Ctrl + v
Select the columns and rows where you want to enter your text
Shift + i = go into insert mode in column mode
x = delete
Esc = apply your change (or alternately Ctrl+c)
Shift + v
Select the rows where you want to enter your text
:norm i// = add // in front, ":'<,'>norm i//" will appear at cmdline
gv = reselect previous selection
:norm xx = remove // in front, ":'<,'>norm xx" will appear at cmdline
"ayy
"ap
Shift + v (do line selection at current)
"ay (copy to register "a", "a mean refer to register a)
"Ay (copy and Append to register "a")
:2b (switch to buffer no 2) (Or gt)
"ap (paste from register "a", "a mean refer to register a)
Ctrl + r then 0 (from vi clipboard, i.e. after yiw cmd) (Or Ctrl + r then ")
or
Shift + Insert (from windows clipboard)
or
"*p (Register * is windows clipboard)
Ctrl + r then % (in edit mode)
Ctrl + r then Ctrl + w (in edit mode)
noremap x "_x
vnoremap p "_dP
:verbose nmap <C-Right>
d
x
dd
u
. (Or Ctrl + r)
@:
.
Ctrl + p
Or
Ctrl + n
Ctrl + r then = Calculation result will be in the doc
or in command mode
:echo (2+3)*0xA
:echo 0x123
:echo printf('%x',56)
:%s/find/replace/gc
or
:%s#find#replace#gc
:%s:find:replace:gc
:%s!find!replace!gc
:%s%find%replace%gc
or
:1,$s/find/replace/gc
:%s/\<findthis\>/replacethis/g
:%s/^\(Martin\)/Mr \1/g
:%s/[ <tab>]*$//
or
:%s_\s\+$__
or
:%s#\s\+$##
or
:1,$s/[ <tab>]*$//
:%s#\s*\r\?$##
:%s/^\n\{3}//
:s/\(.*\):\(.*\)/\2 : \1/
:%s/^\(.*\)\n\1/\1$/
:%s/^\(.*\)\n\1$/\1/
Shift + v
:'<,'>%s#abc#xyz#
gf = open file in same window
Ctrl + w then f = open file in new window
ga
g8
~
Vu
VU
ctrl + a
ctrl + x
:sh
Ctrl + d
:!./tmake.sh
:!ls -al
:r!date
or
:.!date
:w
:w !sudo tee %
:wq
:sav newfile.txt
:x
or :wq
or ZZ
:q
or :q!
or :qall!
or ZQ
vimdiff file1 file2 (Or in vi with file1, :vert diffsplit file2)
or
vi -d file1 file2
vim -c ':DirDiff /tmpfolder1 /tmp/folder2'
:diffthis
:diffupdate
:sp <filename>
:windo diffthis
:diffoff!
:set diffopt+=iwhite
or
vim -c 'set diffopt+=iwhite' file1 file2
:set diffopt-=iwhite
[c (Or [czz)
]c (Or ]czz)
do (Or :diffget)
dp (Or :diffput)
:diffupdate
zo
zc
zR
zM
zi
:mks (Default session file Session.vim)
or
:mks! (Overwrite)
or
:mks myproject.ses (or :mksession -f myproject.ses)
$ vim -S (Default session file Session.vim)
or
$ vim -S myproject.ses
or within vi
:source myproject.ses (or :so myproject.ses)
:verbose map
:verbose map <F12>
remap = recursive mapping
noremap = no recursive mapping
nnoremap = normal, no recursive mapping
vnoremap = visual, no recursive mapping
Mode letters
n : normal only
v : visual and select
o : operator-pending
x : visual only
s : select only
i : insert
c : command-line
l : insert, command-line, regexp-search (and others. Collectively called "Lang-Arg" pseudo-mode)
Run PuTTY Configuration.
In the left pane, select Terminal, Features.
Put a check mark next to "Disable application keypad mode".
In the left pane, select Session.
Save the settings.
https://www.zinkwazi.com/unix/notes/vimtips.html
Sample .vimrc at home directory
"General
let bg=dark
:colorscheme murphy
syntax on
set number
set numberwidth=5 "Set line numbering to take up 5 spaces
set tabstop=4 "Set tab character to 4 characters
set shiftwidth=4 "Indent width for autoindent
set cursorline "Highlight current line
set autoread "Set to auto read when a file is changed from the outside
set hlsearch "Set highlight search on
set dir=~/.vim-tmp "Set swp file directory
set nobackup
set nowritebackup
set noswapfile
"Code folding settings
set foldmethod=marker "fold based on marker
set foldmarker={,} "fold marker is {,} instead of default {{{,}}}
set foldnestmax=10 "deepest fold is 10 levels
set nofoldenable "don't fold by dault
set foldlevel=0 "this is just what i use
"Default encoding
set encoding=utf-8
set fileencoding=utf-8
"Custom template definition
:ab #s <TAB>switch(RemoteKeycode){<CR><TAB><TAB>case KEY_PLAY:<CR><TAB><TAB><TAB>//<CR><TAB><TAB><TAB>break;<CR><TAB><TAB>default:<CR><TAB><TAB><TAB>//<CR><TAB><TAB><TAB>break;<CR><TAB>}<CR>
:ab #i <TAB>if(IsComBusy() == TRUE){<CR><TAB><TAB>;<CR><TAB>}else<CR><TAB>if(IsMoveAckNG()){<CR><TAB><TAB>;<CR><TAB>}<CR><TAB>else{<CR><TAB><TAB>;<CR><TAB>}<CR>
:ab #p printf("%s %s() line%d m_value=0x%x \n",__FILE__,__func__,__LINE__,m_value);
:ab #d // BugID 00000 AngKH <c-r>=strftime("%Y-%m-%d %a %I:%Mpm")<CR>
"For DirDiff
let g:DirDiffExcludes = "CVS,*.class,*.exe,.*.swp,*.o,.git,.deps,.svn,*.lsp,*.a,*.log"
"Keymapping, find in files
map <C-M-f> <ESC>:grep -Hrns <c-r>=expand("<cword>")<CR>:copen<CR><CR>
"Keymapping, find in files
map <F3> <ESC>/<c-r>=expand("<cword>")<CR><CR>
"Keymapping, previous diff
map <F7> <ESC>\[c<CR><Tab>
"Keymapping, next diff
map <F8> <ESC>\]c<CR><Tab>
"Keymapping, convert open files to filetabs
map <F9> <ESC>:tab sba<CR>
"Keymapping, show tag list on right hand side
map <F10> <ESC>:TlistToggle<CR><CR>
"Keymapping, find symbol/definition
map <F11> <ESC>:cs find g <C-R>=expand("<cword>")<CR><CR><Tab>
"Comment/Uncomment
map <Leader>. :call ClojureCommentUncomment()<CR>
function! ClojureCommentUncomment()
let search_saved = @/
if getline('.') =~ '^\/'
s/^\/\/// " remove ';' at beginning of line
else
s/^/\/\// " insert ';' at beginning of line
endif
let @/ = search_saved
endfunction