"F1~F12快捷键映射
""{{{
map <F2> :BufExplorer<CR>
nnoremap <silent> <F3> :Grep<CR>
map <F4> :TlistToggle<CR>
"map <F5> : LookupFile<CR> "插件中已映射
noremap <F6> :make<CR>
nnoremap <silent> <F7> :A<CR>
map <F8> :NERDTreeToggle<CR>.
"nmap <F8> :SrcExplToggle<CR>
"nnoremap <silent> <F9> :ConqueTerm bash<CR>
map <C-F12> :!ctags -R --c++-kinds=+p --fields=+ialS --extra=+q .<CR>
nmap <S-F12> ::%s//s/+$//g<CR>
""}}}
"F1~F12快捷键映射
"非F1~F12快捷键
""{{{
let mapleader=","
let g:mapleader=","
map <leader>svi : source ~/.vimrc <CR> " fast reloading of the .vimrc
map <leader>evi : e! ~/.vimrc <CR> " fast editing of .vimrc
map <leader>ms : marks <CR> "显示所有标记的marks
map <leader>dms : delm! <CR> "删除所有标记的marks
noremap /a :A<CR> "a.vim 插件
"map <leader>sb : set scrollbind <CR>
"map <leader>nsb : set noscrollbind <CR>
"map <leader>ls : set laststatus=2 <CR>
"map <leader>nls : set laststatus=1 <CR>
"map <leader>sy : set syntax=on <CR>
"map <leader>nsy : set syntax=off <CR>
"map <leader>dsm : DoShowMarks <CR> "插件showmarks.vim支持, 显示当前buff中的所有marks
"map <leader>nsm : NoShowMarks <CR> "插件showmarks.vim支持, 隐藏当前buff中的所有marks
"nnoremap <Leader>c : set cursorline! cursorcolumn! <CR>
""}}}
"非F1~F12快捷键
"简单配置
"{{{
"打开语法色彩
syntax enable
"打开语法色彩
"打开关键字色
syntax on
"打开关键字色
"侦测文件类型
filetype on
"侦测文件类型
"载入文件类型插件
filetype plugin on
"载入文件类型插件
"为特定文件类型载入相关缩进文件
filetype indent on
"为特定文件类型载入相关缩进文件
"设置VIM颜色主题
"term 黑白终端的属性
"cterm 彩色终端的属性
"ctermfg 彩色终端的前景色
"ctermbg 彩色终端的背景色
"gui GUI 版本属性
"guifg GUI 版本的前景色
"guibg GUI 版本的背景色
colorscheme elflord
"colorscheme morning
"colorscheme evening
"colorscheme desert
"设置VIM颜色主题
"预览窗口,eg. ctr+w { 时的窗口大小
set previewheight=10
"预览窗口,eg. ctr+w { 时的窗口大小
"设置弹出菜单的高度
set pumheight=15
"设置弹出菜单的高度
"使用鼠标
set mouse=a
"使用鼠标
"autocmd
if has("autocmd")
autocmd BufEnter * :lchdir %:p:h
endif
"autocmd
"映射快捷键开始命令,缺省为'/'(已经移到上面)
"let mapleader=","
"let g:mapleader=","
"映射快捷键开始命令,缺省为'/'(已经移到上面)
"解决consle输出乱码
language messages zh_CN.utf-8
"解决consle输出乱码
"在Linux下设置字体的命令是:
:set guifont=Monospace:12
"在Linux下设置字体的命令是:
"可用来改动补全时采用的方式
:set wildmode=list:full
"可用来改动补全时采用的方式
"可用来取得菜单式的匹配列表
:set wildmenu
"可用来取得菜单式的匹配列表
"修改一个文件后,自动进行备份,备份的文件名为原文件名加“~“后缀
"if has("vms")
" set nobackup
"else
" set backup "vim main.c 多出 main.c~文件用来保存打开前的原文件, 最后可用vimdiff main.c main.c~比较
"endif
"修改一个文件后,自动进行备份,备份的文件名为原文件名加“~“后缀
"写备份但关闭vim后自动删除
set writebackup
"set nowritebackup
"写备份但关闭vim后自动删除
"vi兼容开关
set nocp "当使用omni自动补全时,要设置
"vi兼容开关
"不使用swap文件
"set noswapfile
set swapfile
"不使用swap文件
"显示匹配的括号([{和}])
set showmatch
"显示匹配的括号([{和}])
"显示日期的缩写
iab xdate <c-r>=strftime("%Y-%m-%d %H:%M:%S")<cr>
"显示日期的缩写
"关闭遇到错误时的声音提示
set noerrorbells
"关闭遇到错误时的声音提示
"不要闪烁
set novisualbell
"不要闪烁
"使用空格来替换tab
set expandtab
"set et
"使用空格来替换tab
"在vim编辑器下方显示命令
set showcmd
set cmdheight=1
"在vim编辑器下方显示命令
"当光标达到上端或下端时 翻滚的行数
set scrolljump =5
"当光标达到上端或下端时 翻滚的行数
"当光标达到水平极端时 移动的列数
set sidescroll =5
"当光标达到水平极端时 移动的列数
"当光标距离极端(上,下,左,右)多少时发生窗口滚动
set scrolloff =0
"当光标距离极端(上,下,左,右)多少时发生窗口滚动
"当使用vimdiff比较文件,相比较的比较文件同步滚动,但是splite分割窗口, 两个窗口也同步, 有时候挺有用的.
"set scrollbind
"set noscrollbind
"当使用vimdiff比较文件,相比较的比较文件同步滚动,但是splite分割窗口, 两个窗口也同步, 有时候挺有用的.
"将当前编辑文件的路径设置为当前路径
set autochdir
"将当前编辑文件的路径设置为当前路径
"自动读写相关
set autoread " read open files again when changed outside Vim ( 同步 )
set autowrite " write a modified buffer on each :next , ... ( 跳到另一个文件时,自动保存上个文件 )
"自动读写相关
"设置VIM行号
set nu
"set nonu
"设置VIM行号
"Tab 宽度
set ts=4
"Tab 宽度
"自动缩进的时候, 缩进尺寸
set sw=4
"自动缩进的时候, 缩进尺寸
"打开 VIM 的状态栏标尺
set ru
"打开 VIM 的状态栏标尺
"显示括号配对情况
set sm "smartmatch
"显示括号配对情况
" 开启新行时使用智能自动缩进
set smartindent
" 开启新行时使用智能自动缩进
" 搜索时忽略大小写,但在有一个或以上大写字母时仍保持对大小写敏感
set ignorecase smartcase
" 搜索时忽略大小写,但在有一个或以上大写字母时仍保持对大小写敏感
" 输入搜索内容时就显示搜索结果
set incsearch
" 输入搜索内容时就显示搜索结果
" 搜索时高亮显示被找到的文本
set hlsearch
" 搜索时高亮显示被找到的文本
"打开 C/C++ 风格的自动缩进 ( =a{ , gg=G 代码美化 )
set cin
"打开 C/C++ 风格的自动缩进 ( =a{ , gg=G 代码美化 )
"允许backspace和光标键跨越行边界 ( 不习惯 )
"set whichwrap+=<,>,h,l
"允许backspace和光标键跨越行边界 ( 不习惯 )
"内容多时,换行显示
"set wrap
set nowrap
"内容多时,换行显示
"启动的时候不显示那个援助乌干达儿童的提示
set shortmess=atI
"启动的时候不显示那个援助乌干达儿童的提示
"通过使用: commands命令,告诉我们文件的哪一行被改变过 ( 不习惯 )
"set report=0
"通过使用: commands命令,告诉我们文件的哪一行被改变过 ( 不习惯 )
"在被分割的窗口间显示空白,便于阅读 (没看到效果)
set fillchars=vert:/ ,stl:/ ,stlnc:/
"在被分割的窗口间显示空白,便于阅读 (没看到效果)
"带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
"带有如下符号的单词不要被换行分割
" 中文帮助
set helplang=cn
" 中文帮助
" 设定doc文档目录
let helptags=$VIMFILES.'/doc'
" 设定doc文档目录
" 保留历史记录
set history=500
" 保留历史记录
" 英文单词在换行时不被截断
set linebreak
" 英文单词在换行时不被截断
" 设置每行多少个字符自动换行,加上换行符
"set textwidth=80 "有时不爽
set textwidth=0 "总不还行
" 设置每行多少个字符自动换行,加上换行符
" 光标可以定位在没有实际字符的地方
"set ve=block
" 光标可以定位在没有实际字符的地方
" 短暂跳转到匹配括号的时
" set matchtime=2
" 短暂跳转到匹配括号的时
"多少个键被敲下后执行一次交换文件刷新
set updatecount=400 "设置敲入400个字符后执行
"多少个键被敲下后执行一次交换文件刷新
"交换文件刷新后的超时时间
set updatetime=50000 "50秒后刷新
":preserve "若设置的时间过长,该命令会手工的存入交换文件中.
"交换文件刷新后的超时时间
" 隐藏工具栏
"set guioptions-=T
" 隐藏工具栏
" 隐藏菜单栏
"set guioptions-=m
" 隐藏菜单栏
" Shift+F12 删除所有行未尾空格
"nmap <S-F12> :%s,/s/+$,,g<CR>
" Shift+F12 删除所有行未尾空格
"}}}
"简单配置
"改变注释代码的颜色
"{{{
hi Comment ctermfg=6
"改.c文件的c风格/* ... */注释为会灰白色
hi cComment ctermfg=DarkMagenta "DarkGray 灰白色 " guifg=Grey
"改.c文件的c++风格// ... 注释为彩色终端下为暗蓝灰色、GUI下为浅蓝色
hi cCommentL ctermfg=LightBlue " guifg=LightBlue
"以上可参看/usr/share/vim/vim72/syntax/c.vim中对cComment和cCommentL的定义
"}}}
"改变注释代码的颜色
"字符编码(多字节)
"{{{
if has("multi_byte")
set encoding=utf-8
set fileencodings=ucs-bom,utf-8,chinese,big5,latin1,cp936
endif
"}}}
"字符编码(多字节)
"设置C/C++语言的具体缩进方式 eg. switch case 缩进
""{{{
set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
"set cino=:4g2t0(sus
"set cino=:0g0t0(sus
" :0 -- switch 语句之下的 case 语句缩进 0 个空格
" g0 -- class,struct,等权限控制语句(public,protected,private)相对class,struct等所在的块缩进 0 个空格
" t0 -- 如果函数返回值与函数名不在同一行,则返回值缩进 0 个空格
" (sus - 当一对括号跨越多行时,其后的行缩进前面 sw 指定的距离
""}}}
"设置C/C++语言的具体缩进方式 eg. switch case 缩进
"C的编译和运行 " 不好用,推荐用cvim.zip插件, /rr(运行), /ra(带参数运行), /ro(输出到(buff, xterm, vim))
"{{{
"func! CompileRunGcc()
" exec "w"
" exec "!gcc % -o %<"
" exec "! ./%<"
"endfunc
"}}}
"C的编译和运行 " 不好用,推荐用cvim.zip插件, /rr(运行), /ra(带参数运行), /ro(输出到(buff, xterm, vim))
"search 搜索 (visual mode)
""{{{
"set hls " hlsearch :highlight search
"set is " incsearch :increase search
"set ic " ignorecase :ignore case when searching
"set scs " smartcase :if has upper case, ignore 'ignorecase' option
""map <leader>h *N " <leader>h to highlight all word the same to which under cursor (可以使用vim自带shift + *)
""
""basically you press * or # to search for the current selection !! Really useful
vnoremap <silent> * :call VisualSearch('f')<CR>
vnoremap <silent> # :call VisualSearch('b')<CR>
function! VisualSearch(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '///.*$^~[]')
let l:pattern = substitute(l:pattern, "/n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
else
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
"map <space> :nohl<CR> " :press <space> to clear hightlight search highlight
""}}}
"search 搜索 (visual mode)
"状态栏显示当前文件, 字符编码, 时间等
"{{{
"显示状态栏
set ruler
set laststatus=2
highlight statusline cterm=bold ctermfg=black ctermbg=white
"显示状态栏
"
function! CurDir()
let curdir = substitute(getcwd(), $HOME, "~", "g")
return curdir
endfunction
function! CurTime()
let curtime = strftime("%m-%d %H:%M:%S")
return curtime
endfunction
"set statusline=[%n]/ %f%m%r%h/ /|/ / pwd:/ %{CurDir()}/ / /|%=/|/ %l,%c/ %p%%/ /|/ ascii=%b,hex=%b%{((&fenc==/"/")?/"/":/"/ /|/ /".&fenc)}/ /|/ %{$USER}/ @/ %{hostname()}/
"set statusline=[%n]/ %F%m%r%h/ /|/ / pwd:/ %{CurDir()}/ / /|%=/|/ %l,%c/ %p%%/ /|/ ascii=%b,hex=%B%{((&fenc==/"/")?/"/":/"/ /|/ /".&fenc)}/ /|
"使用%F就不需要使用自定义函数CurDir()
"set statusline=[%n]/ /|/ %F%m%r%h/ /|%=/|/ %l,%c/ %p%%/ /|/ ascii=%b,hex=%B%{((&fenc==/"/")?/"/":/"/ /|/ /".&fenc)}/ /|/ / %{CurTime()}/ /|
set statusline=[%n]/ /|/ %f%m%r%h/ /|%=/|/ %c/ /|/ ascii=%b,hex=%B%{((&fenc==/"/")?/"/":/"/ /|/ /".&fenc)}/ /|/ %{CurTime()}/ /|
"状态行显示内容
" %f 只显示名字不显示路径
" %F 当前文件名
" %m 当前文件修改状态
" %r 当前文件是否只读
" %Y 当前文件类型
" %{&fileformat} 当前文件编码
" %b 当前光标处字符的 ASCII 码值
" %B 当前光标处字符的十六进制值
" %l 当前光标行号
" %c 当前光标列号
" %V 当前光标虚拟列号 (根据字符所占字节数计算)
" %p 当前行占总行数的百分比
" %% 百分号
" %L 当前文件总行数
"}}}
"状态栏显示当前文件, 字符编码, 时间等
"当前行(列)高亮显示
"{{{
set cursorline
set cursorcolumn
" ctermfg : red(1) yellow(2) blue green grey brown cyan magenta 数字
"hi CursorLine term=reverse cterm=reverse ctermbg=darkred ctermfg=black guibg=blue guifg=white
"hi CursorLine term=none cterm=reverse ctermbg=Magenta ctermfg=DarkGray "guibg=blue guifg=white
"hi CursorLine term=none cterm=reverse ctermbg=Cyan ctermfg=DarkGray "guibg=blue guifg=white
hi CursorLine term=none cterm=underline ctermbg=8 ctermfg=none "guibg=blue guifg=white
hi CursorColumn term=none cterm=bold ctermbg=none ctermfg=Cyan "guibg=darkgrey guifg=white
"nnoremap <Leader>c : set cursorline! cursorcolumn! <CR>
"set cursorline
"au! Cursorhold * exe 'match CurrentLine //%' . line('.') . 'l.*/'
"set ut=100
"}}}
"当前行(列)高亮显示
"单行或多行注释 "也可以使用cvim.zip插件来完成注释(*.c文件) /cc ---> // /c* ---> /* */ /co ---> 取消
"{{{
" nmap <C-C> <Esc>:Setcomment<CR>
" "normal 模式下ctrl + C 快捷键
" imap <C-C> <Esc>:Setcomment<CR>
" "insert 模式下ctrl + C 快捷键
" vmap <C-C> <Esc>:SetcommentV<CR>
" "visual 模式下ctrl + C 快捷键
" command! -nargs=0 Setcomment call s:SET_COMMENT()
" command! -nargs=0 SetcommentV call s:SET_COMMENTV()
"
" "非视图模式下所调用的函数
" function! s:SET_COMMENT()
" let lindex=line(".")
" let str=getline(lindex)
" "查看当前是否为注释行
" let CommentMsg=s:IsComment(str)
" call s:SET_COMMENTV_LINE(lindex,CommentMsg[1],CommentMsg[0])
" endfunction
"
" "视图模式下所调用的函数
" function! s:SET_COMMENTV()
" let lbeginindex=line("'<") "得到视图中的第一行的行数
" let lendindex=line("'>") "得到视图中的最后一行的行数
" let str=getline(lbeginindex)
" "查看当前是否为注释行
" let CommentMsg=s:IsComment(str)
" "为各行设置
" let i=lbeginindex
" while i<=lendindex
" call s:SET_COMMENTV_LINE(i,CommentMsg[1],CommentMsg[0])
" let i=i+1
" endwhile
" endfunction
"
" "设置注释
" "index:在第几行
" "pos:在第几列
" "comment_flag: 0:添加注释符 1:删除注释符
" function! s:SET_COMMENTV_LINE( index,pos, comment_flag )
" let poscur = [0, 0,0, 0]
" let poscur[1]=a:index
" let poscur[2]=a:pos+1
" call setpos(".",poscur) "设置光标的位置
"
" if a:comment_flag==0
" "插入//
" exec "normal! i//"
" else
" "删除//
" exec "normal! xx"
" endif
" endfunction
"
" "查看当前是否为注释行并返回相关信息
" "str:一行代码
" function! s:IsComment(str)
" let ret= [0, 0] "第一项为是否为注释行(0,1),第二项为要处理的列,
" let i=0
" let strlen=len(a:str)
" while i<strlen
" "空格和tab允许为"//"的前缀
" if !(a:str[i]==' ' || a:str[i] == ' ' )
" let ret[1]=i
" if a:str[i]=='/' && a:str[i+1]=='/'
" let ret[0]=1
" else
" let ret[0]=0
" endif
" return ret
" endif
" let i=i+1
" endwhile
" return [0,0] "空串处理
" endfunction
"}}}
"单行或多行注释 "也可以使用cvim.zip插件来完成注释(*.c文件) /cc ---> // /c* ---> /* */ /co ---> 取消
"vim折叠功能
""{{{
"折叠方式,可用选项 ‘foldmethod’ 来设定折叠方式:set fdm=***
"有 6 种方法来选定折叠:
"manual 手工定义折叠
"indent 更多的缩进表示更高级别的折叠
"expr 用表达式来定义折叠
"syntax 用语法高亮来定义折叠
"diff 对没有更改的文本进行折叠
"marker 对文中的标志折叠
"常用的折叠快捷键
"zf 创建折叠 (marker 有效)
"zo 打开折叠
"zO 对所在范围内所有嵌套的折叠点展开
"zc 关闭当前折叠
"zC 对所在范围内所有嵌套的折叠点进行折叠
"[z 到当前打开的折叠的开始处。
"]z 到当前打开的折叠的末尾处。
"zM 关闭所有折叠 (我喜欢)
"zr 打开所有折叠
"zR 循环地打开所有折叠 (我喜欢)
"zE 删除所有折叠
"zd 删除当前折叠
"zD 循环删除 (Delete) 光标下的折叠,即嵌套删除折叠
"za 若当前打开则关闭,若当前关闭则打开 ( 这个就足够了)
"zA 循环地打开/关闭当前折叠
"zj 到下一折叠的开始处 ( 我喜欢 )
"zk 到上一折叠的末尾 ( 我喜欢 )
"set fdm=marker
"set foldmethod=indent
"要想在{ } 代码块中折叠,按空格键
"syntax 与 c.vim 中的 /cc 注释功能冲突
set fdm=marker
"nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR> "使用空格打开或关闭折叠
"}}}
"vim折叠功能
"文件比较
""{{{
":vertical diffsplit FILE_RIGHT "与已打开的文件进行比较
"设置不同之处显示上下三行
set diffopt=context:3
"命令模式(ESC键进入):
"dp 左边文件差异复制到右边文件(直接在键盘上行按下dp)
"do 右边文件差异复制到左边文件(直接在键盘上行按下do)
"zo 隐藏相同行
"zc 展开向同行
"u 撤销
"Ctrl+w 文件切换
"
":qa! 退出不保存
":wa 保存
":wqa 保存退出
":diffupdate 重新比较
""}}}
"文件比较
"单词列表匹配
"{{{
"ctrl+x ctrl+k
"apt-get install wordlist
set dictionary+=~/.vim/dict/wordlist.txt
set cpt=.,b,t,k
" . scan the current buffer ('wrapscan' is ignored)
" w scan buffers from other windows
" b scan other loaded buffers that are in the buffer list
" u scan the unloaded buffers that are in the buffer list
" U scan the buffers that are not in the buffer list
" k scan the files given with the 'dictionary' option
" kspell use the currently active spell checking |spell|
" k{dict} scan the file {dict}. Several "k" flags can be given,
" patterns are valid too. For example: >
" :set cpt=k/usr/dict/*,k~/spanish
" s scan the files given with the 'thesaurus' option
" s{tsr} scan the file {tsr}. Several "s" flags can be given, patterns
" are valid too.
" i scan current and included files
" d scan current and included files for defined name or macro
" |i_CTRL-X_CTRL-D|
" ] tag completion
" t same as "]"
"}}}
"单词列表匹配
"括号智能匹配 autoclose.vim
"{{{
"let g:AutoClosePairs={'(': ')', '{': '}', '[': ']', '"': '"', "'": "'"}
let g:AutoClosePairs={'{': '}'} "间接不使用,不习惯
"}}}
"括号智能匹配 autoclose.vim
"简单tab智能完成 使用实际的tab 需要shift+tab 可以使用插件SuperTab
"{{{
"ctrl + c 可以中断正在查找
"function! Smart_TabComplete()
" let line = getline('.') " curline
" let substr = strpart(line, -1, col('.')+1) " from start to cursor
" let substr = matchstr(substr, "[^ /t]*$") " word till cursor
" if (strlen(substr)==0) " nothing to match on empty string
" return "/<tab>"
" endif
" let has_period = match(substr, '/.') != -1 " position of period, if any
" let has_slash = match(substr, '//') != -1 " position of slash, if any
" if (!has_period && !has_slash)
" return "/<C-X>/<C-P>" " existing text matching
" elseif ( has_slash )
" return "/<C-X>/<C-F>" " file matching
" else
" return "/<C-X>/<C-O>" " plugin matching
" endif
"endfunction
"inoremap <tab> <c-r>=Smart_TabComplete()<CR>
"}}}
"简单tab智能完成 使用实际的tab 需要shift+tab 可以使用插件SuperTab
"gf 命令 go file 到该文件去
"{{{
"set path+=/home/linux/u-boot-1.3.1/include/
"set path+=/usr/src/linux-headers-2.6.27-7/include/
"set path+=/usr/src/linux/include/
"}}}
"gf 命令 go file 到该文件去
"completeopt 弹出菜单 输入字母实现即时的过滤和匹配 ( 参考 neocomplcache )
""{{{
""关掉智能补全时的预览窗口 (Scratch)
"" menu 使用弹出菜单来显示可能的补全
"" longest 只插入匹配的最长公共文本
""set completeopt=menuone,menu,longest,preview
"filetype plugin indent on
set ofu=syntaxcomplete#Complete
set completeopt=menu,longest
""}}}
"completeopt 弹出菜单 输入字母实现即时的过滤和匹配 ( 参考 neocomplcache )
"----------------------
"利用 插件 丰富 功能
"----------------------
"{{{
"WinManager 插件 ( 不好用 )
""{{{
"let g:defaultExplorer=1
"let g:winManagerWindowLayout='FileExplorer|BufExplorer|TagList'
"let g:persistentBehaviour=0 "只剩一个窗口时, 退出vim.
"let g:winManagerWidth=80 "设置winmanager的宽度,默认为25
"nmap <silent> <leader>fir :FirstExplorerWindow<cr>
"nmap <silent> <leader>bot :BottomExplorerWindow<cr>
"nmap <silent> <leader>wm :WMToggle<cr
"nmap <silent> <F8> :WMToggle<cr> "定义打开关闭winmanager按键
""}}}
"WinManager 插件 ( 不好用 )
"NERD_commenter.vim : 1218 "可以使用cvim.zip, 但是这个觉到习惯一些
""{{{
let NERDSpaceDelims=1 " 让注释符与语句之间留一个空格
let NERDCompactSexyComs=1 " 多行注释时样子更好看
let NERD_c_alt_style=1
"Default mapping:
"[count],cc " 以行为单位进行注释.
" ,c<space> " comment , <--> , uncomment. ( 常用 )
" ,cm " 一段为单位进行注释. ( 常用 )
" ,cs " 简洁美观式注释. ( 常用 , 可以嵌套注释,用,cu取消注释 )
" ,cy " Same as ,cc except that the commented line(s) are yanked first.
" ,c$ " 注释当前光标到行末的内容.
" ,cA " 在行末进行手动输入注释内容.
" ,ca " 切换注释方式(/**/ <--> //). ( 常用 )
" ,cl " Same cc, 左对齐.
" ,cb " Same cc, 两端对其.
" ,cu " Uncomments the selected line(s). ( 常用 )
"}}}
"NERD_commenter.vim : 1218 "可以使用cvim.zip, 但是这个觉到习惯一些
"F8单独切换打开NERD_tree ( F8 )
"{{{
"-----------------------------------------------------------------
" plugin - NERD_tree.vim 以树状方式浏览系统中的文件和目录
" :ERDtree 打开NERD_tree :NERDtreeClose 关闭NERD_tree
" o 打开关闭文件或者目录 t 在标签页中打开
" T 在后台标签页中打开 ! 执行此文件
" p 到上层目录 P 到根目录
" K 到第一个节点 J 到最后一个节点
" u 打开上层目录 m 显示文件系统菜单(添加、删除、移动操作)
" r 递归刷新当前目录 R 递归刷新当前根目录
"-----------------------------------------------------------------
let g:NERDChristmasTree = 1 "色彩显示
let g:NERDTreNERDShowHidden = 1 "显示隐藏文件
let g:NERDTreeWinPos = 'left' "窗口显示位置
let g:NERDTreeHighlightCursorline = 0 "高亮当前行
let g:NERDTreeWinSize = 40 "设置显示宽度
"nmap <F2> :NERDTreeToggle<CR>.
"
" o.......打开所选文件或目录 ( 常用 )
" enter..............相当于o
" go......类似o, 但光标仍然停留在NERD_tree ( 常用 )
" t.......在新标签中打开所选文件
" T.......类似t, 但光标仍然停留在NERD_tree
" i.......在一个水平分割窗口中打开文件
" gi......类似i, 但光标仍然停留在NERD_tree
" s.......在一个垂直分割窗口中打开文件.......................|NERDTree-s|
" gs......类似s, 但光标仍然停留在NERD_tree
" O.......递归打开所选目录
" 鼠标双击.......相当于o, 没错支持鼠标的~!
""}}}
"F8单独切换打开NERD_tree ( F8 )
"bufexplorer插件 ( F2 )
"{{{
"map <F2> :BufExplorer<CR>
",be 打开选择窗口 ','是前面mapleader设置的 ( F2 )
"r可以进行反向排序.
"d/D可以用来关闭文件.
"p可以用来显示/关闭绝对路径模式
"}}}
"bufexplorer插件 ( F2 )
"echofunc.vim 在命令行中显示函数信息 ( 不错 )
""{{{
"直接下载解压即可( tags 插件已包含相似功能, 没必要装此插件 )
"这个插件的功能需要 tags 文件的支持, 并且在创建 tags 文件的时候要加选项"--fields=+lS" : ctags -R --fields=+lS
let g:EchoFuncKeyPrev='<C-p>'
let g:EchoFuncKeyNext='<C-n>'
let g:EchoFuncLangsUsed = ["c","java","cpp"]
""}}}
"echofunc.vim 在命令行中显示函数信息 ( 不错 )
"code_complete.vim 函数参数提示 ctags -R --c-kinds=+p --fields=+S
""{{{
" 若已经有echofunc.vim 和 cvim.zip插件那此插件不需要.
" (1) 下载后放到plugin目录中
" (2) ctags -R --c-kinds=+p --fields=+S
" (3) 提示: 默认触发键tab 导致supertab插件可能不正常,从而影响neocomplcache自动补全(如果设置的话).
"let g:completekey = "<tab>" "默认hotkey
"( 插件越多 冲突越多 功能重复 一切从简 )
""}}}
"code_complete.vim 函数参数提示 ctags -R --c-kinds=+p --fields=+S
"DoxygenToolkit.vim 代码说明文档自动生成
""{{{
" (1) :DoxLic 生成license (不常使用)
" (2) :DoxAuthor 生成文件描述 (C程序等常使用,@file有用)
" (3) :Dox 生成函数注释 (很有用)
map <leader>da :DoxAuthor<CR>
map <leader>df :Dox<CR>
map <leader>db :DoxBlock<CR>
" 对class struct enum union等结构类的成员变量的注释为 /**< 解释变量 */
" @class 文档化一个C++类
" @struct 文档化一个 C 结构
" @union 文档化一个联合
" @enum 文档化一个枚举
" @fn 文档化一个函数
" @var 文档化一个变量,类型转换,枚举值其中之一
" @def 文档化一个#define
" @typedef 文档化一个类型转换
"
" Shell 命令
" (x) doxygen 生成文档(这个命令需要安装 apt-get install doxgen )
" (1) doxygen -g "默认生成doxygen的配置文件Doxyfile, 你也可以指定 doxygen -g myfile
" (2) 编辑生成的配置文件 (配置文件采用 <TAGNAME> = <VALUE> 这样的结构)
" * OUTPUT_DIRECTORY : 为生成的文档指定存放位置
" * INPUT : 指定源文件目录位置, 如有多个以空格分开
" * FILE_PATTERNS : 指定源文件扩展名 (eg .c,.cc,.cpp,.h )
" * RECURSIVE : 源代码层次结构嵌套设置, ( yes or no )
" * EXTRACT_ALL : 函数没有注释文档也要提取信息(即yes)
" * EXTRACT_PRIVATE : 设置为yes才会将私有信息提取
" * EXTRACT_STATIC : 设置为yes才会提取静态成员
" * 其他需要自己看
" (3) doxygen Doxyfile "运行
" Shell 命令
let g:DoxygenToolkit_authorName = "Michael"
let g:DoxygenToolkit_briefTag_funcName = "yes"
let g:doxygen_enhanced_color = 1
"let g:DoxygenToolkit_blockHeader = "--------------------------------------------------------------------------"
"let g:DoxygenToolkit_authorName = "Michael"
"let g:DoxygenToolkit_authorTag = "@Author "
"let g:DoxygenToolkit_dateTag = "@Date "
"let g:DoxygenToolkit_versionTag = "@Version "
"let g:DoxygenToolkit_fileTag = "@File "
"let g:DoxygenToolkit_briefTag_pre = "@Description "
"let g:DoxygenToolkit_paramTag_pre = "@Param "
"let g:DoxygenToolkit_paramTag_post = ":"
"let g:DoxygenToolkit_returnTag = "@Return "
"let g:DoxygenToolkit_throwTag_pre = "@Exception "
"let g:DoxygenToolkit_briefTag_funcName = "yes"
"let g:doxygen_enhanced_color = 1
"let g:DoxygenToolkit_blockFooter = "--------------------------------------------------------------------------"
""}}}
"DoxygenToolkit.vim 代码说明文档自动生成
"<F9> :ConqueTerm bash
""{{{
" vim 中使用终端 : 可用于终端调试
""}}}
"<F9> :ConqueTerm bash
"fencview.vim 对你打开的文件的编码自动识别
""{{{
"直接下载解压即可
let g:fencview_autodetect = 1
""}}}
"fencview.vim 对你打开的文件的编码自动识别
"F3 Grep.vim 查找字符插件
""{{{
" 将光标位置放到所要搜索的字符串上, 按F3, 默认搜索所有(*)类型文件
" nnoremap <silent> <F3> :Grep<CR>
" 直接放到plugin中.
""}}}
"F3 Grep.vim 查找字符插件
"<F5> lookupfile插件默认会使用ctags产生的tag来查找,效率很低,使用下面脚本生成filenametags
""{{{
"当使用了acp.vim ( autocomplpop.vim)时, 该插件好像有点问题. 不过还是可以使用
"echo "!_TAG_FILE_SORTED 2 /2=foldcase/"; find . -not -iregex '.*/./(jar/|gif/|jpg/|class/|exe/|dll/|pdd/|sw[op]/|xls/|doc/|pdf/|zip/|tar/|ico/|ear/|war/|dat/).*' -type f -printf "%f/t%p/t1/n" | sort -f > ./filenametags
let g:LookupFile_MinPatLength = 2 "最少输入3个字符才开始查找
let g:LookupFile_PreserveLastPattern = 0 "不保存上次查找的字符串
let g:LookupFile_PreservePatternHistory = 1 "保存查找历史
let g:LookupFile_AlwaysAcceptFirst = 1 "回车打开第一个匹配项目
let g:LookupFile_AllowNewFiles = 0 "不允许创建不存在的文件
let g:LookupFile_SortMethod = "" "关闭对搜索结果的字母排序
let g:LookupFile_UpdateTime = 200
let g:LookupFile_AlwaysAcceptFirst = 1
let g:LookupFile_DefaultCmd = ':LUTags'
" Don't display binary files
let g:LookupFile_FileFilter = '/.class$/|/.o$/|/.obj$/|/.exe$/|/.jar$/|/.zip$/|/.war$/|/.ear$'
let g:LookupFile_TagExpr = string('/home/tags/filenametags')
"if filereadable("/home/tags/filenametags") "设置tag文件的名字
" let g:LookupFile_TagExpr ='"/home/tags/filenametags"'
"endif
"映射LookupFile为,lk
nmap <silent> <leader>lk :LUTags<cr>
"映射LUBufs为,ll
nmap <silent> <leader>ll :LUBufs<cr>
"映射LUWalk为,lw
nmap <silent> <leader>lw :LUWalk<cr>
" lookup file with ignore case
function! LookupFile_IgnoreCaseFunc(pattern)
let _tags = &tags
try
let &tags = eval(g:LookupFile_TagExpr)
let newpattern = '/c' . a:pattern
let tags = taglist(newpattern)
catch
echohl ErrorMsg | echo "Exception: " . v:exception | echohl NONE
return ""
finally
let &tags = _tags
endtry
" Show the matches for what is typed so far.
let files = map(tags, 'v:val["filename"]')
return files
endfunction
let g:LookupFile_LookupFunc = 'LookupFile_IgnoreCaseFunc'
""}}}
"<F5> lookupfile插件默认会使用ctags产生的tag来查找,效率很低,使用下面脚本生成filenametags
"neocomplcache.vba 插件替代autocomplpop(acp.vim) omnicppcomplete.vim , 在使用acp.vim,OmniCppComplete.vim 你就被out.
""{{{
"-----------------------------------------------------------------
" plugin - NeoComplCache.vim 自动补全插件
" 1、使用缓存,自动补全时效率高;
" 2、生成的关键词列表准确;
" 3、支持下划线分割的关键词,如apple_boy_cat,就可以只输入a_b_c,然后补全;
" 4、支持驼峰格式匹配关键词,如AppleBoyCat,就可以只输入ABC,然后补全;
" 5、既可以像AutoComplPop那样在Vim中输入的同时自动弹出补全列表,又可以自定义快捷键手动触发;
" 6、支持从文件名和目录名中匹配补全条件;
" 7、对于程序源文件,支持从语言API中匹配补全条件;
"-----------------------------------------------------------------
" Disable AutoComplPop.
"set completeopt=menu,longest
let g:acp_enableAtStartup = 0
" Use neocomplcache.
let g:neocomplcache_enable_at_startup = 1
" Use smartcase.
let g:neocomplcache_enable_smart_case = 1
" Use camel case completion.
let g:neocomplcache_enable_camel_case_completion = 1 "支持驼峰格式匹配关键词
" Use underbar completion.
let g:neocomplcache_enable_underbar_completion = 1 "支持下划线分割的关键词
" Set minimum syntax keyword length.
let g:neocomplcache_min_syntax_length = 3
let g:neocomplcache_lock_buffer_name_pattern = '/*ku/*'
let g:neocomplcache_enable_auto_delimiter = 1
let g:neocomplcache_disable_auto_complete = 1 "设置NeoComplCache不自动弹出补全列表
"let g:neocomplcache_enable_wildcard = 1
" Define dictionary.
let g:neocomplcache_dictionary_filetype_lists = {
/ 'default' : '',
/ 'vimshell' : $HOME.'/.vimshell_hist',
/ 'scheme' : $HOME.'/.gosh_completions',
/ }
" Define keyword.
if !exists('g:neocomplcache_keyword_patterns')
let g:neocomplcache_keyword_patterns = {}
endif
let g:neocomplcache_keyword_patterns['default'] = '/h/w*'
let g:neocomplcache_enable_auto_select = 1
"let g:neocomplcache_enable_caching_message=1 "显示启动进度
" Enable omni completion.
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
autocmd filetype cpp set omnifunc=omni#cpp#complete#main
"Enable heavy omni completion.
if !exists('g:neocomplcache_omni_patterns')
let g:neocomplcache_omni_patterns = {}
endif
let g:neocomplcache_omni_patterns.ruby = '[^. */t]/./w*/|/h/w*::'
autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete
let g:neocomplcache_omni_patterns.php = '[^. /t]->/h/w*/|/h/w*::'
let g:neocomplcache_omni_patterns.c = '/%(/./|->/)/h/w*'
let g:neocomplcache_omni_patterns.cpp = '/h/w*/%(/./|->/)/h/w*/|/h/w*::'
"
"映射:
"inoremap <expr><C-x><C-f> neocomplcache#manual_filename_complete()
"inoremap <expr><C-j> neocomplcache#manual_filename_complete()
"inoremap <expr><C-n> pumvisible() ? "/<C-n>" : neocomplcache#manual_keyword_complete()
"inoremap <expr><C-y> neocomplcache#close_popup()
"inoremap <expr><C-e> neocomplcache#cancel_popup()
"inoremap <expr><C-g> neocomplcache#undo_completion()
"inoremap <expr><C-l> neocomplcache#complete_common_string()
"
""}}}
"neocomplcache.vba 插件替代autocomplpop(acp.vim) omnicppcomplete.vim , 在使用acp.vim,OmniCppComplete.vim 你就被out.
"omnicppcomplete : c/c++ omni-completion with ctags database
""{{{
"
"推荐使用<c-x>... "尽可能缩小范围,比如 1.补全函数<c-x><c-]> 2.补全单词<c-x><c-k> 3.补全路径<c-x><c-f> 等
" |<c-n>| - Keywords in 'complete' searching down.
" |<c-p>| - Keywords in 'complete' searching up (SuperTab default).
" |<c-x><c-l>| - Whole lines.
" |<c-x><c-n>| - Keywords in current file.
" |<c-x><c-k>| - Keywords in 'dictionary'.
" |<c-x><c-t>| - Keywords in 'thesaurus', thesaurus-style.
" |<c-x><c-i>| - Keywords in the current and included files.
" |<c-x><c-]>| - Tags. ---> 有用
" |<c-x><c-f>| - File names.
" |<c-x><c-d>| - Definitions or macros.
" |<c-x><c-v>| - Vim command-line.
" |<c-x><c-u>| - User defined completion.
" |<c-x><c-o>| - Omni completion.
" |<c-x>s| - Spelling suggestions.
" Ctrl+P 向前切换成员
" Ctrl+N 向后切换成员
" Ctrl+E 表示退出下拉窗口, 并退回到原来录入的文字
" Ctrl+Y 表示退出下拉窗口, 并接受当前选项
" Ctrl+X Ctrl+L 整行补全
" Ctrl+X Ctrl+N 根据当前文件里关键字补全
" Ctrl+X Ctrl+K 根据字典补全
" Ctrl+X Ctrl+T 根据同义词字典补全
" Ctrl+X Ctrl+I 根据头文件内关键字补全
" Ctrl+X Ctrl+] 根据标签补全
" Ctrl+X Ctrl+F 补全文件名
" Ctrl+X Ctrl+D 补全宏定义
" Ctrl+X Ctrl+V 补全vim命令
" Ctrl+X Ctrl+U 用户自定义补全方式
" Ctrl+X Ctrl+S 拼写建议
"
"set nocp "要关闭兼容 (上面已处理)
let omnicpp_namespacesearch = 1
let omnicpp_globalscopesearch = 1
let omnicpp_showaccess = 1
let omnicpp_showprototypeinabbr = 1 " show function parameters
let omnicpp_maycompletedot = 1 " autocomplete after .
let omnicpp_maycompletearrow = 1 " autocomplete after ->
let omnicpp_maycompletescope = 1 " autocomplete after ::
let omnicpp_defaultnamespaces = ["std", "_glibcxx_std"]
""automatically open and close the popup menu / preview window
"au cursormovedi,insertleave * if pumvisible() == 0|silent! pclose|endif
""set completeopt=menuone,menu,longest,preview
""自定义快捷键 ( 若使用neocomplcache插件: 已定义了下面很多映射 )
"inoremap <expr> <cr> pumvisible()?"/<c-y>":"/<cr>"
"inoremap <expr> <c-j> pumvisible()?"/<pagedown>/<c-n>/<c-p>":"/<c-x><c-o>" "注意cvim.zip另有映射,而且很强大
inoremap <expr> <c-k> pumvisible()?"/<pageup>/<c-p>/<c-n>":"/<c-k>"
inoremap <expr> <c-u> pumvisible()?"/<c-e>":"/<c-u>"
"inoremap <expr> <c-p> pumvisible()?"/<up>":"/<c-p>"
"inoremap <expr> <c-n> pumvisible()?"/<down>":"/<c-n>"
""上面的映射都是在插入模式下的映射,解释如下
""如果下拉菜单弹出,回车映射为接受当前所选项目,否则,仍映射为回车
""如果下拉菜单弹出,ctrl-j映射为在下拉菜单中向下翻页。否则映射为ctrl-x ctrl-o
""如果下拉菜单弹出,ctrl-k映射为在下拉菜单中向上翻页,否则仍映射为ctrl-k
""如果下拉菜单弹出,ctrl-u映射为ctrl-e,即停止补全,否则,仍映射为ctrl-u
""如果下拉菜单弹出,ctrl-p映射为在下拉菜单中表示上一项。
""如果下拉菜单弹出,ctrl-n映射为在下拉菜单中表示下一项。
"":set omnifunc ? 查看设置的补全插件
""}}}
"omnicppcomplete : c/c++ omni-completion with ctags database
"加速你的补全 -- 插件: SuperTab 使用上面的,可以关闭这个
"{{{
"设置按下<Tab>后默认的补全方式, 默认是<C-P>,
"还有其他的补全方式, 你可以看看下面的一些帮助:
":help ins-completion
":help compl-omni
" 0 - 不记录上次的补全方式
" 1 - 记住上次的补全方式,直到用其他的补全命令改变它
" 2 - 记住上次的补全方式,直到按 ESC 退出插入模式为止
"let g:SuperTabDefaultCompletionType="context"
"let g:SuperTabDefaultCompletionType="<C-X><C-O>"
let g:SuperTabDefaultCompletionType = "<c-x><c-u>"
let g:SuperTabRetainCompletionType=2
"}}}
"加速你的补全 -- 插件: SuperTab 使用上面的,可以关闭这个
"教你高效地浏览源码 -- 插件: TagList
""{{{
set tags+=/home/tags/tags
"在taglist窗口中,可以使用下面的快捷键:
"<CR> 跳到光标下tag所定义的位置,用鼠标双击此tag功能也一样
"o 在一个新打开的窗口中显示光标下tag
"<Space> 显示光标下tag的原型定义
"u 更新taglist窗口中的tag
"s 更改排序方式,在按名字排序和按出现顺序排序间切换
"x taglist窗口放大和缩小,方便查看较长的tag
"+ 打开一个折叠,同zo
"- 将tag折叠起来,同zc
"* 打开所有的折叠,同zR
"= 将所有tag折叠起来,同zM
"[[ 跳到前一个文件
"]] 跳到后一个文件
"q 关闭taglist窗口
"<F1> 显示帮助
"使用 :Tlist
":help taglist.txt ( ~/.vim/doc/taglist.txt )
"
"快捷键
"map <F4> :TlistToggle<CR>
"noremap <F7> :Tlist<CR>
"noremap <S-F7> :TlistSync<CR>
"快捷键
"
highlight Pmenu ctermbg=Green "guibg=LightGray
highlight PmenuSel ctermbg=Red "guibg=DarkGray guifg=White
highlight PmenuSbar ctermbg=Blue "guibg=DarkBlue
highlight PmenuThumb ctermbg=Yellow "guibg=Black
"设定Linux系统中ctags程序的位置
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
"设定Linux系统中ctags程序的位置
"
"不同时显示多个文件的tag,只显示当前文件的
"let Tlist_Show_One_File=1
"不同时显示多个文件的tag,只显示当前文件的
"
"如果taglist窗口是最后一个窗口,则退出vim
let Tlist_Exit_OnlyWindow=1
"如果taglist窗口是最后一个窗口,则退出vim
"
"在右侧窗口中显示taglist窗口
let Tlist_Use_Right_Window = 1
"在右侧窗口中显示taglist窗口
"
"在左侧窗口中显示taglist窗口
"let Tlist_Use_Left_Window = 1
"在左右侧窗口中显示taglist窗口
"
" 缺省情况下,在双击一个tag时,才会跳到该tag定义的位置
let Tlist_Use_SingleClick= 1
" 缺省情况下,在双击一个tag时,才会跳到该tag定义的位置
"
"Taglist窗口宽度
let Tlist_WinWidth = 45
"Taglist窗口宽度
"
"在启动VIM后,自动打开taglist窗口
"let Tlist_Auto_Open=1
"在启动VIM后,自动打开taglist窗口
"
"taglist始终解析文件中的tag,不管taglist窗口有没有打开
"let Tlist_Process_File_Always=1
"taglist始终解析文件中的tag,不管taglist窗口有没有打开
"
"set 1 同时显示多个文件中的tag时,可使taglist只显示当前文件tag,其它文件的tag都被折叠起来
let Tlist_File_Fold_Auto_Close=1
"set 1 同时显示多个文件中的tag时,可使taglist只显示当前文件tag,其它文件的tag都被折叠起来
""}}}
"教你高效地浏览源码 -- 插件: TagList
"当查看源码是使用 -- 插件 : Cscope_map.vim
""{{{
"是否使用 quickfix 窗口来显示 cscope 结果
set cscopequickfix=s-,c-,d-,i-,t-,e-
"echo "export CSCOPE_DB=/home/tags/cscope.out" >> ~/.bashrc
"------- 下面是对cscope_map.vim文件的部分翻译
""0 或 s 查找本 C 符号(可以跳过注释)
""1 或 g 查找本定义
""2 或 d 查找本函数调用的函数 --可以到函数的定义处
""3 或 c 查找调用本函数的函数 --该函数被谁调用
""4 或 t 查找本字符串
""6 或 e 查找本 egrep 模式
""7 或 f 查找本文件
""8 或 i 查找包含本文件的文件
""ctrl + o 可以返回
"nmap <C-/>s :cs find s <C-R>=expand("<cword>")<CR><CR>
"nmap <C-/>g :cs find g <C-R>=expand("<cword>")<CR><CR>
"nmap <C-/>c :cs find c <C-R>=expand("<cword>")<CR><CR>
"nmap <C-/>t :cs find t <C-R>=expand("<cword>")<CR><CR>
"nmap <C-/>e :cs find e <C-R>=expand("<cword>")<CR><CR>
"nmap <C-/>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
"nmap <C-/>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
"nmap <C-/>d :cs find d <C-R>=expand("<cword>")<CR><CR>
"
""window split horizontally
"nmap <C-@>s :scs find s <C-R>=expand("<cword>")<CR><CR>
"nmap <C-@>g :scs find g <C-R>=expand("<cword>")<CR><CR>
"nmap <C-@>c :scs find c <C-R>=expand("<cword>")<CR><CR>
"nmap <C-@>t :scs find t <C-R>=expand("<cword>")<CR><CR>
"nmap <C-@>e :scs find e <C-R>=expand("<cword>")<CR><CR>
"nmap <C-@>f :scs find f <C-R>=expand("<cfile>")<CR><CR>
"nmap <C-@>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
"nmap <C-@>d :scs find d <C-R>=expand("<cword>")<CR><CR>
"
""window split vertically
"nmap <C-@><C-@>s :vert scs find s <C-R>=expand("<cword>")<CR><CR>
"nmap <C-@><C-@>g :vert scs find g <C-R>=expand("<cword>")<CR><CR>
"nmap <C-@><C-@>c :vert scs find c <C-R>=expand("<cword>")<CR><CR>
"nmap <C-@><C-@>t :vert scs find t <C-R>=expand("<cword>")<CR><CR>
"nmap <C-@><C-@>e :vert scs find e <C-R>=expand("<cword>")<CR><CR>
"nmap <C-@><C-@>f :vert scs find f <C-R>=expand("<cfile>")<CR><CR>
"nmap <C-@><C-@>i :vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
"nmap <C-@><C-@>d :vert scs find d <C-R>=expand("<cword>")<CR><CR>
"
""使用方法
""生成一个 cscope 的数据库
""1.cd /usr/src/linux/
""2.cscope -Rbq
""cs add /usr/src/linux/cscope.out /usr/src/linux/
""reset : 重新初始化所有连接. 用法 : cs reset
""
""1.下載cscope包 http://cscope.sourceforge.net/
""2.安裝cscope A../configure B.make C.make install
""3.修改set csprg 位置 :/usr/local/bin/cscope
""4.F3
""5.测试(1)cscope find g 函数名 (2) cscope find c 函数名
""6. :cw 显示多个结果
""
""下面是shell脚本,放到源码目录下运行
""#!/bin/sh
""find . -name "*.h" -o -name "*.c" -o -name "*.cc" > cscope.files
""cscope -bkq -i cscope.files
""ctags -R
""上面是shell脚本,放到源码目录下运行
""
""下面是对cscope -Rbkq 的解释
""-R: 在生成索引文件时,搜索子目录树中的代码
""-b: 只生成索引文件,不进入cscope的界面
""-k: 在生成索引文件时,不搜索/usr/include目录
""-q: 生成cscope.in.out和cscope.po.out文件,加快cscope的索引速度
""下面是对cscope -Rbkq 的解释
""
""-------------当前使用 快键----------
""noremap <F3> :!./vitags.sh<CR>:cs reset<CR>
""noremap <F3> :! cscope -Rbq<CR>:cs reset<CR>
""
""cscope和ctags的兼容问题
"if has("cscope")
" set csprg=/usr/bin/cscope
" set csto=0
" set cst "具有Ctags快捷键功能eg. ctrl+] , ctrl + t
" set nocsverb
" " add any database in current directory
" if filereadable("cscope.out")
" cs add cscope.out
" " else add database pointed to by environment
" elseif $CSCOPE_DB !=" "
" cs add $CSCOPE_DB "这是一个很好的方法
" endif
" set csverb
" set cscopetag
"endif
""cscope和ctags的兼容问题
":help if_cscop.txt
":cs show
"}}}
"当查看源码是使用 -- 插件 : Cscope_map.vim
"利用cvim.zip插件实现,下载后解压到~/.vim中
""{{{
"下载地址: http://www.vim.org/scripts/script.php?script_id=213
"
"let g:C_MapLeader = ',' "默认的是'/'
"Ctrl+j 的使用:eg. 当你使用/if添加一个函数时,会多出一些类似<+xxx+>的东西(需要重新填写), ctrl+j可以帮你忙,试一下很强.
"
"1.添加文件头注释(自动完成)
"2.添加c函数(标准模式执行/if, 再输入函数名)
"3.添加main函数(标准模式执行/im)
"4.添加函数注释 (标准模式执行/cfu)
"5.添加注释框架 (标准模式执行/cfr)
"6.添加头文件 (标准模式执行/p<包含头文件 或 /p"包含头文件)
"7.添加宏定义 (标准模式执行/pd)
"8.添加代码片段
"(标准模式执行/nr,需在~/.vim/c-support/codesnippets/中加入存放代码的文件)
" -- Help ---------------------------------------------------------------
"
" /hm show manual for word under the cursor (n,i)
" /hp show plugin help (n,i)
"
" -- Comments -----------------------------------------------------------
"
" /cl end-of-line comment (n,v,i)
" /cj adjust end-of-line comment(s) (n,v,i) ---> V模式下可以对注释调整对齐
" /cs set end-of-line comment column (n) ---> 设置行尾注释,起始位置(列)
" /c* code -> comment /* */ (n,v)
" /cc code -> comment // (n,v)
" /co comment -> code (n,v) ---> V模式下取消注释
" /cfr frame comment (n,i)
" /cfu function comment (n,i)
" /cme method description (n,i)
" /ccl class description (n,i)
" /cfdi file description (implementation) (n,i)
" /cfdh file description (header) (n,i)
" /ccs C/C++-file section (tab. compl.) (n,i)
" /chs H-file section (tab. compl.) (n,i)
" /ckc keyword comment (tab. compl.) (n,i)
" /csc special comment (tab. compl.) (n,i)
" /cd date (n,v,i)
" /ct date /& time (n,v,i)
"
" -- Statements ---------------------------------------------------------
"
" /sd do { } while (n,v,i)
" /sf for (n,i)
" /sfo for { } (n,v,i)
" /si if (n,i)
" /sif if { } (n,v,i)
" /sie if else (n,v,i)
" /sife if { } else { } (n,v,i)
" /se else { } (n,v,i)
" /sw while (n,i)
" /swh while { } (n,v,i)
" /ss switch (n,v,i)
" /sc case (n,i)
" /s{ /sb { } (n,v,i)
"
" -- Preprocessor -------------------------------------------------------
"
" /ps choose a standard library include (n,i)
" /pc choose a C99 include (n,i)
" /p< #include <> (n,i)
" /p" #include "" (n,i)
" /pd #define (n,i)
" /pu #undef (n,i)
" /pie #if #else #endif (n,v,i)
" /pid #ifdef #else #endif (n,v,i)
" /pin #ifndef #else #endif (n,v,i)
" /pind #ifndef #def #endif (n,v,i)
" /pi0 #if 0 #endif (n,v,i)
" /pr0 remove #if 0 #endif (n,i)
" /pe #error (n,i)
" /pl #line (n,i)
" /pp #pragma (n,i)
"
" -- Idioms -------------------------------------------------------------
"
" /if function (n,v,i)
" /isf static function (n,v,i)
" /im main() (n,v,i)
" /i0 for( x=0; x<n; x+=1 ) (n,v,i)
" /in for( x=n-1; x>=0; x-=1 ) (n,v,i)
" /ie enum + typedef (n,i)
" /is struct + typedef (n,i)
" /iu union + typedef (n,i)
" /ip printf() (n,i)
" /isc scanf() (n,i)
" /ica p=calloc() (n,i)
" /ima p=malloc() (n,i)
" /isi sizeof() (n,v,i)
" /ias assert() (n,v)
" /ii open input file (n,i)
" /io open output file (n,i)
"
" -- Snippets -----------------------------------------------------------
"
" /nr read code snippet (n,i)
" /nw write code snippet (n,v,i)
" /ne edit code snippet (n,i)
" /np pick up prototype (n,v,i)
" /ni insert prototype(s) (n,i)
" /nc clear prototype(s) (n,i)
" /ns show prototype(s) (n,i)
" /ntl edit local templates (n,i)
" /ntg edit global templates (n,i)
" /ntr rebuild templates (n,i)
"
" -- C++ ----------------------------------------------------------------
"
" /+co cout << << endl; (n,i)
" /+" << "" (n,i)
" /+c class (n,i)
" /+ps #include <...> STL (n,i)
" /+pc #include <c..> C (n,i)
" /+cn class (using new) (n,i)
" /+ci class implementation (n,i)
" /+cni class (using new) implementation (n,i)
" /+mi method implementation (n,i)
" /+ai accessor implementation (n,i)
"
" /+tc template class (n,i)
" /+tcn template class (using new) (n,i)
" /+tci template class implementation (n,i)
" /+tcni template class (using new) impl. (n,i)
" /+tmi template method implementation (n,i)
" /+tai template accessor implementation (n,i)
"
" /+tf template function (n,i)
" /+ec error class (n,i)
" /+tr try ... catch (n,v,i)
" /+ca catch (n,v,i)
" /+c. catch(...) (n,v,i)
"
" -- Run ----------------------------------------------------------------
"
" /rc save and compile (n,i)
" /rl link (n,i)
" /rr run (n,i)
" /ra set comand line arguments (n,i)
" /rm run make (n,i)
" /rmc run 'make clean' (n,i)
" /rme executable to run (n,i)
" /rma cmd. line arg. for make (n,i)
" /rp run splint (n,i)
" /rpa cmd. line arg. for splint (n,i)
" /rk run CodeCheck (TM) (n,i)
" /rka cmd. line arg. for CodeCheck (TM) (n,i)
" /rd run indent (n,v,i)
" /rh hardcopy buffer (n,v,i)
" /rs show plugin settings (n,i)
" /rx set xterm size (n, only Linux/UNIX & GUI)
" /ro change output destination (n,i)
"filetype plugin on
"}}}
"利用cvim.zip插件实现,下载后解压到~/.vim中
"a.vim实现源文件与头文件切换
"{{{
let alternateSearchPath = 'sfr:.,sfr:./include,sfr:../include' "设置include(.h)文件存在何处.
let alternateNoDefaultAlternate = 1 "当没有找到相应的.h文件时,不自动创建
":A 切换当前文件的头文件,在当前窗口打开(或者反过来) "先打开.h .c 文件存于buff中
":AS 功能同:A,但是切换到水平分割窗口的打开
":AV 功能同:A,但是切换到竖直分割的窗口打开
":AT 功能同:A,但是切换到标签页打开
"}}}
"a.vim实现源文件与头文件切换
"vim 自带Marks的使用, 如果不习惯可以使用插件ShowMarks(下面有介绍), 使能showmarks_enable = 1
"{{{
"这个功能是VIM自带的功能, 习惯就好, 一切从简.可以查看帮助文档, 下面是简单介绍.
"(1) 设置标记 --> norm模式下, m + [a-z]. ( m - mark, [a-z] 也可以是[A-Z], 推荐只使用小写字母. )
"(2) 删除标记 --> 多种方法如下:
" 1. 删除标记所在的行.
" 2. 在其他行作相同的标记(eg. ma ).
" 3. 命令模式下 :delmarks a ( 简写 :delm a )
" 4. 命令模式下 :delmarks! ( 删除所有小写字母标记 )
" 5. 删除多个标记 :delmarks abcd (a,b,c,d都被删除, 也可以 :delmarks a-d)
"(3) 使用标记 -->
" 1. 定位到标记位置(以a为例) --> `a or 'a ( 区别在于 `a到目标行的最左端,'a到目标行的第一个非空字符之前)
" 2. 对当前行到标记位置的操作--> d`a , y`a , c`a 分别表示对该区域的删除, 复制, 更改
" 3. 显示设置的标记信息 --> :marks (显示所有) :marks a (只显示a标记的信息)
"(4) 有用特殊标记(系统设置好的)
" 1. '' 或者 `` 从当前行跳回到最近一次跳到改行的位置去.
" 2. `. 从当前行跳回到最后一次修改的行的位置去.
"}}}
"vim 自带Marks的使用, 如果不习惯可以使用插件ShowMarks(下面有介绍), 使能showmarks_enable = 1
"ShowMarks高亮功能显示出标记的位置( 先使用vim提供的sign功能进行标记位置 )
"{{{
" ================= (第一个) http://www.vim.org/scripts/script.php?script_id=152 对vim7.x是有一小点问题的. =============
"let showmarks_enable = 1 "使能showmarks插件
let showmarks_enable = 0
"Show which marks:全部的大写标记和小写 ( 推荐只使用小写, 大写可能有bug )
let showmarks_include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
" Ignore help, quickfix, non-modifiable buffers:对文件类型为help, quickfix, 和不可修改的缓冲区,不显示标记的位置
let showmarks_ignore_type = "hqm"
" Hilight lower & upper marks
let showmarks_hlline_lower = 1
let showmarks_hlline_upper = 1
hi ShowMarksHLl ctermbg=Black ctermfg=White "guibg=#FFDB72 guifg=Black "Magenta
hi ShowMarksHLu ctermbg=Yellow ctermfg=Black "guibg=#FFB3FF guifg=Black
"ShowMarks插件中已经定义了一些快捷键:
",mt - 打开/关闭ShowMarks插件 ( 常用 )
",mo - 强制打开ShowMarks插件
",mh - 清除当前行的标记 ( 常用 )
",ma - 清除当前缓冲区中所有的标记 ( 常用 )
",mm - 在当前行打一个标记,使用下一个可用的标记名 ( 常用 )
" ================= (第二个) http://www.vim.org/scripts/script.php?script_id=2142 =============
"解压到vim家目录即可, 使用默认.
"设置可用来作标记的字母
"let g:showmarks_marks = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" "使用默认
"}}}
"ShowMarks高亮功能显示出标记的位置( 先使用vim提供的sign功能进行标记位置 )
"mark.vim 当你在文件中想多个不同的关键词,且用不同的颜色显示, 那么该插件可你帮助你
"{{{
"下载地址: http://www.vim.org/scripts/script.php?script_id=1238
"1. map keys 触发键 默认是'/', 可以设置为',' let g:mapleader=",". 本vimrc已设置为','
"2. ,m : "高亮"显示光标下的单词或取消当前光标下的单词高亮显示
"3. ,r : 手工输入需要高亮显示的单词
"4. ,n : 当光标下有"高亮"显示的单词时,则取消. 如光标下没有"高亮"的单词时,则取消所有"高亮"的单词.
"5. * : 下一个与光标下颜色相同的高亮单词.
"6. # : 上一个与光标下颜色相同的高亮单词.
"7. ,/ : 下一个高亮单词(不一定是相同颜色).
"8. ,? : 上一个高亮单词(不一定是相同颜色).
"9. 重新定义需要高亮单词的颜色:
hi MarkWord1 ctermbg=Yellow ctermfg=White guibg=#FFDB72 guifg=Black
hi MarkWord2 ctermbg=Blue ctermfg=White guibg=#9999FF guifg=Black
hi MarkWord3 ctermbg=Cyan ctermfg=White guibg=#8CCBEA guifg=Black
hi MarkWord4 ctermbg=Red ctermfg=White guibg=#FF7272 guifg=Black
hi MarkWord5 ctermbg=Brown ctermfg=White guibg=#FF7272 guifg=Black
hi MarkWord6 ctermbg=Magenta ctermfg=White guibg=#FFB3FF guifg=Black
hi MarkWord7 ctermbg=Green ctermfg=White guibg=#A4E57E guifg=Black
"}}}
"mark.vim 当你在文件中想多个不同的关键词,且用不同的颜色显示, 那么该插件可你帮助你
"自动更新tags文件autotags.vim插件
""{{{
"要到autotags.vim中修改tags文件大小 __maxTagsFileSize = 1024 * 1024 * 5
"let g:autotagDisabled = 1 "还是关掉好.太低效
"let g:autotagTagsFile = '/home/tags/tags'
""}}}
"自动更新tags文件autotags.vim插件
"工程管理值tags更新 -- indexer.vim
""{{{
"let g:indexer_indexerListFilename="/home/tags/indexer_file"
"let g:indexer_ctagsCommandLineOptions = '--c++-kinds=+p+l --fields=+ialS --extra=+q'
""}}}
"工程管理值tags更新 -- indexer.vim
"srcexpl.vim just like source insight
""{{{
"let loaded_srcexpl = 0
" // The switch of the Source Explorer
"nmap <F8> :SrcExplToggle<CR>
" // Set the height of Source Explorer window
"let g:SrcExpl_winHeight = 8
" // Set 100 ms for refreshing the Source Explorer
"let g:SrcExpl_refreshTime = 100
" // Set "Enter" key to jump into the exact definition context
" let g:SrcExpl_jumpKey = "<ENTER>"
" // Set "Space" key for back from the definition context
"let g:SrcExpl_gobackKey = "<SPACE>"
" // In order to Avoid conflicts, the Source Explorer should know what plugins
" // are using buffers. And you need add their bufname into the list below
" // according to the command ":buffers!"
"let g:SrcExpl_pluginList = [
/ "__Tag_List__",
/ "_NERD_tree_",
/ "Source_Explorer"
/ ]
" // Enable/Disable the local definition searching, and note that this is not
" // guaranteed to work, the Source Explorer doesn't check the syntax for now.
" // It only searches for a match with the keyword according to command 'gd'
"let g:SrcExpl_searchLocalDef = 1
" // Do not let the Source Explorer update the tags file when opening
"let g:SrcExpl_isUpdateTags = 0
" // Use 'Exuberant Ctags' with '--sort=foldcase -R .' or '-L cscope.files' to
" // create/update a tags file
"let g:SrcExpl_updateTagsCmd = "ctags --sort=foldcase -R ."
" // Set "<F12>" key for updating the tags file artificially
"let g:SrcExpl_updateTagsKey = "<F12>"
"}}}
"srcexpl.vim just like source insight
"----------------------
"利用 插件 丰富 功能
"----------------------
"}}}
"==================================以下是个人喜爱使用的vim(or 插件)其他强大功能,尚未完成===========================
"
"vim master
""{{{
"
"Verdancy --- New Commer
""{{{
" f --- find; practic : (before)"aabbbccdd" --> ex: dfc --> (after)"cdd"
"
"寄存器
""{{{
" q[a-z] --- 记录命令, 已q结束, @[a-z]引用 --- 很强大,需要习惯使用
" "[a-z]p --- 可以将寄存器[a-z]中的命令以文本的方式输出,并进行修改
" "[a-z]y$ --- 将寄存器修改后的内容存回到对应寄存器
""}}}
"寄存器
"
""}}}
"Verdancy --- New Commer
"
"Visual 选中模式
""{{{
" shift + v : 配合jk,上下键,整行选择
" ctrl + v : 配合hjkl,上下左右键,灵活选择区域
" o : 在选中的区域中对角线移动
" O : 在选中的区域中行左右移动
" gv : 重新选中原来的选中的区域
" : : 在选中区域后,shift+:到命令模式, : eg. '<,'>s/pattern/newstring/g -- 在选中的区域中查找patte && replace
" ctrl + v 选中一列后, 按I插入字符,Esc退出 : 每一行都添加这个字符,很好的一个注释方法
""}}}
"Visual 选中模式
"
"Command Mode
""{{{
" :g/pattern/d --- delete line contained of string "pattern"
""}}}
"Command Mode
"
"窗口
""{{{
"ctrl + 0 : 恢复窗口大小
"ctrl + = : 窗口等大
"ctrl + w + _ : 窗口最大化
"nctrl + w + _ : 改变窗口的大小
"ctrl + w + ctrl + c : 关闭窗口
"ctrl + w + ctrl + ] : 以函数所在文件分割窗口
"ctrl + w + shift + [hjkl] : 窗口位置放置
"
"shift + z + z : close vim edit. You need set auto write.
"
"vim t1.c t2.c t3.c -o2 : open thress files using two windows. if -o(no number), using three windows here.
""}}}
"窗口
"
"杂项
""{{{
" !!date --- 插入日期
" read !date -R --- 插入日期 ( -R 显示日期的格式而已 man date )
"
" ctr + w ctrl + c --- 关闭当前窗口
"
" %s//s/+$// --- 删除多余的空格
"
" ctrl + K --- 插入特殊字符
" digraph --- 显示特殊字符,字符组合
"
" set ic --- 忽略大小写
"
" . --- 重复前次操作
"
" ctrl + a --- repeat record.
"
" ctrl + r --- 反撤消, 当u撤消后,又想恢复,可以使用
"
" daw && caw && cis --- delete a word && change a word && 修改一个句子
"
" cc && dd --- change one line reserving indent && delete one line
"
" CTRL+U ---- CTRL+D ---> half page move
" CTRL+E ---- CTRL+Y ---> one line move
" CTRL+F ---- CTRL+B ---> one page move
"
" CTRL + O --- 返回刚才½置,每按一次都会退回到之前的位置
" CTRL + I --- 与CTRL+O相反,每按一次退回来
"
" [i --- (将光标移到变量上)显示第一个局部变量定义处
" [I --- (将光标移到变量上)显示所有该变量的定义处
" '' --- 回到刚才停留处
"
" //<patter/> ---- 精确查找
"
"
""}}}
"杂项
"
""}}}
"vim master
"
"Shell
""{{{
"巧妙去除Linux下代码行中的^M符号和windows下代码编辑引起的警告错
":%s /^M//g ,其中^M的写法是按住ctrl不放,再按v,然后按M,再放ctrl
""{{{
" #wash_error.sh
" #!/bin/sh
" ls *.h *.c | awk '{print $1}' > dealfile
" cat dealfile | while read file
" do
" echo " " >> $file
" done
" #dos2unix *.c *.h
""}}}
"巧妙去除Linux下代码行中的^M符号和windows下代码编辑引起的警告错
""}}}
"Shell
"
"==================================以上是个人喜爱使用的vim(or 插件)其他强大功能,尚未完成===========================
"Doxygen 例子
"{{{
"/**
" * @file t.c
" * @brief Test for test
" * @author Michael
" * @version 1.0
" * @date 2011-04-10
" */
"
"/**
" * @struct STU_INFO
" * @brief This is a struct about student's infomation.
" */
"struct STU_INFO
"{
" unsigned int stu_no; /**< stu_no : ID of the Student */
" unsigned int stu_age; /**< stu_age : Age of the Student */
" char stu_name[100]; /**< stu_name: Name of the Student */
" unsigned short int stu_level; /**< stu_level: level of the Student */
" struct STU_INFO *next; /**< next : Pointer to next Student */
"};
"
"/**
" * @enum STU_LEVEL
" * @brief This is a enum about student's level.
" */
"enum STU_LEVEL
"{
" NUMBER_ONE, /**< student's level : 1 or A */
" NUMBER_TWO, /**< student's level : 2 or B */
" NUMBER_THREE, /**< student's level : 3 or C */
" NUMBER_FOUR /**< student's level : 4 or D */
"};
"
"/**
" * @brief This is a function about getting the student's infomation by id.
" * - student who get A can own:
" * -# A intellectual computer.
" * -# A kiss of Michael.
" * - student who get B can own:
" * -# A intellectual phone.
" * -# A kiss of Jone.
" *
" * @param id a unsigned integer param.
" * @param stu a pointer that return the student info.
" *
" * @return student's level
" */
"int get_student_info( unsigned int id, struct STU_INFO *stu )
"{
" return level.
"}
"}}}
"Doxygen 例子