- "~/.vimrc (configuration file for vim only)
- " Encoding related
- set fileencodings=utf-8,gb2312,gbk,gb18030
- set termencoding=utf-8
- """""""""""""""""""""""""""""""""""""""""""""""""""""""
- " vundle begin
- """""""""""""""""""""""""""""""""""""""""""""""""""""""
- filetype off " required!
- set rtp+=~/.vim/bundle/vundle/
- call vundle#rc()
- " let Vundle manage Vundle
- Bundle 'gmarik/vundle'
- " vim-scripts repos
- " Improved C++ STL syntax highlighting
- Bundle 'STL-improved'
- " Displays tags in a window, ordered by class etc, i used it instead of taglist
- Bundle 'majutsushi/tagbar'
- " recommend fetch it from which support c and cpp
- Bundle 'tczengming/autoload_cscope.vim'
- Bundle 'CmdlineComplete'
- Bundle 'xptemplate'
- " Ultimate auto completion system for Vim
- Bundle 'neocomplcache'
- "Bundle 'Rip-Rip/clang_complete'
- "Bundle 'osyo-manga/neocomplcache-clang_complete'
- Bundle 'genutils'
- Bundle 'lookupfile'
- " Fuzzy file, buffer, mru, tag, ... finder with regexp support.
- Bundle 'kien/ctrlp.vim'
- " Fast file navigation
- Bundle 'wincent/Command-T'
- " Preview the definition of variables or functions in a preview window
- Bundle 'autopreview'
- " Echo the function declaration in the command line for C/C++
- Bundle 'echofunc.vim'
- Bundle 'grep.vim'
- Bundle 'a.vim'
- Bundle 'The-NERD-Commenter'
- Bundle 'The-NERD-tree'
- " Under linux need exec 'dos2unix ~/.vim/bundle/QFixToggle/plugin/qfixtoggle.vim'
- Bundle 'QFixToggle'
- Bundle 'Color-Sampler-Pack'
- Bundle 'altercation/vim-colors-solarized'
- Bundle 'txt.vim'
- Bundle 'mru.vim'
- Bundle 'YankRing.vim'
- Bundle 'tpope/vim-surround.git'
- Bundle 'DoxygenToolkit.vim'
- Bundle 'tczengming/headerGatesAdd.vim'
- Bundle 'ShowMarks'
- Bundle 'Lokaltog/vim-powerline'
- " Deal with pairs of punctuations such as (), [], {}, and so on
- Bundle 'kana/vim-smartinput'
- " non github repos
- " ...
- filetype plugin indent on " required!
- """""""""""""""""""""""""""""""""""""""""""""""""""""""
- " vundle end
- """""""""""""""""""""""""""""""""""""""""""""""""""""""
- " solarized theme
- set t_Co=256 " Explicitly tell vim that the terminal supports 256 colors, need before setting the colorscheme
- let g:solarized_termcolors=256
- colorscheme solarized
- set background=dark
- " Enable syntax highlighting
- syntax on
- set number
- set autochdir " 自动切换当前目录为当前文件所在的目录
- " Set to auto read when a file is changed from the outside
- set autoread
- " 下面两行改变备份文件存放路径
- set backupdir=~/.vim/backup
- set directory=~/.vim/backup
- " vim-powerline
- set laststatus=2 " always have status-line'
- let g:Powerline_symbols = 'fancy'
- "set statusline=%F%m%r%h%w\ %{&ff}\ %Y\ [ascii:%b\ hex:0x\%02.2B]\ [%{(&fenc\ ==\ \"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}]\ %=%l/%L,%v\ %p%%
- " allow backspacing over everything in insert mode
- set backspace=indent,eol,start
- " 光标到达行尾或者行首时,特定键继续移动转至下一行或上一行
- set whichwrap+=b,s,<,>,[,]
- " Tab related
- set shiftwidth=4
- set tabstop=4
- set softtabstop=4
- set expandtab " Use spaces instead of tabs
- set list
- set listchars=tab:\|\ , " 显示Tab符,使用一高亮竖线代替
- " Indent related
- "
- " g0 类的public顶格写
- " :0 将 case 标号放在 switch() 缩进位置之后的 N 个字符处
- " N-s namespace 下顶格
- " (0 条件语句多个条件在不同行时下一行与上一行对齐
- set cinoptions=g0,:0,N-s,(0
- set autoindent " always set autoindenting on
- set smartindent
- set mps+=<:> " 让<>可以使用%跳转
- set hid " allow to change buffer without saving
- set shortmess=atI " shortens messages to avoid 'press a key' prompt
- set lazyredraw " do not redraw while executing macros (much faster)
- " Set Number format to null(default is octal) , when press CTRL-A on number
- " like 007, it would not become 010
- set nf=
- " In Visual Block Mode, cursor can be positioned where there is no actual character
- set ve=block
- set ignorecase " Set search/replace pattern to ignore case
- set smartcase " Set smartcase mode on, If there is upper case character in the search patern, the 'ignorecase' option will be override.
- set showcmd " display incomplete commands
- set incsearch " do incremental searching
- set hlsearch " highlight search
- set magic " Enable magic matching
- set showmatch " show matching paren
- set wildmenu " 增强模式中的命令行自动完成操作
- "set mouse=a " Enable mouse usage (all modes) in terminals
- " showmarks setting
- let showmarks_enable = 0 " disable showmarks when vim startup
- let showmarks_include = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
- let showmarks_ignore_type = "hqm" " help, Quickfix, non-modifiable
- " NERDTree options
- " Auto change the root directory
- let NERDTreeChDirMode=2
- let g:NERDTreeWinSize = 23
- " Tagbar options
- let g:tagbar_width = 30
- let g:DoxygenToolkit_blockHeader="--------------------------------------------------------------------------"
- let g:DoxygenToolkit_blockFooter="--------------------------------------------------------------------------"
- let g:DoxygenToolkit_authorName="zengming@jyxtec.com"
- let g:DoxygenToolkit_versionString="0.1.00"
- let g:DoxygenToolkit_briefTag_funcName="yes"
- autocmd BufNewFile *.{h,hpp,c,cpp} DoxAuthor
- " Switching between buffers.
- nnoremap
h - nnoremap
j - nnoremap
k - nnoremap
l - inoremap
h - inoremap
j - inoremap
k - inoremap
l - " Set Up and Down non-linewise
- noremap
gk - noremap
gj - " use Meta key(Windows:Alt) to move cursor in insert mode.
- " Note: if system install "Lingoes Translator",
- " you will need change/disabled hot key.
- noremap!
- noremap!
- noremap!
- noremap!
- "/
: 把单个 单词放入搜索或者命令行 - " open ctags entries in a new tab
- nnoremap
T - set pastetoggle=
- nnoremap
:Grep - nnoremap
:Rgrep - nnoremap
:AutoPreviewToggle - inoremap
:AutoPreviewToggle i - " --lookupfile--
- " script to generate filenametags
- " #!/bin/sh
- " # generate tag file for lookupfile plugin, use absolute path
- " echo -e "!_TAG_FILE_SORTED\t2\t/2=foldcase/" > filenametags
- " find `pwd` -not -regex '.*\.\(png\|gif\)' -type f -printf "%f\t%p\t1\n" | \
- " sort -f >> filenametags
- "
- let g:LookupFile_MinPatLength = 2 "最少输入2个字符才开始查找
- let g:LookupFile_PreserveLastPattern = 0 "不保存上次查找的字符串
- "let g:LookupFile_PreservePatternHistory = 1 "保存查找历史
- let g:LookupFile_AlwaysAcceptFirst = 1 "回车打开第一个匹配项目
- let g:LookupFile_AllowNewFiles = 0 "不允许创建不存在的文件
- if filereadable("./filenametags") "设置tag文件的名字
- let g:LookupFile_TagExpr ='"./filenametags"'
- endif
- "ctrlp
- let g:ctrlp_user_command = 'find %s -type f'
- set tags=tags;
- " -- cscope --
- let g:autocscope_menus=0
- " Use quickfix window to show cscope results
- set cscopequickfix=s-,c-,d-,i-,t-,e-
- "'csto' 被设为 0,cscope 数据库先 被搜索,搜索失败的情况下在搜索标签文件
- "设定了 'cscopetag',这样所有的 :tag 命令就会实际上调用 :cstag。这包括 :tag、Ctrl-] 及 vim -t。
- "结果是一般的 tag 命令不仅搜索由 ctags 产生的标签文 件,同时也搜索 cscope 数据库,但是好像有bug,二者共存时有的无法搜索
- if has("cscope")
- set csprg=/usr/bin/cscope
- " Use both cscope and ctag
- set cscopetag
- " Show msg when cscope db added
- set cscopeverbose
- " Use cscope for definition search first
- set cscopetagorder=0
- endif
- 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与tag共存时ctrl+]有时不正常的bug
- nmap
:tj =expand(" ") - " Disable AutoComplPop.
- 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_ignore_case = 0
- " 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*'
- " Recommended key-mappings.
- "
: close popup and save indent. - inoremap
neocomplcache#smart_close_popup() . "\ " - "
: completion. - "inoremap
pumvisible() ? "\ " : "\ " - "
, : close popup and delete backword char. - inoremap
neocomplcache#smart_close_popup()."\ " - inoremap
neocomplcache#smart_close_popup()."\ " - inoremap
neocomplcache#close_popup() - inoremap
neocomplcache#cancel_popup() - " use neocomplcache & clang_complete
- " neocomplcache option
- "let g:neocomplcache_force_overwrite_completefunc=1
- " clang_complete option
- "let g:clang_complete_auto=1
- "Fast remove highlight search
- nmap
:noh - " 每行超过80个的字符用下划线标示
- au BufRead,BufNewFile *.asm,*.c,*.cpp,*.java,*.cs,*.sh,*.lua,*.pl,*.pm,*.py,*.rb,*.hs,*.vim 2match Underlined /.\%81v/
- " 超过80个的字符高亮
- "au BufWinEnter * let w:m1=matchadd('Search', '\%<88v.\%>81v', -1)
- "au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
- "高亮显示txt 需要txt.vim
- au BufRead,BufNewFile * setfiletype txt
- " Restore the last quit position when open file.
- autocmd BufReadPost *
- \ if line("'\"") > 0 && line("'\"") <= line("$") |
- \ exe "normal g'\"" |
- \ endif
- " 自动更新最后修改时间
- function! AutoUpdateTheLastUpdateInfo()
- let s:original_pos = getpos(".")
- let s:regexp = "^\\s*\\([#\\\"\\*]\\|\\/\\/\\)\\s\\?[lL]ast \\([uU]pdate\\|[cC]hange\\):"
- let s:lu = search(s:regexp)
- if s:lu != 0
- let s:update_str = matchstr(getline(s:lu), s:regexp)
- call setline(s:lu, s:update_str . strftime("%Y-%m-%d %H:%M:%S", localtime()))
- call setpos(".", s:original_pos)
- endif
- endfunction
- autocmd BufWritePost *.{h,hpp,c,cpp} call AutoUpdateTheLastUpdateInfo()
- autocmd BufNewFile *.{h,hpp,c,cpp} exec 'call append(0, "\/\/ Last Update:" . strftime("%Y-%m-%d %H:%M:%S", localtime()))'
- function! ToggleNERDTreeAndTagbar()
- let w:jumpbacktohere = 1
- " Detect which plugins are open
- if exists('t:NERDTreeBufName')
- let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
- else
- let nerdtree_open = 0
- endif
- let tagbar_open = bufwinnr('__Tagbar__') != -1
- " Perform the appropriate action
- if nerdtree_open && tagbar_open
- NERDTreeClose
- TagbarClose
- elseif nerdtree_open
- TagbarOpen
- elseif tagbar_open
- NERDTree
- else
- NERDTree
- TagbarOpen
- endif
- " Jump back to the original window
- for window in range(1, winnr('$'))
- execute window . 'wincmd w'
- if exists('w:jumpbacktohere')
- unlet w:jumpbacktohere
- break
- endif
- endfor
- endfunction
- nmap
:call ToggleNERDTreeAndTagbar()
已经放到github上了,最新的可到git上查看
希望能给大家做一个参考。插件用bundle (也有人叫vundle)管理的,推荐大家使用bundle,插件安装升级很方便
只要一个vimrc
先安装bundle
git clone ~/.vim/bundle/vundle
然后可下载我的.vimrc替换你的.vimrc 步骤如下:
git clone
下载后用myvim/myvimrc替换你的.vimrc (可自行修改其内容)
然后在vim中执行
:BundleInstall 就可以自动地安装插件
:BundleInstall! 则是自动更新插件,不用再手动去网上一个个下最新包了。
缷载插件 :BundleClean
推一些插件吧
功能 插件
在.c/.cpp 与.h间快速切换. a.vim
变量或者函数跳转. ctags cscope
输入时提示 neocomplcache
打开某文件时自动插入数据 headerGatesAdd.vim 新建.h文件时自行插入防头重复包含的代码 自个写着玩
注释与取消注释快速切换. The-NERD-Commenter
doxygen风格快速注释 DoxygenToolkit.vim
高亮 丰富的配色方案 配对符()[]"" ''等不匹配时会高亮提示
查找 变量 文件 /xxvar lookupfile ctrlp.vim
查看函数原型 autopreview echofunc.vim
显示最近打开过的文件 mru.vim
丰富的状态栏 vim-powerline
列出当前文件中的所有宏,全局变量, 函数名等 TagList 不过本人更喜欢tagbar
记录增删 就算退出编辑器, 还能还原已经修改过的文件, 方便得复制还原 YankRing.vim
%在配符对如()[]""等间跳转 matchit.vim
写标签语言的利器 surround.vim
其他的插件像玩游戏,画表格等不再一一描述
表述可能有些不清, 如需更多资料可上vim官网查阅
最后上个部分效果图: