From 6d31cdcd10dfead571c3ab3ae48c161efe4cef16 Mon Sep 17 00:00:00 2001 From: We-unite <3205135446@qq.com> Date: Tue, 24 Oct 2023 11:18:40 +0800 Subject: vim --- .gitignore | 2 - vim/vimrc | 29 +++++ vim/vimrc.tiny | 13 +++ vim/vimrc_origin | 55 +++++++++ vim/vimrcs/autocmd.vim | 81 ++++++++++++++ vim/vimrcs/fuck.vim | 69 ++++++++++++ vim/vimrcs/keybind.vim | 34 ++++++ vim/vimrcs/match.vim | 15 +++ vim/vimrcs/myset.vim | 66 +++++++++++ vim/vimrcs/plugs.vim | 121 ++++++++++++++++++++ vim/vimscript.vim | 295 +++++++++++++++++++++++++++++++++++++++++++++++++ 11 files changed, 778 insertions(+), 2 deletions(-) create mode 100644 vim/vimrc create mode 100644 vim/vimrc.tiny create mode 100644 vim/vimrc_origin create mode 100644 vim/vimrcs/autocmd.vim create mode 100644 vim/vimrcs/fuck.vim create mode 100644 vim/vimrcs/keybind.vim create mode 100644 vim/vimrcs/match.vim create mode 100644 vim/vimrcs/myset.vim create mode 100644 vim/vimrcs/plugs.vim create mode 100644 vim/vimscript.vim diff --git a/.gitignore b/.gitignore index c6eb4f2..02e8202 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ -* -!*.* push.sh diff --git a/vim/vimrc b/vim/vimrc new file mode 100644 index 0000000..34bb9cc --- /dev/null +++ b/vim/vimrc @@ -0,0 +1,29 @@ +" Vundle插件管理及插件内容 +if filereadable(expand("/etc/vim/vimrcs/plugs.vim")) + source /etc/vim/vimrcs/plugs.vim +endif + +" 自行设置 +if filereadable(expand("/etc/vim/vimrcs/myset.vim")) + source /etc/vim/vimrcs/myset.vim +endif + +" 符号自动匹配 +if filereadable(expand("/etc/vim/vimrcs/match.vim")) + source /etc/vim/vimrcs/match.vim +endif + +" 不知道是什么 +if filereadable(expand("/etc/vim/vimrcs/fuck.vim")) + source /etc/vim/vimrcs/fuck.vim +endif + +" 自己设的快捷键 +if filereadable(expand("/etc/vim/vimrcs/keybind.vim")) + source /etc/vim/vimrcs/keybind.vim +endif + +" 自动命令 +if filereadable(expand("/etc/vim/vimrcs/autocmd.vim")) + source /etc/vim/vimrcs/autocmd.vim +endif diff --git a/vim/vimrc.tiny b/vim/vimrc.tiny new file mode 100644 index 0000000..890037a --- /dev/null +++ b/vim/vimrc.tiny @@ -0,0 +1,13 @@ +" Vim configuration file, in effect when invoked as "vi". The aim of this +" configuration file is to provide a Vim environment as compatible with the +" original vi as possible. Note that ~/.vimrc configuration files as other +" configuration files in the runtimepath are still sourced. +" When Vim is invoked differently ("vim", "view", "evim", ...) this file is +" _not_ sourced; /etc/vim/vimrc and/or /etc/vim/gvimrc are. + +" Debian system-wide default configuration Vim +set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim82,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after + +set compatible + +" vim: set ft=vim: diff --git a/vim/vimrc_origin b/vim/vimrc_origin new file mode 100644 index 0000000..1fcd4d7 --- /dev/null +++ b/vim/vimrc_origin @@ -0,0 +1,55 @@ +" All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by +" the call to :runtime you can find below. If you wish to change any of those +" settings, you should do it in this file (/etc/vim/vimrc), since debian.vim +" will be overwritten everytime an upgrade of the vim packages is performed. +" It is recommended to make changes after sourcing debian.vim since it alters +" the value of the 'compatible' option. + +runtime! debian.vim + +" Vim will load $VIMRUNTIME/defaults.vim if the user does not have a vimrc. +" This happens after /etc/vim/vimrc(.local) are loaded, so it will override +" any settings in these files. +" If you don't want that to happen, uncomment the below line to prevent +" defaults.vim from being loaded. +" let g:skip_defaults_vim = 1 + +" Uncomment the next line to make Vim more Vi-compatible +" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous +" options, so any other options should be set AFTER setting 'compatible'. +"set compatible + +" Vim5 and later versions support syntax highlighting. Uncommenting the next +" line enables syntax highlighting by default. +if has("syntax") + syntax on +endif + +" If using a dark background within the editing area and syntax highlighting +" turn on this option as well +"set background=dark + +" Uncomment the following to have Vim jump to the last position when +" reopening a file +"au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif + +" Uncomment the following to have Vim load indentation rules and plugins +" according to the detected filetype. +"filetype plugin indent on + +" The following are commented out as they cause vim to behave a lot +" differently from regular Vi. They are highly recommended though. +"set showcmd " Show (partial) command in status line. +"set showmatch " Show matching brackets. +"set ignorecase " Do case insensitive matching +"set smartcase " Do smart case matching +"set incsearch " Incremental search +"set autowrite " Automatically save before commands like :next and :make +"set hidden " Hide buffers when they are abandoned +"set mouse=a " Enable mouse usage (all modes) + +" Source a global configuration file if available +if filereadable("/etc/vim/vimrc.local") + source /etc/vim/vimrc.local +endif + diff --git a/vim/vimrcs/autocmd.vim b/vim/vimrcs/autocmd.vim new file mode 100644 index 0000000..c974344 --- /dev/null +++ b/vim/vimrcs/autocmd.vim @@ -0,0 +1,81 @@ +autocmd BufReadPost,BufWritePre *.html,*.c,*.cpp,*.vim normal gg=G +"autocmd FileType * :normal gg=G +autocmd Filetype c,cpp map 0xxta +autocmd Filetype python map 0xxta + +"新建.c,.h,.sh,.java文件,自动插入文件头 +autocmd BufNewFile *.cpp,*.[ch],*.sh exec ":call SetTitle()" +func SetTitle() + if &filetype == 'sh' + call setline(1,"#!/bin/bash") + call append(line("."), "" ) + call append(line(".")+1, "\##########################################################################" ) + call append(line(".")+2, "\# File Name : ".expand("%")) + call append(line(".")+3, "\# Encoding : utf-8") + call append(line(".")+4, "\# Author : We-unite") + call append(line(".")+5, "\# Email : weunite1848@gmail.com") + call append(line(".")+6, "\# Created Time : ".strftime("%Y-%m-%d",localtime())) + call append(line(".")+7, "\##########################################################################" ) + call append(line(".")+8, "") + elseif &filetype =='py' + call setline(1,"#!/usr/bin/env python") + call append(line("."), "" ) + call append(line(".")+1, "\##########################################################################" ) + call append(line(".")+2, "\# File Name : ".expand("%")) + call append(line(".")+3, "\# Encoding : utf-8") + call append(line(".")+4, "\# Author : We-unite") + call append(line(".")+5, "\# Email : weunite1848@gmail.com") + call append(line(".")+6, "\# Created Time : ".strftime("%Y-%m-%d",localtime())) + call append(line(".")+7, "\##########################################################################" ) + call append(line(".")+8, "") + else + call setline(1, "/*************************************************************************") + call append(line("."), " > File Name : ".expand("%")) + call append(line(".")+1, " > Encoding : utf-8") + call append(line(".")+2, " > Author : We-unite") + call append(line(".")+3, " > Email : weunite1848@gmail.com ") + call append(line(".")+4, " > Created Time : ".strftime("%Y-%m-%d-%H:%M:%S",localtime())) + call append(line(".")+5, " ************************************************************************/") + call append(line(".")+6, "") + if &filetype == 'cpp' + call append(line(".")+7, "#include ") + call append(line(".")+8, "using namespace std;") + call append(line(".")+9, "") + elseif &filetype == 'c' + call append(line(".")+7, "#include ") + call append(line(".")+8, "#include ") + call append(line(".")+9, "") + endif + endif + " 光标移动到文件末尾 + normal G +endfunc + +"C,C++ 按F5编译运行 +map :call CompileRunGcc() + +func CompileRunGcc() + exec "w" + if &filetype == 'c' + exec "!gcc -g -o %< %" + exec "! ./%<" + elseif &filetype == 'cpp' + exec "!g++ -g -o %< %" + exec "! ./%<" + "elseif &filetype == 'java' + " exec "!javac %" + " exec "!java %<" + elseif &filetype == 'sh' + :!./% + elseif &filetype == 'python' + exec "!python %" + endif +endfunc + +"C,C++的调试 +map :call RunGdb() + +func RunGdb() + exec "w" + exec "!gdb ./%<" +endfunc diff --git a/vim/vimrcs/fuck.vim b/vim/vimrcs/fuck.vim new file mode 100644 index 0000000..d149b0b --- /dev/null +++ b/vim/vimrcs/fuck.vim @@ -0,0 +1,69 @@ +set guitablabel=%{ShortTabLabel()} +function ShortTabLabel () + let bufnrlist = tabpagebuflist (v:lnum) + let label = bufname (bufnrlist[tabpagewinnr (v:lnum) -1]) + let filename = fnamemodify (label, ':t') + return filename +endfunction + +set tabline=%!MyTabLine() +function MyTabLine() + let s = '' + for i in range(tabpagenr('$')) + " 选择高亮 + if i + 1 == tabpagenr() + let s .= '%#TabLineSel#' + else + let s .= '%#TabLine#' + endif + " 设置标签页号 (用于鼠标点击) + let s .= '%' . (i + 1) . 'T' + " MyTabLabel() 提供完整路径标签 MyShortTabLabel 提供文件名标签 + let s .= ' %{MyShortTabLabel(' . (i + 1) . ')} ' + endfor + " 最后一个标签页之后用 TabLineFill 填充并复位标签页号 + let s .= '%#TabLineFill#%T' + " 右对齐用于关闭当前标签页的标签 + if tabpagenr('$') > 1 + let s .= '%=%#TabLine#%999Xclose' + endif + return s +endfunction +" 文件名标签 +function MyShortTabLabel(n) + let buflist = tabpagebuflist(a:n) + let label = bufname (buflist[tabpagewinnr (a:n) -1]) + let filename = fnamemodify (label, ':t') + return filename +endfunction +"完整路径标签 +function MyTabLabel(n) + let buflist = tabpagebuflist(a:n) + let winnr = tabpagewinnr(a:n) + return bufname(buflist[winnr - 1]) +endfunction + +" 状态栏显示git分支函数 +function! GitBranch() + " 获取当前所在分支名,注意不要保留开头的*和行末的空符号 + let s:branch = system("git branch --no-color 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \\(.*\\)/\\1/' | tr -d '\n' | tr -d ' '") + return strlen(s:branch) ? 'b: '.s:branch.'> ' : '' +endfunction + +set laststatus=2 "显示状态栏(默认值为 1,无法显示状态栏) +set statusline=%f%m%r%h%w\ >\ %{GitBranch()}%=\ <\ %{&ff}\ <\ %y\ <\ %l,%v\ <\ %p%%\ <\ lines=%L + +function! CurDir() + let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g") + return curdir +endfunction + +"标签样式 +" TabLineFill tab pages line, where there are no labels +hi TabLineFill term=none +hi TabLineFill ctermfg=DarkGrey +hi TabLineFill guifg=#777777 +" TabLineSel tab pages line, active tab page label +hi TabLineSel term=inverse +hi TabLineSel cterm=none ctermfg=yellow ctermbg=Black +hi TabLineSel gui=none guifg=yellow guibg=Black diff --git a/vim/vimrcs/keybind.vim b/vim/vimrcs/keybind.vim new file mode 100644 index 0000000..270cd96 --- /dev/null +++ b/vim/vimrcs/keybind.vim @@ -0,0 +1,34 @@ +map - dd +map H 0 +map J :exe "normal! ".v:count1*10."j" +map K :exe "normal! ".v:count1*10."k" +map L $ +nmap c "关闭除当前窗口的所有页面 +nmap :w !sudo tee %L +nmap p "补全路径 +"nmap :tabn +nmap :tabp +"nmap :tabnew +"map = :vertical resize +5 +"map - :vertical resize -5 + +nnoremap 1gt +nnoremap 2gt +nnoremap 3gt +nnoremap 4gt +nnoremap 5gt +nnoremap 6gt +nnoremap 7gt +nnoremap 8gt +nnoremap 9gt +nnoremap :tablast + +"光标在页面间切换 +nnoremap h +nnoremap j +nnoremap k +nnoremap l + +"复制粘贴 +vnoremap "+y +nnoremap "+p diff --git a/vim/vimrcs/match.vim b/vim/vimrcs/match.vim new file mode 100644 index 0000000..279a33f --- /dev/null +++ b/vim/vimrcs/match.vim @@ -0,0 +1,15 @@ +"各类符号自动匹配 +: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 +endfunction diff --git a/vim/vimrcs/myset.vim b/vim/vimrcs/myset.vim new file mode 100644 index 0000000..37e65b5 --- /dev/null +++ b/vim/vimrcs/myset.vim @@ -0,0 +1,66 @@ +set expandtab "设置tab键替换为tabstop规定的空格数 +set tabstop=4 +set shiftwidth=4 "设置tab的间隔 + "set softtabstop=4 +set sts=4 +set showmatch "在输入括号时光标会短暂地跳到与之相匹配的括号处 +set wrap "设置自动折行 +set textwidth=80 "设置自动换行的长度 +set lbr +"set autoindent "设置自动缩进 +"set smartindent "设置智能缩进 +"set foldmethod=indent "设置按缩进折叠代码 +set foldmethod=syntax "设置按语法折叠代码 +"set foldlevel=99 "折叠层级 +"nnoremap za + + +"set guifont=Monospace +set guifont=:b:h16 +set encoding=utf-8 +set fileencoding=utf-8 +set fileencodings=ucs-bom,utf-8,GB18030,cp936,big5,euc-jp,euc-kr,latin1 +set fileformat=unix +set helplang=cn "帮助中文支持 +set mouse=a " 设置鼠标 +set noeb " 去掉输入错误的提示声音 +set confirm " 在处理未保存或只读文件的时候,弹出确认 +set langmenu=zh_CN.UTF-8 +set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离 + +"自动补全配置 +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 php set omnifunc=phpcomplete#CompletePHP +autocmd FileType c set omnifunc=ccomplete#Complete + +set rnu "设置相对行号 +set nu "设置绝对行号 +" Set cursor shape and color +if &term =~ "xterm" + " INSERT mode + let &t_SI = "\[6 q" . "\]12;blue\x7" + " REPLACE mode + let &t_SR = "\[3 q" . "\]12;black\x7" + " NORMAL mode + let &t_EI = "\[2 q" . "\]12;green\x7" +endif +" 1 -> blinking block 闪烁的方块 +" 2 -> solid block 不闪烁的方块 +" 3 -> blinking underscore 闪烁的下划线 +" 4 -> solid underscore 不闪烁的下划线 +" 5 -> blinking vertical bar 闪烁的竖线 +" 6 -> solid vertical bar 不闪烁的竖线 + +syntax on +set cul +set cuc +hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white +colorscheme industry "设置颜色主题 +""set lines=35 columns=118 +"set list "显示tab和空格 +"set listchars=tab:>-,trail:. "设置tab和空格的显示 +"hi SpecialKey ctermfg=red guifg=red diff --git a/vim/vimrcs/plugs.vim b/vim/vimrcs/plugs.vim new file mode 100644 index 0000000..cfd0136 --- /dev/null +++ b/vim/vimrcs/plugs.vim @@ -0,0 +1,121 @@ +" Vundle插件管理器配置 +set nocompatible "去除VIM一致性,必须 +filetype off "必须 + +"设置包括vundle和初始化相关的运行时路径" +set rtp+=/home/player/useful/bundle/Vundle.vim +call vundle#begin('/home/player/useful/bundle') + +Plugin 'VundleVim/Vundle.vim' "启用vundle管理插件,必须 +Plugin 'Valloric/YouCompleteMe' "代码补全插件 +Plugin 'preservim/nerdtree' "文件目录树插件 +Plugin 'Xuyuanp/nerdtree-git-plugin' "nerdtree git支持 +Plugin 'skywind3000/vim-terminal-help' "vim-terminal-help插件 +Plugin 'scrooloose/syntastic' "语法检查插件 +"Plugin 'Lokaltog/powerline',{'rtp':'powerline/bindings/vim/'} "状态栏信息插件 +Plugin 'github/copilot.vim' "GitHub Copilot插件 +Plugin 'voldikss/vim-translator' "翻译插件 +Plugin 'yegappan/taglist' "taglist插件 + +call vundle#end() +filetype plugin indent on "加载vim自带和插件相应的语法和文件类型相关脚本,必须 + +" YouCompleteMe +let g:ycm_global_ycm_extra_conf='/home/player/useful/bundle/YouCompleteMe/.ycm_extra_conf.py' +let g:ycm_key_invoke_completion = '' +let g:ycm_semantic_triggers = { + \ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'], + \ 'cs,lua,javascript': ['re!\w{2}'], + \ } +highlight PMenu ctermfg=34 ctermbg=21 guifg=darkred guibg=darkblue +highlight PMenuSel ctermfg=21 ctermbg=34 guifg=darkblue guibg=darkred +let g:ycm_autoclose_preview_window_after_completion=1 +nnoremap gf :YcmCompleter GoToDeclaration +nnoremap gf :YcmCompleter GoToDefinition +nnoremap gg :YcmCompleter GoToDefinitionElseDeclaration +nnoremap gr :YcmCompleter GoToReferences +let g:ycm_min_num_of_chars_for_completion=3 + +"NERDTree +"autocmd vimenter * NERDTree "进入vim自动打开nerdtree +"当nerdtree为当前标签页剩余唯一窗口时自动关闭 +autocmd bufenter * if(winnr('$') ==1 && exists('b:NERDTree') && b:NERDTree.isTabTree()) | quit | endif +"F2键开关文件目录树,注意shift+i切换是否显示隐藏文件 +nmap :NERDTreeToggle +nmap T :NERDTreeToggle +let g:NERDTreeDirArrowExpandable = '+' +let g:NERDTreeDirArrowCollapsible = '-' "修改树的显示图标 +"let g:NERDTreeWinPos='left' "窗口位置 +let g:NERDTreeSize=10 "窗口尺寸 +let g:NERDTreeShowLineNumbers=1 "窗口是否显示行号 +"let g:NERDTreeHidden=1 "似乎是隐藏文件的旧命令?没看到作用 +let NERDTreeShowHidden=1 "显示隐藏文件 +let NERDTreeIgnore = ['\.pyc$', '\.swp', '\.swo', '\.vscode', '__pycache__'] "过滤: 所有指定文件和文件夹不显示 +autocmd BufWinEnter * if getcmdwintype() == '' | silent NERDTreeMirror | endif "在每个标签页打开相同的文件树 + + +"nerdtree-git-plugin +let g:NERDTreeGitStatusIndicatorMapCustom = { + \ 'Dirty' :'Dty', + \ 'Modified' :'M', + \ 'Staged' :'Sta', + \ 'Untracked' :'U', + \ 'Renamed' :'R', + \ 'Unmerged' :'Umg', + \ 'Deleted' :'X', + \ 'Ignored' :'Ign', + \ 'Clean' :'Cl', + \ 'Unknown' :'?', + \ } +let g:NERDTreeGitStatusShowIgnored = 1 "a heavy feature may cost much more time. default: 0 +let g:NERDTreeGitStatusUntrackedFilesMode = 'all' "a heavy feature too. default: normal + +"vim-terminal-help +"set termwinsize=10*106 +"let g:terminal_key = '' +"设置光标在终端与编辑器间切换的快捷键 + +"syntastic +"YouCompleteMe插件对该插件支持过于优秀,一般不再需要配置,故废弃 +let g:syntastic_python_checkers=['pylint'] +let g:syntastic_python_pylint_args=['--disable=C0111,R0903,C0301'] +"GNU as汇编语言语法检查,需要安装as86和ld86 +let g:syntastic_asm_checkers=['as86'] +"" syntastic end + +" powerline +let laststatus=2 +let g:airlinr_powerline_fonts=1 "使用官方打过补丁的字体 +let g:Powerline_symbols='fancy' + +"vim-translator +let g:translator_target_lang = 'zh' +let g:translator_source_lang = 'auto' +let g:translator_default_engines = ['youdao', 'bing', 'haici'] +let g:translator_history_enable = v:true +let g:translator_window_type = 'popup' "可选值为 'popup' 和 'preview',默认为 'popup' +" Echo translation in the cmdline +nmap t Translate +vmap t TranslateV +" Display translation in a window +nmap w TranslateW +vmap w TranslateWV +" Replace the text with translation +nmap r TranslateR +vmap r TranslateRV +" Translate the text in clipboard +nmap x TranslateX + + +"进行Taglist的设置 +map :TlistToggle +map :silent Tlist "按下F3就可以呼出了 +let Tlist_Ctags_Cmd='/usr/local/bin/ctags' "因为我们放在环境变量里,所以可以直接执行 +let Tlist_Use_Right_Window=1 "让窗口显示在右边,0的话就是显示在左边 +let Tlist_Show_One_File=0 "让taglist可以同时展示多个文件的函数列表 +let Tlist_File_Fold_Auto_Close=0 "非当前文件列表折叠隐藏 +" 在每个标签页打开相同的函数列表 +autocmd BufWinEnter * if getcmdwintype() == '' | silent TlistUpdate | endif +let Tlist_Exit_OnlyWindow=1 "当taglist是最后一个分割窗口时,自动推出vim +let Tlist_Process_File_Always=0 "是否一直处理tags.1:处理;0:不处理 +let Tlist_Inc_Winwidth=1 "不是一直实时更新tags,因为没有必要 diff --git a/vim/vimscript.vim b/vim/vimscript.vim new file mode 100644 index 0000000..001b060 --- /dev/null +++ b/vim/vimscript.vim @@ -0,0 +1,295 @@ +" 主要参考 http://www.cnblogs.com/ma6174/archive/2011/12/10/2283393.html +" 额外添加了 ctags, YouCompleteMe等 +" 主要特点 + +"1.按F5可以直接编译并执行C、C++、java代码以及执行shell脚本,按“F8”可进行C、C++代码的调试 +"2.自动插入文件头 ,新建C、C++源文件时自动插入表头:包括文件名、作者、联系方式、建立时间等,读者可根据需求自行更改 +"3.映射“Ctrl + A”为全选并复制快捷键,方便复制代码 +"4.按“F2”可以直接消除代码中的空行 +"5.“F3”可列出当前目录文件,打开树状文件目录 +"6. 支持鼠标选择、方向键移动 +"7. 代码高亮,自动缩进,显示行号,显示状态行 +"8. 按“Ctrl + P”可自动补全 +"9. []、{}、()、""、‘ ‘等都自动补全 --- 如果需要{}做函数形式的补全(右括号自动换行,加一个空行,光标定位到空行,可以看下面的修改提示) +"10. 使用YouCompleteMe提供C++的自动补全提示,效果类似 Visual Studio那种,可以解析系统头文件 + + +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" """""""""""""" Suzzz """"""""""""""""""""" +"https://github.com/gmarik/Vundle.vim#about + +set nocompatible " be iMproved, required +filetype off " required + +set rtp+=~/.vim/bundle/Vundle.vim + +call vundle#begin() +" let Vundle manage Vundle, required +Plugin "gmarik/Vundle.vim" +" plugin on GitHub repo 添加github上的vimn插件,形式非常简单 +Plugin "tpope/vim-fugitive" +"语法检查 +Plugin "scrooloose/syntastic" +"让 syntastic忽略 python 文件 +let g:syntastic_ignore_files=[".*\.py$"] +"补全 python +Plugin "davidhalter/jedi" +Plugin "rstacruz/sparkup", {"rtp": "vim/"} +" YouCompleteMe插件,很好的智能提示,基本达到 IDE 级别 +Plugin "Valloric/YouCompleteMe" + +call vundle#end() " required + +filetype plugin indent on " required +" To ignore plugin indent changes, instead use: +"filetype plugin on +" YouCompleteMe 通过这个cm_global_ycm_extra_conf来获得补全规则,可以如下指定,也可以每次放置在工作目录 +let g:ycm_global_ycm_extra_conf=‘~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py‘ +"让YouCompleteMe同时利用原来的ctags +let g:ycm_collect_identifiers_from_tag_files = 1 + +" """"""""""""" By ma6174 """"""""""""""""""""" +" 显示相关 +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +autocmd InsertLeave * se nocul " 用浅色高亮当前行 +autocmd InsertEnter * se cul " 用浅色高亮当前行 +"set ruler " 显示标尺 +set showcmd " 输入的命令显示出来,看的清楚些 +"set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界(不建议) +"set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离 +set novisualbell " 不要闪烁(不明白) +"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 background=dark "背景使用黑色 +" 显示中文帮助 +if version >= 603 + set helplang=cn + set encoding=utf-8 +endif + +set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936 +set termencoding=utf-8 +set encoding=utf-8 +set fileencodings=ucs-bom,utf-8,cp936 +set fileencoding=utf-8 + +"键盘命令 + +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +"map ggVGY +"map! ggVGY +"map gg=G +""去空行 +"nnoremap :g/^\s*$/d + +"比较文件 +nnoremap :vert diffsplit + +"列出当前目录文件 +map :tabnew . + +"打开树状文件目录 +map \be + +"C,C++ 按F5编译运行 +map :call CompileRunGcc() + +func! CompileRunGcc() + + exec "w" + if &filetype == ‘c‘ + exec "!g++ % -o %<" + exec "! ./%<" + elseif &filetype == ‘cpp‘ + exec "!g++ % -o %<" + exec "! ./%<" + elseif &filetype == ‘java‘ + exec "!javac %" + exec "!java %<" + elseif &filetype == ‘sh‘ + :!./% + endif +endfunc + +"C,C++的调试 + +map :call Rungdb() + +func! Rungdb() + exec "w" + exec "!g++ % -g -o %<" + exec "!gdb ./%<" +endfunc + +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +""实用设置 + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +" 设置当文件被改动时自动载入 +set autoread + +" quickfix模式 +autocmd FileType c,cpp map :w:make + +"代码补全 +set completeopt=preview,menu + +"允许插件 +filetype plugin on + +"共享剪贴板 +set clipboard+=unnamed + +"从不备份 +"set nobackup + +"make 运行 +:set makeprg=g++\ -Wall\ \ % + +"自动保存 +set autowrite + +set ruler " 打开状态栏标尺 +set cursorline " 突出显示当前行 +set magic " 设置魔术 +set guioptions-=T " 隐藏工具栏 +set guioptions-=m " 隐藏菜单栏 +" 设置在状态行显示的信息 +"set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\ + +"set foldcolumn=0 +"set foldmethod=indent +"set foldlevel=3 +"set foldenable " 开始折叠 + +" 去掉输入错误的提示声音 +set noeb + +" 在处理未保存或只读文件的时候,弹出确认 +set confirm + +" 自动缩进 +"set autoindent +"set cindent + +" 在行和段开始处使用制表符 +set smarttab + +" 历史记录数 +set history=1000 + +"禁止生成临时文件 +set noswapfile + +"搜索忽略大小写 +set ignorecase + +"搜索逐字符高亮 +set hlsearch +set incsearch + +"行内替换 +set gdefault + +"语言设置 +set langmenu=zh_CN.UTF-8 +set helplang=cn + +" 我的状态行显示的内容(包括文件类型和解码) +"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 + +" 命令行(在状态行下)的高度,默认为1,这里是2 +set cmdheight=2 + +" 带有如下符号的单词不要被换行分割 +set iskeyword+=_,$,@,%,#,- + +set selection=exclusive +set selectmode=mouse,key + +" 通过使用: commands命令,告诉我们文件的哪一行被改变过 +set report=0 + +" 光标移动到buffer的顶部和底部时保持3行距离 +set scrolloff=3 + +" 为C程序提供自动缩进 + +" 高亮显示普通txt文件(需要txt.vim脚本) + +au BufRead,BufNewFile * setfiletype txt + +"自动补全 +"by Suzzz: 原作者这种设置,输入{会自动补全,并且中间插入一个空行,将光标定位到空行。这对于函数是OK的,但是使用花括号初始化数组、vector时就不方便了。所以改为现在这种。只是补全,然后光标在左右括号中间。 +":inoremap { {}O +:inoremap ( ()i +:inoremap ) =ClosePair(‘)‘) +:inoremap { {}i +:inoremap } =ClosePair(‘}‘) +:inoremap [ []i +:inoremap ] =ClosePair(‘]‘) +:inoremap " ""i +:inoremap ‘ ‘‘i + +function! ClosePair(char) + if getline(‘.‘)[col(‘.‘) - 1] == a:char + return "\" + else + return a:char + endif +endfunction + +set completeopt=longest,menu + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +" 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 " 不要显示折叠树 +autocmd FileType java set tags+=D:\tools\java\tags +"autocmd FileType h,cpp,cc,c set tags+=D:\tools\cpp\tags +"let Tlist_Show_One_File=1 "不同时显示多个文件的tag,只显示当前文件的 +"设置tags +set tags=tags +"set autochdir + +"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +"其他东东 + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" + +"默认打开Taglist +let Tlist_Auto_Open=1 + +"""""""""""""""""""""""""""""" + +" Tag list (ctags) + +"""""""""""""""""""""""""""""""" + +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窗口 +" minibufexpl插件的一般设置 +let g:miniBufExplMapWindowNavVim = 1 +let g:miniBufExplMapWindowNavArrows = 1 +let g:miniBufExplMapCTabSwitchBufs = 1 +let g:miniBufExplModSelTarget = 1 -- cgit v1.2.3-70-g09d2