My Vim

Posted 自为

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了My Vim相关的知识,希望对你有一定的参考价值。

noip考完啦

不管成绩怎么样,以后不用Dev啦。

尝试一下传说中的Vim

我的Vim配置

Vim8.0

https://files.cnblogs.com/files/zwfymqz/gvim80.zip

 

VIM中文帮助

https://files.cnblogs.com/files/zwfymqz/vimcdoc-1.7.0-setup.zip

 

_Vimrce配置文件

 

  1 source $VIMRUNTIME/vimrc_example.vim
  2 source $VIMRUNTIME/mswin.vim
  3 behave mswin
  4 
  5 colorscheme molokai
  6 set t_Co=256
  7 :set guifont=Consolas:h17
  8 :set expandtab
  9 :set shiftwidth=4
 10 :set softtabstop=4
 11 :set nu!
 12 :set tabstop=4
 13 syntax on
 14 :set smartindent
 15 :set mouse=a
 16 :set autoindent
 17 :retab!
 18 "成对标点的自动定位功能,编程时的快速单步移动功能
 19 inoremap \' \'\'<ESC>i
 20 inoremap " ""<ESC>i
 21 inoremap ( ()<ESC>i
 22 inoremap [ []<ESC>i
 23 inoremap { {<CR>}<ESC>O
 24 
 25 "C,C++的调试
 26 map <F8> :call Rungdb()<CR>
 27 func! Rungdb()
 28     exec "w"
 29     exec "!g++ % -g -o %<"
 30     exec "!gdb ./%<"
 31 endfunc
 32 
 33 
 34 "C++编译运行
 35 "------------------------------------------------------------------------------  
 36 "  < 判断操作系统是否是 Windows 还是 Linux >  
 37 "------------------------------------------------------------------------------  
 38 if(has("win32") || has("win64") || has("win95") || has("win16"))  
 39     let g:iswindows = 1  
 40 else  
 41     let g:iswindows = 0  
 42 endif  
 43    
 44 "------------------------------------------------------------------------------  
 45 "  < 判断是终端还是 Gvim >  
 46 "------------------------------------------------------------------------------  
 47 if has("gui_running")  
 48     let g:isGUI = 1  
 49 else  
 50     let g:isGUI = 0  
 51 endif  
 52    
 53 "------------------------------------------------------------------------------  
 54 "  < 编译、连接、运行配置 >  
 55 "------------------------------------------------------------------------------  
 56 " F10 一键保存、编译、连接存并运行  
 57 map <F10> :call Run()<CR>  
 58 imap <F10> <ESC>:call Run()<CR>  
 59    
 60 " F9 一键保存并编译  
 61 map <F9> :call Compile()<CR>  
 62 imap <F9> <ESC>:call Compile()<CR>  
 63    
 64 " Ctrl + F10 一键保存并连接  
 65 map <c-F10> :call Link()<CR>  
 66 imap <c-F10> <ESC>:call Link()<CR>  
 67    
 68 let s:LastShellReturn_C = 0  
 69 let s:LastShellReturn_L = 0  
 70 let s:ShowWarning = 1  
 71 let s:Obj_Extension = \'.o\'  
 72 let s:Exe_Extension = \'.exe\'  
 73 let s:Sou_Error = 0  
 74    
 75 let s:windows_CFlags = \'gcc\\ -fexec-charset=gbk\\ -Wall\\ -g\\ -O0\\ -c\\ %\\ -o\\ %<.o\'  
 76 let s:linux_CFlags = \'gcc\\ -Wall\\ -g\\ -O0\\ -c\\ %\\ -o\\ %<.o\'  
 77    
 78 let s:windows_CPPFlags = \'g++\\ -fexec-charset=gbk\\ -Wall\\ -g\\ -O0\\ -c\\ %\\ -o\\ %<.o\'  
 79 let s:linux_CPPFlags = \'g++\\ -Wall\\ -g\\ -O0\\ -c\\ %\\ -o\\ %<.o\'  
 80    
 81 func! Compile()  
 82     exe ":ccl"  
 83     exe ":update"  
 84     if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx"  
 85         let s:Sou_Error = 0  
 86         let s:LastShellReturn_C = 0  
 87         let Sou = expand("%:p")  
 88         let Obj = expand("%:p:r").s:Obj_Extension  
 89         let Obj_Name = expand("%:p:t:r").s:Obj_Extension  
 90         let v:statusmsg = \'\'  
 91         if !filereadable(Obj) || (filereadable(Obj) && (getftime(Obj) < getftime(Sou)))  
 92             redraw!  
 93             if expand("%:e") == "c"  
 94                 if g:iswindows  
 95                     exe ":setlocal makeprg=".s:windows_CFlags  
 96                 else  
 97                     exe ":setlocal makeprg=".s:linux_CFlags  
 98                 endif  
 99                 echohl WarningMsg | echo " compiling..."  
100                 silent make  
101             elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"  
102                 if g:iswindows  
103                     exe ":setlocal makeprg=".s:windows_CPPFlags  
104                 else  
105                     exe ":setlocal makeprg=".s:linux_CPPFlags  
106                 endif  
107                 echohl WarningMsg | echo " compiling..."  
108                 silent make  
109             endif  
110             redraw!  
111             if v:shell_error != 0  
112                 let s:LastShellReturn_C = v:shell_error  
113             endif  
114             if g:iswindows  
115                 if s:LastShellReturn_C != 0  
116                     exe ":bo cope"  
117                     echohl WarningMsg | echo " compilation failed"  
118                 else  
119                     if s:ShowWarning  
120                         exe ":bo cw"  
121                     endif  
122                     echohl WarningMsg | echo " compilation successful"  
123                 endif  
124             else  
125                 if empty(v:statusmsg)  
126                     echohl WarningMsg | echo " compilation successful"  
127                 else  
128                     exe ":bo cope"  
129                 endif  
130             endif  
131         else  
132             echohl WarningMsg | echo ""Obj_Name"is up to date"  
133         endif  
134     else  
135         let s:Sou_Error = 1  
136         echohl WarningMsg | echo " please choose the correct source file"  
137     endif  
138     exe ":setlocal makeprg=make"  
139 endfunc  
140    
141 func! Link()  
142     call Compile()  
143     if s:Sou_Error || s:LastShellReturn_C != 0  
144         return  
145     endif  
146     let s:LastShellReturn_L = 0  
147     let Sou = expand("%:p")  
148     let Obj = expand("%:p:r").s:Obj_Extension  
149     if g:iswindows  
150         let Exe = expand("%:p:r").s:Exe_Extension  
151         let Exe_Name = expand("%:p:t:r").s:Exe_Extension  
152     else  
153         let Exe = expand("%:p:r")  
154         let Exe_Name = expand("%:p:t:r")  
155     endif  
156     let v:statusmsg = \'\'  
157     if filereadable(Obj) && (getftime(Obj) >= getftime(Sou))  
158         redraw!  
159         if !executable(Exe) || (executable(Exe) && getftime(Exe) < getftime(Obj))  
160             if expand("%:e") == "c"  
161                 setlocal makeprg=gcc\\ -o\\ %<\\ %<.o  
162                 echohl WarningMsg | echo " linking..."  
163                 silent make  
164             elseif expand("%:e") == "cpp" || expand("%:e") == "cxx"  
165                 setlocal makeprg=g++\\ -o\\ %<\\ %<.o  
166                 echohl WarningMsg | echo " linking..."  
167                 silent make  
168             endif  
169             redraw!  
170             if v:shell_error != 0  
171                 let s:LastShellReturn_L = v:shell_error  
172             endif  
173             if g:iswindows  
174                 if s:LastShellReturn_L != 0  
175                     exe ":bo cope"  
176                     echohl WarningMsg | echo " linking failed"  
177                 else  
178                     if s:ShowWarning  
179                         exe ":bo cw"  
180                     endif  
181                     echohl WarningMsg | echo " linking successful"  
182                 endif  
183             else  
184                 if empty(v:statusmsg)  
185                     echohl WarningMsg | echo " linking successful"  
186                 else  
187                     exe ":bo cope"  
188                 endif  
189             endif  
190         else  
191             echohl WarningMsg | echo ""Exe_Name"is up to date"  
192         endif  
193     endif  
194     setlocal makeprg=make  
195 endfunc  
196    
197 func! Run()  
198     let s:ShowWarning = 0  
199     call Link()  
200     let s:ShowWarning = 1  
201     if s:Sou_Error || s:LastShellReturn_C != 0 || s:LastShellReturn_L != 0  
202         return  
203     endif  
204     let Sou = expand("%:p")  
205     let Obj = expand("%:p:r").s:Obj_Extension  
206     if g:iswindows  
207         let Exe = expand("%:p:r").s:Exe_Extension  
208     else  
209         let Exe = expand("%:p:r")  
210     endif  
211     if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou)  
212         redraw!  
213         echohl WarningMsg | echo " running..."  
214         if g:iswindows  
215             exe ":!%<.exe"  
216         else  
217             if g:isGUI  
218                 exe ":!gnome-terminal -e ./%<"  
219             else  
220                 exe ":!./%<"  
221             endif  
222         endif  
223         redraw!  
224         echohl WarningMsg | echo " running finish"  
225     endif  
226 endfunc  
227 
228 :nmap <F5> :call Debug()<CR>
229 :nmap <F9> :call Compile()<CR>
230 :nmap <F10> :call Run()<CR>
231 :nmap <F11> :call CompileAndRun()<CR>
232 :nmap <S-F9> :call O2Compile()<CR>
233 :nmap <S-F11> :call O2CompileAndRun()<CR>
234 :nmap <F12> :call FileTest()<CR>
235 :nmap <S-F12> :call O2FileTest()<CR>
236 
237 
238 " 配置多语言环境,解决中文乱码问题
239 
240 if has("multi_byte") 
241     " UTF-8 编码 
242     set encoding=utf-8 
243     set termencoding=utf-8 
244     set formatoptions+=mM 
245     set fencs=utf-8,gbk 
246     if v:lang =~? \'^/(zh/)/|/(ja/)/|/(ko/)\' 
247         set ambiwidth=double 
248     endif 
249     if has("win32") 
250         source $VIMRUNTIME/delmenu.vim 
251         source $VIMRUNTIME/menu.vim 
252         language messages zh_CN.utf-8 
253     endif 
254 else 
255     echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte" 
256 endif
257 
258 
259 " ===== Set omnicppcomplete <C-X><C-O>, can get the option =====
260 " enable plugins
261 set nocp    
262 filetype plugin on
263 " --c++-kinds=+p  : Adds prototypes in the database for C/C++ files.
264 " --fields=+iaS   : Adds inheritance (i), access (a) and function signatures (S) information.
265 " --extra=+q      : Adds context to the tag name. Note: Without this option, the script cannot get class members.
266 " --languages=c++ : Builds only the tags for C++ files.
267 "        ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --languages=c++ .
268 " add a map <C-F12>
269 map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q --languages=c++ .<CR>
270 let OmniCpp_NamespaceSearch = 1
271 let OmniCpp_GlobalScopeSearch = 1
272 let OmniCpp_DisplayMode = 1
273 let OmniCpp_ShowScopeInAbbr = 1
274 let OmniCpp_ShowAccess = 1
275 let OmniCpp_ShowPrototypeInAbbr = 1 " 显示函数参数列表 
276 let OmniCpp_MayCompleteDot = 1   " 输入 .  后自动补全
277 let OmniCpp_MayCompleteArrow = 1 " 输入 -> 后自动补全 
278 let OmniCpp_MayCompleteScope = 1 " 输入 :: 后自动补全 
279 let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
280 let OmniCpp_SelectFirstItem = 1
281 set completeopt=longest,menu
282 
283 VIM
Vim

 

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin




colorscheme pablo
set guifont=Consolas:h17
set shiftwidth=4
set softtabstop=4
set tabstop=4
set nu!"设置行号"
set smartindent
set go -=T
set go -=m
inoremap ( ()<ESC>i
map <F9> :call C()<CR>
map <F10> :call R()<CR>
func! C()
    exec "w"
    exec "!g++ % -o %<"
endfunc
func! R()
    exec "!%<"
endfunc

map <F8> :call Rungdb()<CR>
func! Rungdb()
    exec "w"
    exec "!g++ % -g -o %<"
    exec "!gdb ./%<"
endfunc



set diffexpr=MyDiff()
function MyDiff()
  let opt = \'-a --binary \'
  if &diffopt =~ \'icase\' | let opt = opt . \'-i \' | endif
  if &diffopt =~ \'iwhite\' | let opt = opt . \'-b \' | endif
  let arg1 = v:fname_in
  if arg1 =~ \' \' | let arg1 = \'"\' . arg1 . \'"\' | endif
  let arg2 = v:fname_new
  if arg2 =~ \' \' | let arg2 = \'"\' . arg2 . \'"\' | endif
  let arg3 = v:fname_out
  if arg3 =~ \' \' | let arg3 = \'"\' . arg3 . \'"\' | endif
  let eq = \'\'
  if $VIMRUNTIME =~ \' \'
    if &sh =~ \'\\<cmd\'
      let cmd = \'""\' . $VIMRUNTIME . \'\\diff"\'
      let eq = \'"\'
    else
      let cmd = substitute($VIMRUNTIME, \' \', \'" \', \'\') . \'\\diff"\'
    endif
  else
    let cmd = $VIMRUNTIME . \'\\diff\'
  endif
  silent execute \'!\' . cmd . \' \' . opt . arg1 . \' \' . arg2 . \' > \' . arg3 . eq
endfunction
比赛

 

colorscheme molokai
set guifont=Consolas:h17
set shiftwidth=4
set softtabstop=4
set tabstop=4
set nu!"设置行号"
set smartindent
set go -=T
set go -=m
map <F9> :call C()<CR>
map <F10> :call R()<CR>
func! C()
    exec "w"
    exec "!g++ % -o %<"
endfunc
func! R()
    exec "!%<"
endfunc
map <F8> :call Rungdb()<CR>
func! Rungdb()
    exec "!gdb ./%<"
endfunc
new

 

 

 

分享一下我的VIM

  • F9一键编译(保证你的电脑上有gcc)
  • F10一键运行
  • F8一键gdb调试
  • Ctrl+F12自动生成tags
  • :Tlist可查看变量及函数
  • mokolai高亮
  • consolas字体
  • 括号自动补全(打头文件的时候比较鬼畜。。)
  • 结构体成员自动补全

https://pan.baidu.com/s/1skLGiuD

 

以上是关于My Vim的主要内容,如果未能解决你的问题,请参考以下文章

从零开始配置vim(27)——代码片段

从零开始配置vim(27)——代码片段

从零开始配置vim(27)——代码片段

vim代码片段插件ultisnips的使用

My Vim

my vim settings