星期五, 3月 24, 2006

[Note]vimrc and shortcut keys

After I refered to several articles, I adjust the final vimrc. I post vimrc in the end of this post for future reference.

References:

If you are reading the C/C++ source code, you can use ctags to generate tags for C/C++ source code.
Usage:
ctags -R

Then, you can use
set tags=your_tag_file

to load tags. When you want to see where the identifier and functions is, you can press g ctrl+] or ctrl+] to jump.
If you wanna return, press ctrl+t.
If you wanna find the matched quote, press % (shift+5).
ctags can also generate tags file for c# source code.
Reading source code is not boring anymore. I should accepted Irene's advice 3 years ago.

Beside, Vim can coordinate with Vim Intellisense, vim is really powerful...

The following is vimrc

" Inherit gvim win32 settings
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

" Hide mouse cursor when you are typing
set mousehide

" Load tags automatically.
set tags=./tags,tags

" Don't backup.
set nobackup

" Auto indent / Indent
set autoindent
set cindent

" show ruler
set ruler

" Highlight matched quote
set showmatch

" tab
set shiftwidth=4
set tabstop=4

" syntax highlight
syntax on

" expand tab to space.
" set et
" opposite
" set noet

" The following setting is copied from here: http://edt1023.sayya.org/vim/node10.html
" 使用 :update 代替 :w,以便在有修改時才會存檔,注意,這和 vi 不相容。
map <F2> :up<CR>
map <F3> :up<CR>:q<CR> " 存檔後離開
map <F4> :q!<CR> " 不存檔離開
map <F5> :bp<CR> " 前一個 buffer 檔案
map <F6> :bn<CR> " 下一個 buffer 檔案
" 單鍵 <F7> 控制 syntax on/off。倒斜線是 Vim script 的折行標誌
" 按一次 <F7> 是 on 的話,再按一次則是 off,再按一次又是 on。
" 原因是有時候顏色太多會妨礙閱讀。
map <F7> :if exists("syntax_on") <BAR>
\ syntax off <BAR><CR>
\ else <BAR>
\ syntax enable <BAR>
\ endif <CR>
" 按 F8 會在 searching highlight 及非 highlight 間切換
map <F8> :set hls!<BAR>set hls?<CR>
" Toggle on/off paste mode
map <F9> :set paste!<BAr>set paste?<CR>
set pastetoggle=<F9>
map <F10> <ESC>:read !date<CR> " 插入日期
map <F11> :%!xxd<CR> " 呼叫 xxd 做 16 進位顯示
map <F12> :%!xxd -r<CR> " 回復正常顯示

" The default function.
set diffexpr=MyDiff()
function MyDiff()
let opt = '-a --binary '
if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
let arg1 = v:fname_in
if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
let arg2 = v:fname_new
if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
let arg3 = v:fname_out
if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
if &sh =~ '\<cmd'
silent execute '!""C:\Program Files\Vim\vim64\diff" ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . '"'
else
silent execute '!C:\Program" Files\Vim\vim64\diff" ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
endif
endfunction

沒有留言: