vimrc配置

本文详细介绍了Vim编辑器的高级配置技巧,包括cscope和gtags的集成,不同文件类型的智能补全与语法高亮,以及一系列提高工作效率的快捷键设置。此外,还深入探讨了如何管理和优化Vim插件,如NERDTree、Tlist和Syntastic,以实现更高效、个性化的编程体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

set modifiable

"set cscopequickfix=s-,c-,d-,i-,t-,e-
"cscope 用法
"cscope -Rbq: 生成cscope.out文件
":cs add /path/to/cscope.out /your/work/dire

" cscope setting
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("cscope")
    set csprg=/usr/bin/cscope
    set csto=0
    set cst
    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
endif

"--------------cscope 快捷键设置---------------------------
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-@>d :cs find d <C-R>=expand("<cword>")<CR><CR>

"F5 查找c符号; F6 查找字符串;   F7 查找函数定义; F8 查找函数谁调用了,
"nmap <silent> <F5> :cs find s <C-R>=expand("<cword>")<CR><CR> :botright copen<CR><CR>
"nmap <silent> <F6> :cs find t <C-R>=expand("<cword>")<CR><CR> :botright copen<CR><CR>
"nmap <silent> <F7> :cs find g <C-R>=expand("<cword>")<CR><CR>
"nmap <silent> <F7> :cs find c <C-R>=expand("<cword>")<CR><CR> :botright copen<CR><CR>


 "--------------------------空格和tab默认显示设置------------------------------------------------------
"set expandtab        " TAB替换为空格:
"set sw=4
"set lbr
"set softtabstop=4    " 统一缩进为4
"set shiftwidth=4
set tabstop=8           " tab显示为8空格
"set smarttab        " 在行和段开始处使用制表符
set autoindent        " 自动缩进

set noexpandtab
set softtabstop=8
set shiftwidth=8
%retab!

"set list listchars=tab:>-  " 显示tab

"内核代码缩进方式 F6
:nmap <silent> <F6> <ESC>:set softtabstop=8<CR>:set shiftwidth=8<CR>:set noexpandtab<RETURN>
"其它代码缩进方式 F7
:nmap <silent> <F7> <ESC>:set softtabstop=4<CR>:set shiftwidth=4<CR>:set expandtab<RETURN>
"------------------------------------------------------------------------------------------------------

set cscopetag " 使用 cscope 作为 tags 命令
set cscopeprg='gtags-cscope' " 使用 gtags-cscope 代替 cscope


"gtags.vim 设置项
let GtagsCscope_Auto_Load = 1
let CtagsCscope_Auto_Map = 1
let GtagsCscope_Quiet = 1

nmap <silent> <F8> :Gtags -r <C-R>=expand("<cword>")<CR><CR> :botright copen<CR><CR>
"------------------------------------------------------------------------------------------------------
set et
set smartindent
set fo+=mB
set sm
set selection=inclusive
set wildmenu
set mousemodel=popup

au FileType php setlocal dict+=~/.vim/dict/php_funclist.dict
au FileType css setlocal dict+=~/.vim/dict/css.dict
au FileType c setlocal dict+=~/.vim/dict/c.dict
au FileType cpp setlocal dict+=~/.vim/dict/cpp.dict
au FileType scale setlocal dict+=~/.vim/dict/scale.dict
au FileType javascript setlocal dict+=~/.vim/dict/javascript.dict
au FileType html setlocal dict+=~/.vim/dict/javascript.dict
au FileType html setlocal dict+=~/.vim/dict/css.dict

"
"syntastic相关
execute pathogen#infect()
let g:syntastic_python_checkers=['pylint']
let g:syntastic_php_checkers=['php', 'phpcs', 'phpmd']
"golang
"Processing... % (ctrl+c to stop)
let g:fencview_autodetect=0
set rtp+=$GOROOT/misc/vim


"--------------------------------------- 显示----------------------------------------------------------
syntax on
"set cursorcolumn    " 高亮光标所在列
set cursorline        " 高亮光标所在行
set shortmess=atI    " 启动的时候不显示那个援助乌干达儿童的提示
set go=                 " 不要图形按钮
"color desert           " 设置背景主题
color ron               " 设置背景主题
"set guifont=Courier_New:h10:cANSI    " 设置字体
"autocmd InsertLeave * se nocul         " 取消用浅色高亮当前行
autocmd InsertEnter * se cul            " 用浅色高亮当前行
"set ruler                              " 显示标尺
set showcmd                             " 输入的命令显示出来,看的清楚些
set scrolloff=3                         " 光标移动到buffer的顶部和底部时保持3行距离
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}   "状态行显示的内容
set laststatus=2    " 启动显示状态行(1),总是显示状态行(2)
"set foldenable         " 允许折叠
"set foldmethod=manual  " 手动折叠
set nocompatible    " 去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限

if version >= 603    " 显示中文帮助
    set helplang=cn
    set encoding=utf-8
endif

set number    " 显示行号
set history=100    " 历史记录数
set hlsearch    " 搜索逐字符高亮
set incsearch

set langmenu=zh_CN.UTF-8    "语言设置
set helplang=cn

set cmdheight=2            " 总是显示状态行
filetype on            " 侦测文件类型
filetype plugin on        " 载入文件类型插件
filetype indent on        " 为特定文件类型载入相关缩进文件
set viminfo+=!            " 保存全局变量
set iskeyword+=_,$,@,%,#,-    " 带有如下符号的单词不要被换行分割

 

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTags的设定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let Tlist_Sort_Type = "name"            " 按照名称排序
let Tlist_Use_Right_Window = 1          " 在右侧显示窗口
"let Tlist_Compart_Format = 1           " 压缩方式
let Tlist_Exist_OnlyWindow = 1          " 如果只有一个buffer,kill窗口也kill掉buffer
"let Tlist_File_Fold_Auto_Close = 0    " 不要关闭其他文件的tags
"let Tlist_Enable_Fold_Column = 0    " 不要显示折叠树
"let Tlist_Show_One_File=1              " 不同时显示多个文件的tag,只显示当前文件的


let Tlist_Auto_Open=0            " 默认打开Taglist
let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'
let Tlist_Show_One_File = 1        " 不同时显示多个文件的tag,只显示当前文件的
let Tlist_File_Fold_Auto_Close = 1
let Tlist_Exit_OnlyWindow = 1        " 如果taglist窗口是最后一个窗口,则退出vim
let Tlist_Use_Right_Window = 1        " 在右侧窗口中显示taglist窗口
let Tlist_WinWidth = 40            " 设置taglist的宽度


"markdown配置
au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}   set filetype=mkd
au BufRead,BufNewFile *.{go}   set filetype=go
au BufRead,BufNewFile *.{js}   set filetype=javascript
"rkdown to HTML
nmap md :!~/.vim/markdown.pl % > %.html <CR><CR>
nmap fi :!firefox %.html & <CR><CR>
nmap \ \cc
vmap \ \cc


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"键盘命令/已删除————具体请查看完整版vimrc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
:nmap <silent> <F9> <ESC>:Tlist<RETURN>


" 选中状态下 Ctrl+c 复制
"map <C-v> "*pa
imap <C-v> <Esc>"*pa
imap <C-a> <Esc>^
imap <C-e> <Esc>$
vmap <C-c> "+y

"set mouse=v
set clipboard=unnamed

"列出当前目录文件
map <F3> :NERDTreeToggle<CR>
imap <F3> <ESC> :NERDTreeToggle<CR>
"打开树状文件目录
map <C-F3> \be

""实用设置
if has("autocmd")
      autocmd BufReadPost *
          \ if line("'\"") > 0 && line("'\"") <= line("$") |
          \   exe "normal g`\"" |
          \ endif
endif

autocmd vimenter * if !argc() | NERDTree | endif        "当打开vim且没有文件时自动打开NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif    " 只剩 NERDTree时自动关闭
set autoread        " 设置当文件被改动时自动载入
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>        " quickfix模式

set completeopt=preview,menu    " 代码补全
"filetype plugin on        " 允许插件
"set clipboard+=unnamed         " 共享剪贴板
set autowrite            " 自动保存
"set ruler                      " 打开状态栏标尺
set cursorline                  " 突出显示当前行
set magic                       " 设置魔术
set guioptions-=T               " 隐藏工具栏
set guioptions-=m               " 隐藏菜单栏
""set foldcolumn=0
""set foldmethod=indent
""set foldlevel=3

set noeb            " 去掉输入错误的提示声音
set confirm            " 在处理未保存或只读文件的时候,弹出确认
set nobackup
set noswapfile            " 禁止生成临时文件
set ignorecase            " 搜索忽略大小写

set linespace=0
" 增强模式中的命令行自动完成操作
set wildmenu
" 使回格键(backspace)正常处理indent, eol, start等
set backspace=2
" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l

set mouse=a            " 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set selection=exclusive
set selectmode=mouse,key
set report=0            " 通过使用: commands命令,告诉我们文件的哪一行被改变过
set fillchars=vert:\ ,stl:\ ,stlnc:\        " 在被分割的窗口间显示空白,便于阅读
set showmatch            " 高亮显示匹配的括号
set matchtime=100        " 匹配括号高亮的时间(单位是十分之一秒)
set scrolloff=3            " 光标移动到buffer的顶部和底部时保持3行距离


"新文件标题  新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
    "如果文件类型为.sh文件
    if &filetype == 'sh'
        call setline(1,"\#!/bin/bash")
        call append(line("."), "")
    elseif &filetype == 'python'
        call setline(1,"#!/usr/bin/env python")
        call append(line("."),"# coding=utf-8")
        call append(line(".")+1, "")

    elseif &filetype == 'ruby'
        call setline(1,"#!/usr/bin/env ruby")
        call append(line("."),"# encoding: utf-8")
        call append(line(".")+1, "")

"    elseif &filetype == 'mkd'
"        call setline(1,"<head><meta charset=\"UTF-8\"></head>")
    else
        call setline(1, "/*************************************************************************")
        call append(line("."), "    > File Name: ".expand("%"))
        call append(line(".")+1, "    > Author: wws")
        call append(line(".")+2, "    > Mail: wangws0709@thundersoft.com")
        call append(line(".")+3, "    > Created Time: ".strftime("%c"))
        call append(line(".")+4, " ************************************************************************/")
        call append(line(".")+5, "")
    endif
    if expand("%:e") == 'cpp'
        call append(line(".")+6, "#include<iostream>")
        call append(line(".")+7, "using namespace std;")
        call append(line(".")+8, "")
    endif
    if &filetype == 'c'
        call append(line(".")+6, "#include<stdio.h>")
        call append(line(".")+7, "")
    endif
    if expand("%:e") == 'h'
        call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H")
        call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H")
        call append(line(".")+8, "#endif")
    endif
    if &filetype == 'java'
        call append(line(".")+6,"public class ".expand("%:r"))
        call append(line(".")+7,"")
    endif
    "新建文件后,自动定位到文件末尾
endfunc
autocmd BufNewFile * normal G


" 为C程序提供自动缩进
"自动补全
"":inoremap ( ()<ESC>i
"":inoremap ) <c-r>=ClosePair(')')<CR>
":inoremap { {<CR>}<ESC>O
":inoremap } <c-r>=ClosePair('}')<CR>
"":inoremap [ []<ESC>i
"":inoremap ] <c-r>=ClosePair(']')<CR>
"":inoremap " ""<ESC>i
"":inoremap ' ''<ESC>i
""function! ClosePair(char)
""    if getline('.')[col('.') - 1] == a:char
""        return "\<Right>"
""    else
""        return a:char
""    endif
""endfunction
filetype plugin indent on
"打开文件类型检测, 加了这句才可以用智能补全
set completeopt=longest,menu


"python补全
let g:pydiction_location = '~/.vim/after/complete-dict'
let g:pydiction_menu_height = 20
let Tlist_Ctags_Cmd='/usr/local/bin/ctags'
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1


set iskeyword+=.
set termencoding=utf-8
set encoding=utf8
set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030

autocmd FileType python set omnifunc=pythoncomplete#Complete


"filetype off                   " required!

set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'

" My Bundles here:
"
" original repos on github
Bundle 'tpope/vim-fugitive'
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'Yggdroot/indentLine'
let g:indentLine_char = '┊'
"显示对齐虚线
let g:indentLine_enabled = 1
"ndle 'tpope/vim-rails.git'
" vim-scripts repos
Bundle 'L9'
Bundle 'FuzzyFinder'
" non github repos
Bundle 'https://github.com/wincent/command-t.git'
Bundle 'Auto-Pairs'
Bundle 'python-imports.vim'
Bundle 'CaptureClipboard'
Bundle 'ctrlp-modified.vim'
Bundle 'last_edit_marker.vim'
Bundle 'synmark.vim'
"Bundle 'Python-mode-klen'
Bundle 'SQLComplete.vim'
Bundle 'Javascript-OmniCompletion-with-YUI-and-j'
"Bundle 'JavaScript-Indent'
"Bundle 'Better-Javascript-Indentation'
Bundle 'jslint.vim'
Bundle "pangloss/vim-javascript"
Bundle 'Vim-Script-Updater'
Bundle 'ctrlp.vim'
Bundle 'tacahiroy/ctrlp-funky'
Bundle 'jsbeautify'
Bundle 'The-NERD-Commenter'
"django
Bundle 'django_templates.vim'
Bundle 'Django-Projects'

"Bundle 'FredKSchott/CoVim'
"Bundle 'djangojump'
" ...
let g:html_indent_inctags = "html,body,head,tbody"
let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"

filetype plugin indent on     " required!
"
"ctrlp设置
"
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.png,*.jpg,*.gif     " MacOSX/Linux
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe,*.pyc,*.png,*.jpg,*.gif  " Windows

let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_custom_ignore = '\v\.(exe|so|dll)$'
let g:ctrlp_extensions = ['funky']

let NERDTreeIgnore=['\.pyc']

set nocscopeverbose

set tags=tags;
set autochdir


""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" plantuml
:nmap <silent> <F10> <ESC>:!plantuml %<CR>:!eog %<RETURN>

colorscheme molokai

"高亮显示多余的空格和tab
highlight ExtraWhitespace ctermbg=red guibg=red
autocmd BufWinEnter * match ExtraWhitespace /\s\+$\| \+\ze\t\+\|\t\+\zs \+/

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值