码迷,mamicode.com
首页 > 系统相关 > 详细

vim配置

时间:2019-08-22 13:09:05      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:fileread   文件中   高亮   Fix   help   backup   stroke   set   显示   

自用的vim配置信息

syntax on  
syntax enable
"" 设置历史记录条数  
set history=2000  

"" create undo file
set undolevels=1000 "" how many undos
set undoreload=10000 "" number of lines to save for undo
if v:version >= 730
    set undofile     "" keep a persistent backup file
    set undodir=/tmp/vimundo/
endif

""set wildignore=*.swp,*.bak,*.pyc,*.class,.svn

"" 显示当前横竖线  
set cursorline  
set cursorcolumn  

"" 设置退出Vim之后内容显示在终端屏幕,可以用于查看和复制
"" 好处:误删什么,如果以前屏幕打开可以用来找回
set t_ti= t_te=

"" 设置在Vim中可以使用鼠标,防止终端无法拷贝  
set mouse=a  

""==========================================
"" Display Settings
""==========================================
""
"" 显示当前行号和列号
set ruler

"" 在状态栏显示正在输入的命令
set showcmd

"" 左下角显示当前Vim模式
set showmode

"" 光标移动至少保留的行数
""set scrolloff=7

"" 总是显示状态栏 Powerline需要2行  
set laststatus=2  

" 高亮显示普通txt文件(需要txt.vim脚本)
au BufRead,BufNewFile *  setfiletype txt

"" 显示行号  
set number  

"" 指定不折行
set nowrap  

"" 设置代码匹配,包括括号匹配情况  
set showmatch  

"" how many tenths of a second to blink when matching brackets
"" setmatchtime=2

"" 开启及时搜索  
set incsearch  

"" 设置搜索高亮  
set hls  

"" 设置搜索时忽略大小写  
set ignorecase  

"" 当搜索的时候尝试smart  
set smartcase  

"" 设置代码折叠
""set foldenable
"" 折叠方法
"" manual 手工折叠
"" indent 缩进折叠
"" expr 表达式折叠
"" syntax 语法折叠
"" diff 对没有更改的文件折叠
"" marker 标记折叠
""set foldmethod=indent
""set foldlevel=99

"" 设置C/C++方式自动对齐  
set autoindent  
set cindent  
set smartindent  

"" 设置tab宽度  
set tabstop=4

"" 设置自动对齐空格数  
set shiftwidth=4  

"" 按退格键时可以一次删除4个空格
""set softtabstop=4

 "" 编辑的时候将所有的tab设置为空格  
""" set et  

set noexpandtab

 "" 使用Backspace直接删除tab  
 set smarttab  

"" 不在单词中间折行  
set lbr  
 ""==========================================
 "" FileEncode Settings
 ""==========================================

 "" 设置编码方式  
 set encoding=utf-8  

 "" 设置打开文件的编码格式  
 set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1  

 set helplang=cn 

 "" 只对终端影响
 set termencoding=utf-8

 "" use UNIX as the standard file type
 set ffs=unix,dos,mac

"" 如遇Unicode值大于255的文本,不必等到空格再折行。
set formatoptions+=m

"" 合并两行中文时,不在中间加空格:
set formatoptions+=B

""==========================================
"" Other Settings
""==========================================
 "" 自动补全配置让Vim补全菜单行为跟IDE一致
 set completeopt=longest,menu

 "" 增强模式中的命令行自动完成操作
 set wildmenu

 "" ignore compiled files
 "" set wildignore=*.o,*~,*.pyc,*.class

""离开插入模式后自动关闭预览窗口
"autocmd InsertLeave * if pumvisible == 0|pclose|endif
map <leader>/ :nohls<CR>
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove

"" Opens a new tab with the current buffer's path
"" Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand<cr>/

"" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>

"" 手动刷新tags
nmap tg :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q *<CR>:set tags+=./tags<CR>:!cscope -Rbq<CR>:cs add ./cscope.out .<CR>

"" 切换buffer
nnoremap [b :bp<CR>
nnoremap ]b :bn<CR>

""map <F4>:!cscope -Rbq<CR>:cs add ./cscope.out .<CR><CR><CR> :cs reset<CR>
"" 查找符号
nmap <leader>css :cs find s <C-R>=expand<CR><CR> :copen<CR><CR>
"" 查找定义
nmap <leader>csg :cs find g <C-R>=expand<CR><CR>
"" 查找被这个函数调用的函数
nmap <leader>csd :cs find d <C-R>=expand<CR><CR> :copen<CR><CR>
"" 查找调用这个函数的函数
nmap <leader>csc :cs find c <C-R>=expand<CR><CR>:copen<CR><CR>
"" 查找这个字符串
nmap <leader>cst :cs find t <C-R>=expand<CR><CR>:copen<CR><CR>
"" 查找这个egrep匹配模式
nmap <leader>cse :cs find e <C-R>=expand<CR><CR>:copen<CR><CR>
"" 查找这个文件
nmap <leader>csf :cs find f <C-R>=expand<CR><CR>
"" 查找include这个文件的文件
nmap <leader>csi :cs find i <C-R>=expand<CR><CR> :copen<CR><CR>

"" 设定是否使用QuickFix来显示结果
set cscopequickfix=s-,c-,d-,i-,t-,e-

"" QuickFix open and close
nnoremap <F11> :copen<CR>
nnoremap <F12> :cclose<CR>

"" QucikFix next and prev
nnoremap <F9> :cn<CR>
nnoremap <F10> :cp<CR>

""==========================================
"" Theme Settings
""==========================================

"" Set extra options when running in GUI mode
""if has
""    set guifont=Monaco\ 12
""    set guioptions-=T
""    set guioptions+=e
""    set guioptions-=r
""    set guioptions-=L
""    set guitablabel=%M\ %t
""    set showtabline=1 
""    set linespace=2 
""    set noimd   
""    set t_Co=256
""endif

"" 设置主题  
set background=dark

"" 添加水平滚动条  
""set guioptions+=b  

"" 取消菜单栏和导航栏  
set guioptions-=m  
set guioptions-=T  

"" 去除左右两边滚动条
set go-=r
set go-=L

"" 设置水平行数和竖直列数  
"" set lines=35  
"" set columns=99  

"" vim-scripts repos  
"" non-GitHub repos  
"" Git repos on your local machine   

""==========================================
"" ctrlp settings  
""==========================================
""let g:ctrlp_map = '<leader>p'
""let g:ctrlp_cmd = 'CtrlP'
""map <leader>f :CtrlPMRU<CR>
""set wildignore+=*/tmp/*,*.so,*.swp,*.zip     "" MacOSX/Linux
""let g:ctrlp_custom_ignore = {
""    \ 'dir':  '\v[\/]\.$',
""    \ 'file': '\v\.$',
""    \ 'link': 'SOME_BAD_SYMBOLIC_LINKS',
""    \ }
let g:ctrlp_custom_ignore = {
   \ 'file': '\v\.'
    \ }
"" 在每次进行切换分支或者重新设定custome_ignore选项的时候,必须手动清除CtrlP的缓存,
"" 也可以使用下句不让它进行缓存处理,但扫描时间会比较耗时
""let g:ctrlp_use_caching = 0
let g:ctrlp_working_path_mode=0
let g:ctrlp_match_window_bottom=1
let g:ctrlp_max_height=15
let g:ctrlp_match_window_reversed=0
let g:ctrlp_mruf_max=500
let g:ctrlp_follow_symlinks=1
nnoremap <leader>b :CtrlPBuffer<CR>
nnoremap <leader>d :CtrlPDir<CR>

""==============================================================
"" ctrlp-funky settings  ctrlp插件 - 不用ctag进行函数快速跳转
""==============================================================
""nnoremap <Leader>fu :CtrlPFunky<Cr>
nnoremap <Leader>f :CtrlPFunky<Cr>
"" narrow the list down with a word under cursor
""nnoremap <Leader>fU :execute 'CtrlPFunky ' . expand<Cr>
let g:ctrlp_funky_syntax_highlight = 1
let g:ctrlp_extensions = ['funky']

""==========================================
"" nerdcommenter settings  快速注释
""==========================================
"" 注释与代码之间留存的空格数
let g:NERDSpaceDelims = 1

""==========================================
"" Airline settings
""==========================================
""if !exists
""let g:airline_symbols = {}
""endif
""let g:airline_left_sep = '?'
""let g:airline_left_alt_sep = '?'
""let g:airline_right_sep = '?'
""let g:airline_right_alt_sep = '?'
""let g:airline_symbols.linenr = '?'
""let g:airline_symbols.branch = '?'
"""" 开启tabline
""let g:airline#extensions#tabline#enabled = 1
"""" tabline中当前buffer两端的分隔符
""let g:airline#extensions#tabline#left_sep = ' '
"""" tabline为激活的buffer的两端字符
""let g:airline#extensions#tabline#left_alt_sep = '|'
"""" tabline中buffer显示编号
""let g:airline#extensions#tabline#buffer_nr_show = 1
""let g:airline#extensions#buffline#enabled = 1
""let g:airline#extensions#bufferline#overwrite_variables = 1
"""" airline主题
""let g:airline_theme = 'powerlineish' 

""括号显示增强
""let g:rbpt_colorpairs = [
""    \ ['brown',       'RoyalBlue3'],
""    \ ['Darkblue',    'SeaGreen3'],
""    \ ['darkgray',    'DarkOrchid3'],
""    \ ['darkgreen',   'firebrick3'],
""    \ ['darkcyan',    'RoyalBlue3'],
""    \ ['darkred',     'SeaGreen3'],
""    \ ['darkmagenta', 'DarkOrchid3'],
""    \ ['brown',       'firebrick3'],
""    \ ['gray',        'RoyalBlue3'],
""    \ ['black',       'SeaGreen3'],
""    \ ['darkmagenta', 'DarkOrchid3'],
""    \ ['Darkblue',    'firebrick3'],
""    \ ['darkgreen',   'RoyalBlue3'],
""    \ ['darkcyan',    'SeaGreen3'],
""    \ ['darkred',     'DarkOrchid3'],
""    \ ['red',         'firebrick3'],
""    \ ]
""let g:rbpt_max = 40
""let g:rbpt_loadcmd_toggle = 0
""au VimEnter * RainbowParenthesesToggle
""au Syntax * RainbowParenthesesLoadRound
""au Syntax * RainbowParenthesesLoadSquare
""au Syntax * RainbowParenthesesLoadBraces

""let g:solarized_termcolors=256
let g:solarized_termtrans=1

"" increase the width of the taglist window  
""let Tlist_WinWidth=20  
"" 自动打开TagList的window  
let Tlist_Auto_Open=0  
"" 当只剩下Tlist的时候自动关闭  
let Tlist_Exit_OnlyWindow=1  
"" 打开tags用单击  
let Tlist_Use_SingleClick=1  
"" close tag folders for inactive buffers  
let Tlist_File_Fold_Auto_Close=1  
"" show the fold indiactor column in the taglist window  
let Tlist_Enable_Fold_Column=1  
"" 自动更新TagList包含最新编辑的文件  
let Tlist_Auto_Update=1  
"" 显示一个文件的tag  
let Tlist_Show_One_File=1  
"" 在右侧显示窗口  
let Tlist_Use_Right_Window=1  
"" 让TagList始终解释文件中的tag,不管TagList窗口有没有打开  
let Tlist_Process_File_Always=1  
"" 将taglist与ctags关联
let Tlist_Ctags_Cmd="/usr/bin/ctags"
"" 设置leader键  
""" nnoremap <leader>tl :TlistToggle<CR>  
nnoremap <silent><F4> :TlistToggle<CR>

""let g:ycm_key_list_select_completion=['<c-n>']
""let g:ycm_key_list_previous_completion=['<c-p>']
let g:ycm_collect_indentifiers_from_tags_files=1  
let g:ycm_seed_identifiers_with_syntax=1  
"" 避免YCM每次加载都对用户提示是否加载  
let g:ycm_confirm_extra_conf=0  
let g:ycm_autoclose_preview_window_after_completion=1  

"" 设置NerdTree
map <F3> :NERDTreeMirror<CR>
map <F3> :NERDTreeToggle<CR>

" This tests to see if vim was configured with the '--enable-cscope' option
" when it was compiled.  If it wasn't, time to recompile vim...
if has("cscope")
    """"""""""""" Standard cscope/vim boilerplate

    " use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
    set cscopetag

    " check cscope for definition of a symbol before checking ctags: set to 1
    " if you want the reverse search order.
    set csto=0

    " add any cscope database in current directory
    if filereadable("cscope.out")
        cs add cscope.out
    " else add the database pointed to by environment variable
    elseif $CSCOPE_DB != ""
        cs add $CSCOPE_DB
    endif

    " show msg when any other cscope db added
    set cscopeverbose


    """"""""""""" My cscope/vim key mappings
    "
    " The following maps all invoke one of the following cscope search types:
    "
    "   's'   symbol: find all references to the token under cursor
    "   'g'   global: find global definition(s) of the token under cursor
    "   'c'   calls:  find all calls to the function name under cursor
    "   't'   text:   find all instances of the text under cursor
    "   'e'   egrep:  egrep search for the word under cursor
    "   'f'   file:   open the filename under cursor
    "   'i'   includes: find files that include the filename under cursor
    "   'd'   called: find functions that function under cursor calls
    "
    " Below are three sets of the maps: one set that just jumps to your
    " search result, one that splits the existing vim window horizontally and
    " diplays your search result in the new window, and one that does the same
    " thing, but does a vertical split instead (vim 6 only).
    "
    " I've used CTRL-\ and CTRL-@ as the starting keys for these maps, as it's
    " unlikely that you need their default mappings (CTRL-\'s default use is
    " as part of CTRL-\ CTRL-N typemap, which basically just does the same
    " thing as hitting 'escape': CTRL-@ doesn't seem to have any default use).
    " If you don't like using 'CTRL-@' or CTRL-\, , you can change some or all
    " of these maps to use other keys.  One likely candidate is 'CTRL-_'
    " (which also maps to CTRL-/, which is easier to type).  By default it is
    " used to switch between Hebrew and English keyboard mode.
    "
    " All of the maps involving the <cfile> macro use '^<cfile>$': this is so
    " that searches over '#include <time.h>" return only references to
    " 'time.h', and not 'sys/time.h', etc. (by default cscope will return all
    " files that contain 'time.h' as part of their name).


    " To do the first type of search, hit 'CTRL-\', followed by one of the
    " cscope search types above (s,g,c,t,e,f,i,d).  The result of your cscope
    " search will be displayed in the current window.  You can use CTRL-T to
    " go back to where you were before the search.
    "

    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 <F6>   :cs find g <C-R>=expand("<cword>")<CR><CR>
    " imap <F6> <ESC>:cs find g <C-R>=expand("<cword>")<CR><CR>i
    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 <F9>   :cs find t <C-R>=expand("<cword>")<CR><CR>
    " imap <F9> <ESC>:cs find t <C-R>=expand("<cword>")<CR><CR>i
    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>


    " Using 'CTRL-spacebar' (intepreted as CTRL-@ by vim) then a search type
    " makes the vim window split horizontally, with search result displayed in
    " the new window.
    "
    " (Note: earlier versions of vim may not have the :scs command, but it
    " can be simulated roughly via:
    "    nmap <C-@>s <C-W><C-S> :cs find s <C-R>=expand("<cword>")<CR><CR>

    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>


    " Hitting CTRL-space *twice* before the search type does a vertical
    " split instead of a horizontal one (vim 6 and up only)
    "
    " (Note: you may wish to put a 'set splitright' in your .vimrc
    " if you prefer the new window on the right instead of the left

    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>


    """"""""""""" key map timeouts
    "
    " By default Vim will only wait 1 second for each keystroke in a mapping.
    " You may find that too short with the above typemaps.  If so, you should
    " either turn off mapping timeouts via 'notimeout'.
    "
    "set notimeout
    "
    " Or, you can keep timeouts, by uncommenting the timeoutlen line below,
    " with your own personal favorite value (in milliseconds):
    "
    "set timeoutlen=4000
    "
    " Either way, since mapping timeout settings by default also set the
    " timeouts for multicharacter 'keys codes' (like <F1>), you should also
    " set ttimeout and ttimeoutlen: otherwise, you will experience strange
    " delays as vim waits for a keystroke after you hit ESC (it will be
    " waiting to see if the ESC is actually part of a key code like <F1>).
    "
    "set ttimeout
    "
    " personally, I find a tenth of a second to work well for key code
    " timeouts. If you experience problems and have a slow terminal or network
    " connection, set it higher.  If you don't set ttimeoutlen, the value for
    " timeoutlent (default: 1000 = 1 second, which is sluggish) is used.
    "
    "set ttimeoutlen=100

endif

vim配置

标签:fileread   文件中   高亮   Fix   help   backup   stroke   set   显示   

原文地址:https://www.cnblogs.com/jinliang-li/p/11393373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!