当前位置: 首页 > 工具软件 > VimR > 使用案例 >

vimr配置

郑宏朗
2023-12-01
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

set nocompatible       "去掉vi一致性模式

set   autoread         "文件被改动时自动载入

syntax enable           "设置语法高亮
syntax on

set hlsearch           "高亮显示结果

set incsearch           "在输入要搜索的文字时,vim会实时匹配

set backspace=indent,eol,start whichwrap+=<,>,[,]      "允许退格键的使用colorscheme elflord

colorscheme   peachpuff      "tango"desert        "设置配色方案

set   wrap                    "设置允许自动换行
set   whichwrap=b,s,<,>,[,]
"set   slidescroll=10             "设置光标的自动滚动

set   linebreak               "设置整词换行

set    history=1000           "设置历史

set helplang=cn                 "语言设置
set encoding=utf8
set langmenu=zh_CN.UTF-8
set imcmdline
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim

set guifont=Liberation\Mono\ 12     " 设置字体

set   showmatch            "设置匹配模式,输入左括号会匹配右括号

set   mouse=a              "设置鼠标一直可用
set   selection=exclusive
set   selectmode=mouse,key

set   nocursorline           "不高亮当前行

highlight StatusLine guifg=SlateBlue guibg=yellow        "设置状态行颜色
highlight StatusLineNC guifg=Gray guibg=White
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}    " 我的状态行显示的内容(包括文件类型和解码)
"set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%]

set laststatus=2                                 " 总是显示状态行

set ruler                                        " 在编辑过程中,在右下角显示光标位置的状态行

set cmdheight=2            " 命令行(在状态行下)的高度,默认为1,这里是2

set   fillchars=vert:\ ,stl:\ ,stlnc:\      "在被分割的窗口显示空白,便于阅读

set report=0              "通过commands命令,告诉我们那一行被修改过

set    incsearch            "搜索时逐字高亮

set    ignorecase          "搜索时忽视大小写

filetype   on              "打开文件类型自动检测功能

set clipboard+=unnamed     "与windows共享剪贴板

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

set    tabstop=4           "制表符为

"behave  mswin              "使鼠标的使用符合windows的习惯,右键出现菜单,此时未开启

set softtabstop=4          "统一缩进为4
set shiftwidth=4
set formatoptions=tcrqn     "自动格式化
set smartindent             "为c语言提供自动缩进
set autoindent              "继承前一行的缩进模式

set viminfo+=!              "保存全局变量

set  nu                    "显示行数

if has("autocmd")            " 只在下列文件类型被侦测到的时候显示行号,普通文本文件不显示
autocmd FileType xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby set number
autocmd FileType xml,html vmap <C-o> <ESC>'<i<!--<ESC>o<ESC>'>o-->
autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o/*<ESC>'>o*/
autocmd FileType html,text,php,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100
autocmd Filetype html,xml,xsl source $VIMRUNTIME/plugin/closetag.vim
autocmd BufReadPost *
  \ if line("'\"") > 0 && line("'\"") <= line("$") |
  \   exe "normal g`\"" |
  \ endif
endif " has("autocmd")

if filereadable("/etc/vim/gvimrc.local")   "如果有global可以使用
  source /etc/vim/gvimrc.local
endif

set tags=tags;                         "设置当前目录
"set autochdir
"set tags=/home/acer/下载/ctags-5.8/tags;
"set tags=/home/acer/tags
set tags+=../tags                          "为/usr/include目录生成tags文件
let Tlist_Sort_Type = "name"               "按名称排序  
let Tlist_Ctags_Cmd = '/usr/bin/ctags'
let Tlist_Show_One_File = 1            "不同时显示多个文件的tag,只显示当前文件的
let Tlist_Exit_OnlyWindow = 1          "如果taglist窗口是最后一个窗口,则退出vim
let Tlist_Use_Right_Window = 1           "在左侧窗口显示taglist窗口
let Tlist_Enable_Fold_Column = 1        "不显示折叠树
let Tlist_Use_SingleClick=1             "单击时跳转
let Tlist_Process_File_Always=1         "不管taglist窗口是否打开,始终解析文件中的tag
let Tlist_GainFocus_On_ToggleOpen=1     "打开taglist时获得输入焦点
nmap tl :TlistToggle<cr>                "键盘映射

let g:winManagerWindowLayout='FileExplorer'
nmap wm :WMToggle<cr>
map <silent> <F8> :WMToggle<cr>                         "将F8绑定至WinManager,即打开WimManager

":cs find g vim_strsave

syn on                 "vim latex配置
filetype plugin on
filetype indent on
set shellslash
set grepprg=grep\ -nH\ $*
let g:tex_flavor = "latex"

"  OmniCppComplete 配置
set nocp " non vi compatible mode
filetype plugin on " enable plugins

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

set fenc=utf-8                      " 设定默认解码
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936

let g:fencview_autodetect = 1   "打开文件时自动识别编码
let g:fencview_checklines = 100 "检查前后100行来判断编
set fileencodings=ucs-bom,utf8,GB18030,Big5,latin1

if has("cscope")     "cscope配置
  set csprg=/usr/bin/cscope
  set csto=1
  set cst
  set nocsverb
  " add any database in current directory
  if filereadable("cscope.out")
      cs add cscope.out
  endif
  set csverb
endif

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>
 

let g:miniBufExplMapCTabSwitchBufs = 1             "设置minibufexpl插件
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplModSelTarget = 1


set encoding=utf-8                        "能够漂亮地显示.NFO文件
function! SetFileEncodings(encodings)
    let b:myfileencodingsbak=&fileencodings
    let &fileencodings=a:encodings
endfunction
function! RestoreFileEncodings()
    let &fileencodings=b:myfileencodingsbak
    unlet b:myfileencodingsbak
endfunction

nnoremap <silent> <F12> :A<CR>

nnoremap <silent> <F3> :Grep<CR>

map <F6> :make<CR>              "设置一键编译

"filetype plugin indent on                "自动补全
"set completeopt=longest,menu             "关掉加速补全时候的窗口

"let g:SuperTabRetainCompletionType=2      "加速补全
"let g:SuperTabDefaultCompletionType="<C-X><C-O>"

"{{{ plugin - mru.vim                   记录最近打开的文件
let MRU_File = $VIMFILES.'/_vim_mru_files'
let MRU_Max_Entries = 1000
let MRU_Add_Menu = 0
nmap <leader>f :MRU<CR>
" }}}

map <F5> :call CompileRunGcc()<CR>    " C的编译和运行, F5编译和运行C程序
func! CompileRunGcc()
exec "w"
exec "!gcc -Wall % -o %<"
exec "! ./%<"
endfunc

map <F6> :call CompileRunGpp()<CR>   " C++的编译和运行,F6编译和运行C++程序
func! CompileRunGpp()
exec "w"
exec "!g++ -Wall % -o %<"
exec "! ./%<"
endfunc

vmap <C-c> "yy   "模仿MS windows中的快捷键
vmap <C-x> "yd
nmap <C-v> "yp
vmap <C-v> "yp
nmap <C-a> ggvG$

let NERDshutUp=1

set shortmess=atI  "不显示援助索马里儿童信息

let g:calendar_diary="/home/acer/文档/dairy/"   "日历显示配置路径与快捷键
map ca :Calendar<cr>

if has("win32")                                 "vimwiki的配置
  let $VIMFILES = $VIM.'/vimfiles'
else
  let $VIMFILES = $HOME.'/.vim'             "对于vim配置文件的识别
endif
let g:vimwiki_use_mouse = 1
                                             " 多个维基项目的配置
let g:vimwiki_list = [{'path': 'E:/My Dropbox/vimwiki/',
      \ 'html_header': 'E:/My Dropbox/Public/vimwiki_template/header.htm',
      \ 'html_footer': 'E:/My Dropbox/Public/vimwiki_template/footer.htm',
      \ 'diary_link_count': 5},
      \{'path': 'Z:\demo\qiuchi\wiki'}]
" 对中文用户来说,我们并不怎么需要驼峰英文成为维基词条
let g:vimwiki_camel_case = 0
" 标记为完成的 checklist 项目会有特别的颜色
let g:vimwiki_hl_cb_checked = 1
" 是否开启按语法折叠  会让文件比较慢
"let g:vimwiki_folding = 1
" 是否在计算字串长度时用特别考虑中文字符
let g:vimwiki_CJK_length = 1
map <S-F4> :VimwikiAll2HTML<cr>      "设置快捷键自动保存为HTML文件
map <F4> :Vimwiki2HTML<cr>

nmap <silent> ,hl <Plug>MarkSet      "mark给不同的单词高亮配置
vmap <silent> ,hl <Plug>MarkSet
nmap <silent> ,hh <Plug>MarkClear
vmap <silent> ,hh <Plug>MarkClear
nmap <silent> ,hr <Plug>MarkRegex
vmap <silent> ,hr <Plug>MarkRegex
" <leader>*  当前MarkWord的下一个     <leader>#  当前MarkWord的上一个
" <leader>/  所有MarkWords的下一个    <leader>?  所有MarkWords的上一个

let g:wm_move_left  = "<A-h>"           "winmove配置,主要是用于调整窗口大小
let g:wm_move_right = "<A-l>"
let g:wm_move_up    = "<A-k>"
let g:wm_move_down  = "<A-j>"


 类似资料: