"F1~F12快捷键映射
""{{{
map :NERDTreeToggle.
map :BufExplorer
map :TlistToggle
map :call CompileRunGcc() "上面映射
nnoremap :A
"noremap :make
"noremap :make clean;make
"noremap :!cvs up
""}}}
"F1~F12快捷键映射
"非F1~F12快捷键
""{{{
let mapleader=","
let g:mapleader=","
map svi : source ~/.vimrc " fast reloading of the .vimrc
map evi : e! ~/.vimrc " fast editing of .vimrc
""}}}
"非F1~F12快捷键
"简单配置
"{{{
"使用鼠标
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:14
"在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后自动删除
"关闭交换文件
"set nocp
"关闭交换文件
"不使用swap文件
"set noswapfile
"不使用swap文件
"显示匹配的括号([{和}])
set showmatch
"显示匹配的括号([{和}])
"显示日期的缩写
iab xdate =strftime("%Y-%m-%d %H:%M:%S")
"显示日期的缩写
"关闭遇到错误时的声音提示
set noerrorbells
"关闭遇到错误时的声音提示
"不要闪烁
set novisualbell
"不要闪烁
"使用空格来替换tab
set expandtab
"set et
"使用空格来替换tab
"在vim编辑器下方显示命令
set showcmd
"在vim编辑器下方显示命令
"当光标达到上端或下端时 翻滚的行数
set scrolljump =5
"当光标达到上端或下端时 翻滚的行数
"当光标达到水平极端时 移动的列数
set sidescroll =5
"当光标达到水平极端时 移动的列数
"当光标距离极端(上,下,左,右)多少时发生窗口滚动
set scrolloff =0
"当光标距离极端(上,下,左,右)多少时发生窗口滚动
"当使用vimdiff比较文件,相比较的比较文件同步滚动,但是分割窗口也同步
"set scrollbind
set noscrollbind
"当使用vimdiff比较文件,相比较的比较文件同步滚动,但是分割窗口也同步
"将当前编辑文件的路径设置为当前路径
set autochdir
"将当前编辑文件的路径设置为当前路径
"侦测文件类型
filetype on
"侦测文件类型
"载入文件类型插件
filetype plugin on
"载入文件类型插件
"为特定文件类型载入相关缩进文件
filetype indent on
"为特定文件类型载入相关缩进文件
"自动读写相关
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
"显示括号配对情况
"自能缩进 smart cindent
set si
"自能缩进 smart cindent
"打开 C/C++ 风格的自动缩进 ( =a{ , gg=G 代码美化 )
set cin
"打开 C/C++ 风格的自动缩进 ( =a{ , gg=G 代码美化 )
"打开语法色彩
syntax enable
"打开语法色彩
"打开关键字色
syntax on
"打开关键字色
"设置VIM颜色主题
colorscheme elflord
"设置VIM颜色主题
"允许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+=_,$,@,%,#,-
"带有如下符号的单词不要被换行分割
"}}}
"简单配置
"字符编码(多字节)
"{{{
if has("multi_byte")
set encoding=utf-8
"set fileencoding=cp936
"set fileencoding=utf-8
"set fileencodings=ucs-bom,utf-8,chinese
set fileencodings=ucs-bom,utf-8,chinese,big5,latin1,cp936
endif
"if has("multi_byte")
" " Set fileencoding priority
" if getfsize(expand("%")) > 0
" set fileencodings=ucs-bom,utf-8,cp936,big5,euc-jp,euc-kr,latin1
" else
" set fileencodings=cp936,big5,euc-jp,euc-kr,latin1
" endif
" " CJK environment detection and corresponding setting
" if v:lang =~ "^zh_CN"
" " Use cp936 to support GBK, euc-cn == gb2312
" set encoding=cp936
" set termencoding=cp936
" set fileencoding=cp936
" elseif v:lang =~ "^zh_TW"
" " cp950, big5 or euc-tw
" " Are they equal to each other?
" set encoding=big5
" set termencoding=big5
" set fileencoding=big5
" elseif v:lang =~ "^ko"
" " Copied from someone's dotfile, untested
" set encoding=euc-kr
" set termencoding=euc-kr
" set fileencoding=euc-kr
" elseif v:lang =~ "^ja_JP"
" " Copied from someone's dotfile, unteste
" set encoding=euc-jp
" set termencoding=euc-jp
" set fileencoding=euc-jp
" endif
" " Detect UTF-8 locale, and replace CJK setting if needed
" if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
" set encoding=utf-8
" set termencoding=utf-8
" set fileencoding=utf-8
" endif
"else
" echoerr "Sorry, this version of (g)vim was not compiled with multi_byte"
"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的编译和运行
"{{{
"map :call CompileRunGcc() "上面映射
func! CompileRunGcc()
exec "w"
exec "!gcc % -o %<"
exec "! ./%<"
endfunc
"}}}
"C的编译和运行
"目前看不到作用nicer foldtext
"{{{
set foldtext=MyFoldtext()
function! MyFoldtext()
let line = getline(v:foldstart)
let level = v:foldlevel
let i = 1
while i < level
let line = ' ' . line
let i = i + 1
endwhile
let num = v:foldend - v:foldstart
let line = line . '------' . num . ' lines'
return line
endfunction
"}}}
"目前看不到作用nicer foldtext
"search 搜索
""{{{
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 h *N " 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 * :call VisualSearch('f')
vnoremap # :call VisualSearch('b')
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 :nohl " :press to clear hightlight search highlight
""}}}
"search 搜索
"显示当前文件
"{{{
"显示状态栏
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()}/ /|
"状态行显示内容
" %F 当前文件名
" %m 当前文件修改状态
" %r 当前文件是否只读
" %Y 当前文件类型
" %{&fileformat} 当前文件编码
" %b 当前光标处字符的 ASCII 码值
" %B 当前光标处字符的十六进制值
" %l 当前光标行号
" %c 当前光标列号
" %V 当前光标虚拟列号 (根据字符所占字节数计算)
" %p 当前行占总行数的百分比
" %% 百分号
" %L 当前文件总行数
"}}}
"显示当前文件
"当前行(列)高亮显示
"{{{
set cursorline
set cursorcolumn
"hi CursorLine term=bold cterm=bold ctermbg=darkgrey ctermfg=yellow guibg=#333333 guifg=red
"hi CursorLine term=bold cterm=bold ctermbg=darkyellow ctermfg=darkblue guibg=lightblue guifg=black
"hi CursorLine term=bold cterm=bold ctermbg=black ctermfg=yellow guibg=darkgrey guifg=darkyellow
"hi CursorLine term=reverse cterm=reverse ctermbg=darkred ctermfg=black guibg=blue guifg=white
hi CursorLine term=reverse cterm=reverse ctermbg=darkyellow ctermfg=red guibg=blue guifg=white
"hi CursorLine term=bold cterm=bold ctermfg=black ctermfg=white guibg=blue guifg=white
hi CursorColumn term=bold cterm=bold ctermbg=black ctermfg=white guibg=darkgrey guifg=white
nnoremap c : set cursorline! cursorcolumn!
"set cursorline
"au! Cursorhold * exe 'match CurrentLine //%' . line('.') . 'l.*/'
"set ut=100
"}}}
"当前行(列)高亮显示
"单行或多行注释
"{{{
nmap :Setcomment
"normal 模式下ctrl + C 快捷键
imap :Setcomment
"insert 模式下ctrl + C 快捷键
vmap :SetcommentV
"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
"空格和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
"}}}
"单行或多行注释
"自己定义函数或函数头文件
"{{{
"ctrl+F12 或 ctrl+F11:生成tags
"vim -t sys_open : 就可以到sys_open 的定义出
"--c++-kinds=+p : 为C++文件增加函数原型的标签
"--fields=+iaS : 在标签文件中加入继承信息(i)、类成员的访问控制信息(a)、以及函数的指纹(S)
"--extra=+q : 为标签增加类修饰符。注意,如果没有此选项,将不能对类成员补全
"map :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
"map :!ctags -R --c-kinds=+p --fields=+iaS --extra=+q .
"map :!ctags -R .
set tags+=./tags
"}}}
"自己定义函数或函数头文件
"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 @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo') "使用空格打开或关闭折叠
"}}}
"vim折叠功能
"文件比较
""{{{
":vertical diffsplit FILE_RIGHT "与已打开的文件进行比较
"命令模式(ESC键进入):
"dp 左边文件差异复制到右边文件(直接在键盘上行按下dp)
"do 右边文件差异复制到左边文件(直接在键盘上行按下do)
"zo 隐藏相同行
"zc 展开向同行
"u 撤销
"Ctrl+w 文件切换
"
":qa! 退出不保存
":wa 保存
":wqa 保存退出
":diffupdate 重新比较
""}}}
"文件比较
"C库函数参数Scratch显示
""{{{
"1.先下载glibc库
"2.解压到/usr/src中
"3.执行:ctags -R --c-kinds=f
"4.ctrl+x ctrl+o
"one 添加c库函数定义数据库
"set tags+=/usr/src/glibc/tags
"two 添加linux 源码 函数定义数据库
"set tags+=/usr/src/linux/tags
"}}}
"C库函数参数Scratch显示
"C库类型定义,函数声明,宏定义等
"{{{
"1.cd /usr/include/
"2.执行:ctags -R --c-kinds=+pxd
"3.使用:ctrl+x ctrl+]
"set tags+=/usr/include/tags
"}}}
"C库类型定义,函数声明,宏定义等
"单词列表匹配
"{{{
"ctrl+x ctrl+k
"set dictionary+=/usr/share/dict/wordlist.txt
set dictionary+=~/.vim/c-support/wordlists/wordlist.list
set dictionary+=~/.vim/c-support/wordlists/include.list
set complete-=k complete+=k
"}}}
"单词列表匹配
"括号智能匹配
"{{{
:inoremap ( ()i
:inoremap ) =ClosePair(')')
:inoremap { {}i
:inoremap } =ClosePair('}')
:inoremap [ []i
:inoremap ] =ClosePair(']')
:inoremap " ""i
:inoremap " =ClosePair('"')
":inoremap < <>i
":inoremap > =ClosePair('>')
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "/"
else
return a:char
endif
endf
"}}}
"括号智能匹配
"tab智能完成 使用实际的tab 需要shift+tab
"{{{
"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 "/"
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 "//" " existing text matching
elseif ( has_slash )
return "//" " file matching
else
return "//" " plugin matching
endif
endfunction
"inoremap =Smart_TabComplete()
"}}}
"tab智能完成 使用实际的tab 需要shift+tab
"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 到该文件去
"----------------------
"利用 插件 丰富 功能
"----------------------
"WinManager 插件 ( 不好用 )
""{{{
"let g:defaultExplorer=1
"let g:winManagerWindowLayout='FileExplorer|BufExplorer|TagList'
"let g:persistentBehaviour=0 "只剩一个窗口时, 退出vim.
"let g:winManagerWidth=80 "设置winmanager的宽度,默认为25
"nmap fir :FirstExplorerWindow
"nmap bot :BottomExplorerWindow
"nmap wm :WMToggle
"nmap :WMToggle "定义打开关闭winmanager按键
""}}}
"WinManager 插件 ( 不好用 )
"NERD_commenter.vim : 1218
""{{{
let NERDSpaceDelims=1
let NERD_c_alt_style=1
"Default mapping:
"[count],cc " 以行为单位进行注释.
" ,c " 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
"F2单独切换打开NERD_tree(nerd_tree插件)
"{{{
let g:NERDChristmasTree = 1 "色彩显示
let g:NERDTreNERDShowHidden = 1 "显示隐藏文件
let g:NERDTreeWinPos = 'left' "窗口显示位置
let g:NERDTreeHighlightCursorline = 0 "高亮当前行
let g:NERDTreeWinSize = 40 "设置显示宽度
"nmap :NERDTreeToggle.
"
" 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, 没错支持鼠标的~!
""}}}
"F2单独切换打开NERD_tree(nerd_tree插件)
"bufexplorer插件
"{{{
"map :BufExplorer
",be 打开选择窗口 ','是前面mapleader设置的 ( F3 )
"r可以进行反向排序.
"d/D可以用来关闭文件.
"p可以用来显示/关闭绝对路径模式
"}}}
"bufexplorer插件
"使用 autocomplpop.vim 插件
""{{{
" 1. 下载 autocomplpop.vim 后,放到Vim文件目录下的plugin目录中
" 2. 增加智能提示触发命令
" 3. 加入PHP的全能提示触发命令
if !exists('g:AutoComplPop_Behavior')
let g:AutoComplPop_Behavior = {}
let g:AutoComplPop_Behavior['php'] = []
call add(g:AutoComplPop_Behavior['php'], {'command': "//",'pattern': printf('/(->/|::/|/$/)/k/{%d,}$', 0),'repeat': 0,})
endif
""}}}
"使用 autocomplpop.vim 插件
"completeopt 弹出菜单 输入字母实现即时的过滤和匹配
""{{{
"关掉智能补全时的预览窗口 (Scratch)
" menu 使用弹出菜单来显示可能的补全
" longest 只插入匹配的最长公共文本
"set completeopt=menuone,menu,longest,preview
set completeopt=menu,longest
"filetype plugin on
"set ofu=syntaxcomplete#Complete
"
"filetype plugin indent on
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType java set omnifunc=javacomplete#Complete
if has("autocmd") && exists("+omnifunc")
autocmd Filetype *
/ if &omnifunc == "" |
/ setlocal omnifunc=syntaxcomplete#Complete |
/ endif
endif
let g:rubycomplete_buffer_loading = 1
let g:rubycomplete_classes_in_global = 1
"let g:rubycomplete_rails = 1
"
""}}}
"completeopt 弹出菜单 输入字母实现即时的过滤和匹配
"让autocomlpop 支持snipMate.vim
"{{{
"将下面fun写到snipMate.vim
"fun! GetSnipsInCurrentScope()
" let snips = {}
" for scope in [bufnr('%')] + split(&ft, '/.') + ['_']
" call extend(snips, get(s:snippets, scope, {}), 'keep')
" call extend(snips, get(s:multi_snips, scope, {}),'keep')
" endfor
" return snips
"endf
"set g:acp_behaviorSnipmateLength=1
"}}}
"让autocomlpop 支持snipMate.vim
"加速你的补全 -- 插件: SuperTab 使用上面的,可以关闭这个
"{{{
"设置按下后默认的补全方式, 默认是,
"现在改为. 关于的补全方式,
"还有其他的补全方式, 你可以看看下面的一些帮助:
":help ins-completion
":help compl-omni
" 0 - 不记录上次的补全方式
" 1 - 记住上次的补全方式,直到用其他的补全命令改变它
" 2 - 记住上次的补全方式,直到按 ESC 退出插入模式为止
"let g:SuperTabRetainCompletionType=2
"let g:SuperTabDefaultCompletionType=""
"}}}
"加速你的补全 -- 插件: SuperTab 使用上面的,可以关闭这个
"OmniCppComplete : C/C++ omni-completion with ctags database
""{{{
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
"自定义快捷键
inoremap pumvisible()?"/":"/"
inoremap pumvisible()?"///":"/"
inoremap pumvisible()?"///":"/"
inoremap pumvisible()?"/":"/"
"inoremap pumvisible()?"/":"/"
"inoremap pumvisible()?"/":"/"
"=================================
"注意:tab 是选择下一项, shift+tab 是选择上一项
"=================================
"上面的映射都是在插入模式下的映射,解释如下
"如果下拉菜单弹出,回车映射为接受当前所选项目,否则,仍映射为回车
"如果下拉菜单弹出,CTRL-J映射为在下拉菜单中向下翻页。否则映射为CTRL-X CTRL-O
"如果下拉菜单弹出,CTRL-K映射为在下拉菜单中向上翻页,否则仍映射为CTRL-K
"如果下拉菜单弹出,CTRL-U映射为CTRL-E,即停止补全,否则,仍映射为CTRL-U
"如果下拉菜单弹出,CTRL-P映射为在下拉菜单中表示上一项。
"如果下拉菜单弹出,CTRL-N映射为在下拉菜单中表示下一项。
":set omnifunc ? 查看设置的补全插件
autocmd FileType cpp set omnifunc=omni#cpp#complete#Main
""}}}
"OmniCppComplete : C/C++ omni-completion with ctags database
"教你高效地浏览源码 -- 插件: TagList
""{{{
"在taglist窗口中,可以使用下面的快捷键:
" 跳到光标下tag所定义的位置,用鼠标双击此tag功能也一样
"o 在一个新打开的窗口中显示光标下tag
" 显示光标下tag的原型定义
"u 更新taglist窗口中的tag
"s 更改排序方式,在按名字排序和按出现顺序排序间切换
"x taglist窗口放大和缩小,方便查看较长的tag
"+ 打开一个折叠,同zo
"- 将tag折叠起来,同zc
"* 打开所有的折叠,同zR
"= 将所有tag折叠起来,同zM
"[[ 跳到前一个文件
"]] 跳到后一个文件
"q 关闭taglist窗口
" 显示帮助
"使用 :Tlist
":help taglist.txt ( ~/.vim/doc/taglist.txt )
"
"快捷键
"map :TlistToggle
"noremap :Tlist
"noremap :TlistSync
"快捷键
"
"设定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 = 40
"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
""{{{
"是否使用 quickfix 窗口来显示 cscope 结果
set cscopequickfix=s-,c-,d-,i-,t-,e-
"0 或 s 查找本 C 符号(可以跳过注释)
"1 或 g 查找本定义
"2 或 d 查找本函数调用的函数 --可以到函数的定义处
"3 或 c 查找调用本函数的函数 --该函数被谁调用
"4 或 t 查找本字符串
"6 或 e 查找本 egrep 模式
"7 或 f 查找本文件
"8 或 i 查找包含本文件的文件
"ctrl + o 可以返回
nmap s :cs find s =expand("")
nmap g :cs find g =expand("")
nmap c :cs find c =expand("")
nmap t :cs find t =expand("")
nmap e :cs find e =expand("")
nmap f :cs find f =expand("")
nmap i :cs find i ^=expand("")$
nmap d :cs find d =expand("")
"使用方法
"生成一个 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 :!./vitags.sh:cs reset
"noremap :! cscope -Rbq:cs reset
"
"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
"个人添加
"========= vim 打开文件时自动加载 ========
cs add /home/tags/cscope.out /home/tags
cs add /usr/include/cscope.out /usr/include
cs add /newdisk/b190_Brcm7405_UBI/cscope.out /newdisk/b190_Brcm7405_UBI
cs add /newdisk/libzebra/cscope.out /newdisk/libzebra
"========= vim 打开文件时自动加载 ========
"个人添加
set csverb
set cscopetag
endif
"cscope和ctags的兼容问题
":help if_cscop.txt
":cs show
"}}}
"当查看源码是使用 -- 插件 : Cscope
"利用c.vim插件实现,下载后解压到~/.vim中
""{{{
"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)
" /cs set end-of-line comment column (n)
" /c* code -> comment /* */ (n,v)
" /cc code -> comment // (n,v)
" /co comment -> code (n,v)
" /cfr frame comment (n,i)
" /cfu function comment (n,i)
" /cme method description (n,i)
" /ccl class description (n,i)
" /cd date (n,v,i)
" /ct date /& time (n,v,i)
" -- Statements ------------------------------------------
" /sd do { } while (n,v,i)
" /sfo for { } (n,v,i)
" /sife if { } else { } (n,v,i)
" /se else { } (n,v,i)
" /swh while { } (n,v,i)
" /ss switch (n,v,i)
" -- Preprocessor -----------------------------------------
" /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
" /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)
" /+c class (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)
" /rg cmd. line arg. for make (n,i)
" /rp run splint (n,i)
" /ri cmd. line arg. for splint (n,i)
" /rk run CodeCheck (TM) (n,i)
" /re 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
"}}}
"利用c.vim插件实现,下载后解压到~/.vim中
"a.vim实现源文件与头文件切换
"{{{
"nnoremap :A
":A 切换当前文件的头文件,在当前窗口打开(或者反过来) "先打开.h .c 文件存于buff中
":AS 功能同:A,但是切换到水平分割窗口的打开
":AV 功能同:A,但是切换到竖直分割的窗口打开
":AT 功能同:A,但是切换到标签页打开
"}}}
"a.vim实现源文件与头文件切换
"----------------------
"利用 插件 丰富 功能
"----------------------
"Highlight All Function
"{{{
syn match cFunction "/<[a-zA-Z_][a-zA-Z_0-9]*/>[^()]*)("me=e-2
syn match cFunction "/<[a-zA-Z_][a-zA-Z_0-9]*/>/s*("me=e-1
hi cFunction gui=NONE guifg=#B5A1FF
"}}}
"Highlight All Function
"
"
" Highlight All Math Operator
""{{{
" C math operators
syn match cMathOperator display "[-+/*/%=]"
"
" C pointer operators
syn match cPointerOperator display "->/|/."
"
" C logical operators - boolean results
syn match cLogicalOperator display "[!<>]=/="
syn match cLogicalOperator display "=="
"
" C bit operators
syn match cBinaryOperator display "/(&/||/|/^/|>/)=/="
syn match cBinaryOperator display "/(&/||/|/^/|<|>>/)=/="
syn match cBinaryOperator display "/~"
syn match cBinaryOperatorError display "/~="
"
" More C logical operators - highlight in preference to binary
syn match cLogicalOperator display "&&/|||"
syn match cLogicalOperatorError display "/(&&/|||/)="
"
" Math Operator
hi cMathOperator guifg=#3EFFE2
hi cPointerOperator guifg=#3EFFE2
hi cLogicalOperator guifg=#3EFFE2
hi cBinaryOperator guifg=#3EFFE2
hi cBinaryOperatorError guifg=#3EFFE2
hi cLogicalOperator guifg=#3EFFE2
hi cLogicalOperatorError guifg=#3EFFE2
"
""}}}
" Highlight All Math Operator
" 临时
""{{{
"set tags+=/newdisk/b190_Brcm7405_UBI/tags
"set tags+=/home/tags/tags
"set tags+=/usr/include/tags
""}}}
" 临时
"==================================以下是个人喜爱使用的vim(or 插件)其他强大功能===========================
"
"c-support hotkeys begin
"{{{
"详细内容c-hotkeys.tex
"/cl' & end-of-line comment ------- good
"/cj' & adjust end-of-line comment ------- good
"/cs' & set end-of-line comment column
"/c*' & code $/Rightarrow$ comment /verb'/* */'
"/cc' & code $/Rightarrow$ comment /verb'//' ------- 使用上面设置 ctrl + c 好些,同时可以去掉注释
"/cfr'& frame comment ------- good
"/cfu'& function comment ------- good
"/cd' & date ------- good
"/ct' & date /& time ------- good
"
"/sd' & /verb'do { } while'
"/sf' & /verb'for'
"/sfo' & /verb'for { }'
"/si' & /verb'if'
"/sif' & /verb'if { }'
"/sie' & /verb'if else'
"/sife'& /verb'if { } else { }' ------ good
"/sw' & /verb'while'
"/swh' & /verb'while { }'
"/ss' & /verb'switch' --------- good
"/sc' & /verb'case'
"/s{' & /verb'{ }'
"
"/p<' & /verb$#include<...>$ --------- good
"/p"' & /verb$#include"..."$ --------- good
"/pd' & /verb'#define'
"/pu' & /verb'#undef'
"/pie' & /verb'#if #else #endif'
"/pid' & /verb'#ifdef #else #endif'
"/pin' & /verb'#ifndef #else #endif'
"/pind' & /verb'#ifndef #def #endif' --------- good
"/pi0' & /verb'#if 0 #endif' --------- good
"/pr0' & remove /verb'#if 0 #endif' --------- good
"
"/if' & function --------- good (我一改动: 第一个参数是返回类型, 第二个是函数名 ))
"/isf' & static function --------- good
"/im' & /verb'main()' --------- good
"/i0' & /verb'for( x=0; x
"/in' & /verb'for( x=n-1; x>=0; x-=1 )'
"/ie' & /verb'enum' + /verb'typedef'
"/is' & /verb'struct' + /verb'typedef' --------- good
"/iu' & /verb'union' + /verb'typedef'
"/ip' & /verb'printf()' --------- good
"/isc' & /verb'scanf()'
"/ica' & /verb'p=calloc()'
"/ima' & /verb'p=malloc()' --------- good
"/isi' & /verb'sizeof()' --------- good
"/ias' & /verb'assert()'
"/ii' & open input file --------- good
"/io' & open output file --------- good
"}}}
"c-support hotkeys end
"
"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 --- (将光标移到变量上)显示所有该变量的定义处
" '' --- 回到刚才停留处
"
" // ---- 精确查找
"
"
""}}}
"杂项
"
""}}}
"vim master
"
"Shell
""{{{
"
"CSCOPE CTAGS
""{{{
" #!/bin/sh
" rm -f cscope.* tags
" find -name "*.h" -o -name "*.c" -o -name "*.cc" > cscope.files
" cscope -bkq -i cscope.files
" ctags -R
""}}}
"CSCOPE CTAGS
"
"巧妙去除Linux下代码行中的^M符号和windows下代码编辑引起的警告错
""{{{
" #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 插件)其他强大功能===========================