博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
我的.vimrc,代码完成基于YcmCompleteMe版
阅读量:6858 次
发布时间:2019-06-26

本文共 23353 字,大约阅读时间需要 77 分钟。

相应的安装部分见上篇文章:vim学习笔记

.vimrc配置

1.基于YcmCompleteMe、taglist.vim、The-NERD-tree等配置,F2调出目录树窗口,F3调出变量、函数窗口,有点IDE的样子,呵呵!

2.定义了一些基本的快捷键:C-a 全选,C-c 选中状态下复制,F5 编译及运行,F8 调试,gb 跳到定义处。
3.Syntastic部分必需正确配置C++ include的目录。
4.刚有个哥们问怎样表明就成功了,我定义了F4为:YcmDiags命令,按F4就会执行,如果代码正确而运行不出错就成功了,若代码不正确运行就会出现Quickfix窗口,给出错误提示,这也表明配置已经成功。但这个配置其实没多大用处,因为只要一存盘,就会自动调用该命令,呵呵!

"********************************************************"                   一般性配置                          *"********************************************************"关闭vim一致性原则set nocompatible"显示行号set number"设置在编辑过程中右下角显示光标的行列信息set ruler"在状态栏显示正在输入的命令set showcmd"设置历史记录条数set history=1000"设置取消备份 禁止临时文件的生成set nobackupset noswapfile"设置匹配模式set showmatch"设置C/C++方式自动对齐set autoindentset cindent"开启语法高亮功能syntax enablesyntax on"指定配色方案为256色set t_Co=256"设置搜索时忽略大小写set ignorecase"配置backspace的工作方式set backspace=indent,eol,start"选中高亮set hls "高亮光标所在行"set cul "cursorline "set cuc"set go=             " 不要图形按钮  "color desert     " 设置背景主题  color ron     " 设置背景主题  "color torte     " 设置背景主题  set guifont=Courier_New:h10:cANSI   " 设置字体  "autocmd InsertLeave * se nocul  " 用浅色高亮当前行  "autocmd InsertEnter * se cul    " 用浅色高亮当前行  "set whichwrap+=<,>,h,l   " 允许backspace和光标键跨越行边界(不建议)  " 光标移动到buffer的顶部和底部时保持3行距离  set scrolloff=3" 总是显示状态行" set cmdheight=1set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}set laststatus=1    " 启动显示状态行(1),总是显示状态行(2)  set foldenable      " 允许折叠  "set foldmethod=manual   " 手动折叠  "set magic                   " 设置魔术"set guioptions-=T           " 隐藏工具栏"set guioptions-=m           " 隐藏菜单栏let g:indentLine_char = '┊'"启动时不显示帮助乌干达儿童提示set shortmess=atI "设置在vim中可以使用鼠标set mouse=a"设置tab宽度set tabstop=4"设置自动对齐空格数set shiftwidth=4"设置退格键时可以删除4个空格set smarttabset softtabstop=4"将tab键自动转换为空格set expandtab"设置编码方式set encoding=utf-8"自动判断编码时 依次尝试以下编码set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1"检测文件类型filetype on"针对不同的文件采取不同的缩进方式filetype indent on"允许插件filetype plugin on"启动智能补全filetype plugin indent on"*********************************************************"                  vundle 配置                           *"*********************************************************set rtp+=~/.vim/bundle/vundle/call vundle#rc()" let Vundle manage VundleBundle 'gmarik/vundle'" My Bundles here:Bundle 'tpope/vim-fugitive'Bundle 'Lokaltog/vim-easymotion'Bundle 'Yggdroot/indentLine'Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}Bundle 'tpope/vim-rails.git'Bundle 'taglist.vim'Bundle 'The-NERD-tree'Bundle 'Syntastic'Bundle 'L9'Bundle 'FuzzyFinder'Bundle 'Lokaltog/vim-powerline'Bundle 'Valloric/YouCompleteMe' "*****************************************************"                   taglist配置                      *"*****************************************************"不显示"press F1 to display help"let Tlist_Compact_Format=1"窗口在左侧显示let Tlist_Use_Right_Window=1"只显示当前文件的tagslet Tlist_Show_One_File=1  "高亮显示let Tlist_Auto_Highlight_tag=1"随文件自动更新let Tlist_Auto_Update=1"设置宽度let Tlist_WinWidth=30       "taglist窗口是最后一个窗口,则退出vimlet Tlist_Exit_OnlyWindow=1 "单击跳转let Tlist_Use_SingClick=1"打开关闭快捷键nnoremap 
:TlistToggle
"********************************************************" NERD_Tree 配置 *"********************************************************"显示增强let NERDChristmasTree=1"自动调整焦点let NERDTreeAutoCenter=1"鼠标模式:目录单击,文件双击let NERDTreeMouseMode=2"打开文件后自动关闭let NERDTreeQuitOnOpen=0"显示文件let NERDTreeShowFiles=1"显示隐藏文件let NERDTreeShowHidden=0"高亮显示当前文件或目录let NERDTreeHightCursorline=1"显示行号let NERDTreeShowLineNumbers=1"窗口位置let NERDTreeWinPos='left'"窗口宽度let NERDTreeWinSize=31"不显示'Bookmarks' label 'Press ? for help'let NERDTreeMinimalUI=1"快捷键nnoremap
:NERDTreeToggle
"当打开vim且没有文件时自动打开NERDTreeautocmd vimenter * if !argc() | NERDTree | endif"只剩 NERDTree时自动关闭autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif" 设置当文件被改动时自动载入" set autoread"*****************************************************" YouCompleteMe配置 *"*****************************************************"leader映射为逗号“,”let mapleader = "," "配置默认的ycm_extra_conf.py"let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py' "按gb 会跳转到定义nnoremap
gb :YcmCompleter GoToDefinitionElseDeclaration
"打开vim时不再询问是否加载ycm_extra_conf.py配置let g:ycm_confirm_extra_conf=0 "使用ctags生成的tags文件let g:ycm_collect_identifiers_from_tag_files = 1 map
: YcmDiags
"*****************************************************" Syntastic配置 *"*****************************************************let g:syntastic_check_on_open = 1let g:syntastic_cpp_include_dirs = ['/usr/include/']let g:syntastic_cpp_remove_include_errors = 1let g:syntastic_cpp_check_header = 1let g:syntastic_cpp_compiler = 'clang++'let g:syntastic_cpp_compiler_options = '-std=c++11 -stdlib=libstdc++'"set error or warning signslet g:syntastic_error_symbol = '✗'let g:syntastic_warning_symbol = '⚠'"whether to show balloonslet g:syntastic_enable_balloons = 1"*****************************************************"C,C++ 按F5编译运行 *"*****************************************************map
:call CompileRunGcc()
func! CompileRunGcc() exec "w" if &filetype == 'c' exec "!gcc % -o %<" exec "! ./%<" elseif &filetype == 'cpp' exec "!g++ % -o %<" exec "! ./%<" elseif &filetype == 'java' exec "!javac %" exec "!java %<" elseif &filetype == 'sh' :!./% endifendfunc"*****************************************************"C,C++的调试 F8 *"*****************************************************map
:call Rungdb()
func! Rungdb() exec "w" exec "!g++ % -g -o %<" exec "!gdb ./%<"endfunc"*****************************************************"键盘命令 *"*****************************************************nmap
w :w!
nmap
f :find
" 映射全选+复制 ctrl+amap
ggVGYmap!
ggVGY" 选中状态下 Ctrl+c 复制vmap
"+y"*****************************************************"新文件标题 *"*****************************************************"新建.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, "") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name : ".expand("%")) call append(line(".")+1, " > Author : zhoutk") call append(line(".")+2, " > Mail : zhoutk@189.cn") 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
") call append(line(".")+7, "using namespace std;") call append(line(".")+8, "") endif if &filetype == 'c' call append(line(".")+6, "#include
") 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"*****************************************************"代码格式优化化 *"*****************************************************map
:call FormartSrc()
"定义FormartSrc()func FormartSrc() exec "w" if &filetype == 'c' exec "!astyle --style=ansi -a --suffix=none %" elseif &filetype == 'cpp' || &filetype == 'hpp' exec "r !astyle --style=ansi --one-line=keep-statements -a --suffix=none %> /dev/null 2>&1" elseif &filetype == 'perl' exec "!astyle --style=gnu --suffix=none %" elseif &filetype == 'py'||&filetype == 'python' exec "r !autopep8 -i --aggressive %" elseif &filetype == 'java' exec "!astyle --style=java --suffix=none %" elseif &filetype == 'jsp' exec "!astyle --style=gnu --suffix=none %" elseif &filetype == 'xml' exec "!astyle --style=gnu --suffix=none %" else exec "normal gg=G" return endif exec "e! %"endfunc"结束定义FormartSrc"下面两个试验没成功,注释后留在这做个记录,去空行若是定义为F4是成功的。"去空行 "nnoremap
:g/^\s*$/d
"比较文件 "nnoremap
:vert diffsplit

.ycm_extra_conf.py配置

拷贝模板~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py到~/

下,主要有两点改动:
1.flags增加对c++相关目录的配置,我把针对OS X的配置删除了。
2.配置文档的倒数8到10注释掉。

# This file is NOT licensed under the GPLv3, which is the license for the rest# of YouCompleteMe.## Here's the license text for this file:## This is free and unencumbered software released into the public domain.## Anyone is free to copy, modify, publish, use, compile, sell, or# distribute this software, either in source code form or as a compiled# binary, for any purpose, commercial or non-commercial, and by any# means.## In jurisdictions that recognize copyright laws, the author or authors# of this software dedicate any and all copyright interest in the# software to the public domain. We make this dedication for the benefit# of the public at large and to the detriment of our heirs and# successors. We intend this dedication to be an overt act of# relinquishment in perpetuity of all present and future rights to this# software under copyright law.## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR# OTHER DEALINGS IN THE SOFTWARE.## For more information, please refer to 
import osimport ycm_core# These are the compilation flags that will be used in case there's no# compilation database set (by default, one is not set).# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.flags = ['-Wall','-Wextra','-Werror','-Wc++98-compat','-Wno-long-long','-Wno-variadic-macros','-fexceptions','-DNDEBUG',# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM# source code needs it.'-DUSE_CLANG_COMPLETER',# THIS IS IMPORTANT! Without a "-std=
" flag, clang won't know which# language to use when compiling headers. So it will guess. Badly. So C++# headers will be compiled as C headers. You don't want that so ALWAYS specify# a "-std=
".# For a C project, you would set this to something like 'c99' instead of# 'c++11'.'-std=c++11',# ...and the same thing goes for the magic -x option which specifies the# language that the files to be compiled are written in. This is mostly# relevant for c++ headers.# For a C project, you would set this to 'c' instead of 'c++'.'-x','c++','-isystem','../BoostParts','-isystem','/usr/include','-isystem','/usr/include/c++/','-isystem','/usr/include/c++/5.2.1',]# Set this to the absolute path to the folder (NOT the file!) containing the# compile_commands.json file to use that instead of 'flags'. See here for# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html## You can get CMake to generate this file for you by adding:# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )# to your CMakeLists.txt file.## Most projects will NOT need to set this to anything; you can just change the# 'flags' list of compilation flags. Notice that YCM itself uses that approach.compilation_database_folder = ''if os.path.exists( compilation_database_folder ): database = ycm_core.CompilationDatabase( compilation_database_folder )else: database = NoneSOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]def DirectoryOfThisScript(): return os.path.dirname( os.path.abspath( __file__ ) )def MakeRelativePathsInFlagsAbsolute( flags, working_directory ): if not working_directory: return list( flags ) new_flags = [] make_next_absolute = False path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ] for flag in flags: new_flag = flag if make_next_absolute: make_next_absolute = False if not flag.startswith( '/' ): new_flag = os.path.join( working_directory, flag ) for path_flag in path_flags: if flag == path_flag: make_next_absolute = True break if flag.startswith( path_flag ): path = flag[ len( path_flag ): ] new_flag = path_flag + os.path.join( working_directory, path ) break if new_flag: new_flags.append( new_flag ) return new_flagsdef IsHeaderFile( filename ): extension = os.path.splitext( filename )[ 1 ] return extension in [ '.h', '.hxx', '.hpp', '.hh' ]def GetCompilationInfoForFile( filename ): # The compilation_commands.json file generated by CMake does not have entries # for header files. So we do our best by asking the db for flags for a # corresponding source file, if any. If one exists, the flags for that file # should be good enough. if IsHeaderFile( filename ): basename = os.path.splitext( filename )[ 0 ] for extension in SOURCE_EXTENSIONS: replacement_file = basename + extension if os.path.exists( replacement_file ): compilation_info = database.GetCompilationInfoForFile( replacement_file ) if compilation_info.compiler_flags_: return compilation_info return None return database.GetCompilationInfoForFile( filename )def FlagsForFile( filename, **kwargs ): if database: # Bear in mind that compilation_info.compiler_flags_ does NOT return a # python list, but a "list-like" StringVec object compilation_info = GetCompilationInfoForFile( filename ) if not compilation_info: return None final_flags = MakeRelativePathsInFlagsAbsolute( compilation_info.compiler_flags_, compilation_info.compiler_working_dir_ ) # NOTE: This is just for YouCompleteMe; it's highly likely that your project # does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR # ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT. # try: # final_flags.remove( '-stdlib=libc++' ) # except ValueError: # pass else: relative_to = DirectoryOfThisScript() final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to ) return { 'flags': final_flags, 'do_cache': True }

2015-11-24更新版.vimrc

function! WrapForTmux(s)  if !exists('$TMUX')    return a:s  endif  let tmux_start = "\
Ptmux;" let tmux_end = "\
\\" return tmux_start . substitute(a:s, "\
", "\
\
", 'g') . tmux_endendfunctionlet &t_SI .= WrapForTmux("\
[?2004h")let &t_EI .= WrapForTmux("\
[?2004l")function! XTermPasteBegin() set pastetoggle=
[201~ set paste return ""endfunctioninoremap
[200~ XTermPasteBegin()if exists('$ITERM_PROFILE') if exists('$TMUX') let &t_SI = "\
[3 q" let &t_EI = "\
[0 q" else let &t_SI = "\
]50;CursorShape=1\x7" let &t_EI = "\
]50;CursorShape=0\x7" endifend"********************************************************" 一般性配置 *"********************************************************"关闭vim一致性原则set nocompatible"显示行号set number"设置在编辑过程中右下角显示光标的行列信息set ruler"在状态栏显示正在输入的命令set showcmd"设置历史记录条数set history=1000"设置取消备份 禁止临时文件的生成set nobackupset noswapfile"设置匹配模式set showmatch"设置C/C++方式自动对齐set autoindentset cindent"开启语法高亮功能syntax enablesyntax on"指定配色方案为256色set t_Co=256"设置搜索时忽略大小写set ignorecase"配置backspace的工作方式set backspace=indent,eol,start"选中高亮set hls "高亮光标所在行"set cul "cursorline "set cuc"set go= " 不要图形按钮 "color desert " 设置背景主题 color ron " 设置背景主题 "color torte " 设置背景主题 set guifont=Courier_New:h10:cANSI " 设置字体 "autocmd InsertLeave * se nocul " 用浅色高亮当前行 "autocmd InsertEnter * se cul " 用浅色高亮当前行 "set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界(不建议) " 光标移动到buffer的顶部和底部时保持3行距离 set scrolloff=3" 总是显示状态行set cmdheight=1set 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 magic " 设置魔术"set guioptions-=T " 隐藏工具栏"set guioptions-=m " 隐藏菜单栏let g:indentLine_char = '┊'"启动时不显示帮助乌干达儿童提示set shortmess=atI "设置在vim中可以使用鼠标set mouse=a"设置tab宽度set tabstop=4"设置自动对齐空格数set shiftwidth=4"设置退格键时可以删除4个空格set smarttabset softtabstop=4"将tab键自动转换为空格set expandtab"设置编码方式set encoding=utf-8"自动判断编码时 依次尝试以下编码set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1"检测文件类型filetype on"针对不同的文件采取不同的缩进方式filetype indent on"允许插件filetype plugin on"简化+寄存器操作set clipboard=unnamedplus"启动智能补全filetype plugin indent oncnoremap
%% getcmdtype() == ':' ? expand('%:h').'/' : '%%'"*********************************************************" vundle 配置 *"*********************************************************set rtp+=~/.vim/bundle/vundle/call vundle#rc()" let Vundle manage VundleBundle 'gmarik/vundle'" My Bundles here:Bundle 'SuperTab'Bundle 'Vim-JavaScript'Bundle 'a.vim'Bundle 'c.vim'Bundle 'Align'Bundle 'L9'Bundle 'vim-javacompleteex'Bundle 'tpope/vim-fugitive'Bundle 'Lokaltog/vim-easymotion'Bundle 'Yggdroot/indentLine'Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}Bundle 'ctags.vim'Bundle 'taglist.vim'Bundle 'The-NERD-tree'Bundle 'Syntastic'Bundle 'std_c.zip'Bundle 'FuzzyFinder'Bundle 'tpope/vim-commentary'Bundle 'tpope/vim-surround'Bundle 'Lokaltog/vim-powerline'Bundle 'Valloric/YouCompleteMe' Bundle 'Valloric/MatchTagAlways'"*****************************************************" MatchTagAlways配置 *"*****************************************************let g:mta_use_matchparen_group = 1"*****************************************************" FuzzyFinder配置 *"*****************************************************map
F :FufFile
map
f :FufTaggedFile
map
g :FufTag
map
b :FufBuffer
"*****************************************************" taglist配置 *"*****************************************************"不显示"press F1 to display help"let Tlist_Compact_Format=1"窗口在左侧显示let Tlist_Use_Right_Window=1"只显示当前文件的tagslet Tlist_Show_One_File=1 "高亮显示let Tlist_Auto_Highlight_tag=1"随文件自动更新let Tlist_Auto_Update=1"设置宽度let Tlist_WinWidth=30 "taglist窗口是最后一个窗口,则退出vimlet Tlist_Exit_OnlyWindow=1 "单击跳转let Tlist_Use_SingClick=1"打开关闭快捷键nnoremap
:TlistToggle
"********************************************************" NERD_Tree 配置 *"********************************************************"显示增强let NERDChristmasTree=1"自动调整焦点let NERDTreeAutoCenter=1"鼠标模式:目录单击,文件双击let NERDTreeMouseMode=2"打开文件后自动关闭let NERDTreeQuitOnOpen=0"显示文件let NERDTreeShowFiles=1"显示隐藏文件let NERDTreeShowHidden=0"高亮显示当前文件或目录let NERDTreeHightCursorline=1"显示行号let NERDTreeShowLineNumbers=1"窗口位置let NERDTreeWinPos='left'"窗口宽度let NERDTreeWinSize=31"不显示'Bookmarks' label 'Press ? for help'let NERDTreeMinimalUI=1"快捷键nnoremap
:NERDTreeToggle
"当打开vim且没有文件时自动打开NERDTreeautocmd vimenter * if !argc() | NERDTree | endif"只剩 NERDTree时自动关闭autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif" 设置当文件被改动时自动载入" set autoread"*****************************************************" YouCompleteMe配置 *"*****************************************************"leader映射为逗号“,”let mapleader = "," "配置默认的ycm_extra_conf.py"let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py' "按gb 会跳转到定义nnoremap
gb :YcmCompleter GoToDefinitionElseDeclaration
"打开vim时不再询问是否加载ycm_extra_conf.py配置let g:ycm_confirm_extra_conf=0 "使用ctags生成的tags文件let g:ycm_collect_identifiers_from_tag_files = 1 map
: YcmDiags
"*****************************************************" Syntastic配置 *"*****************************************************let g:syntastic_check_on_open = 1let g:syntastic_cpp_include_dirs = ['/usr/include/']let g:syntastic_cpp_remove_include_errors = 1let g:syntastic_cpp_check_header = 1let g:syntastic_cpp_compiler = 'clang++'let g:syntastic_cpp_compiler_options = '-std=c++11 -stdlib=libstdc++'"set error or warning signslet g:syntastic_error_symbol = '✗'let g:syntastic_warning_symbol = '⚠'"whether to show balloonslet g:syntastic_enable_balloons = 1"*****************************************************"C,C++ 按F5编译运行 *"*****************************************************map
:call CompileRunGcc()
func! CompileRunGcc() exec "w" if &filetype == 'c' exec "!gcc % -o %<" exec "! ./%<" elseif &filetype == 'cpp' exec "!g++ % -o %<" exec "! ./%<" elseif &filetype == 'java' exec "!javac %" exec "!java %<" elseif &filetype == 'sh' :!./% endifendfunc"*****************************************************"C,C++的调试 F8 *"*****************************************************map
:call Rungdb()
func! Rungdb() exec "w" exec "!g++ % -g -o %<" exec "!gdb ./%<"endfunc"*****************************************************"新文件标题 *"*****************************************************"新建.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, "") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name : ".expand("%")) call append(line(".")+1, " > Author : zhoutk") call append(line(".")+2, " > Mail : zhoutk@189.cn") 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
") call append(line(".")+7, "using namespace std;") call append(line(".")+8, "") endif if &filetype == 'c' call append(line(".")+6, "#include
") 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"*****************************************************"代码格式优化化 *"*****************************************************map
:call FormartSrc()
"定义FormartSrc()func FormartSrc() exec "w" if &filetype == 'c' exec "!astyle --style=ansi -a --suffix=none %" elseif &filetype == 'cpp' || &filetype == 'hpp' exec "r !astyle --style=ansi --one-line=keep-statements -a --suffix=none %> /dev/null 2>&1" elseif &filetype == 'perl' exec "!astyle --style=gnu --suffix=none %" elseif &filetype == 'py'||&filetype == 'python' exec "r !autopep8 -i --aggressive %" elseif &filetype == 'java' exec "!astyle --style=java --suffix=none %" elseif &filetype == 'jsp' exec "!astyle --style=gnu --suffix=none %" elseif &filetype == 'xml' exec "!astyle --style=gnu --suffix=none %" else exec "normal gg=G" return endif exec "e! %"endfunc"结束定义FormartSrc

转载地址:http://pwiyl.baihongyu.com/

你可能感兴趣的文章
GZipStream的简单使用
查看>>
java生成MD5校验码及算法实现
查看>>
thymeleaf 学习笔记(转)
查看>>
Mac 升级 OpenSSL
查看>>
Python学习笔记(5)-if判断、if嵌套、判断小练习
查看>>
文本转换成音频流
查看>>
负载均衡之lvs
查看>>
C#之类与对象知识点
查看>>
斯坦福大学公开课机器学习:Neural network-model representation(神经网络模型及神经单元的理解)...
查看>>
七、集成swagger2
查看>>
Python(面向对象5——高级)
查看>>
chocolatey使用
查看>>
【转】iOS高级向的十道面试问题
查看>>
了解ES6
查看>>
Maven_2 本地资源库 中央存储库
查看>>
昂贵的聘礼 poj 1062 Dijkstra
查看>>
Hadoop HA的搭建
查看>>
JavaScript实现搜索框效果
查看>>
搭建nginx流媒体服务器(支持HLS)
查看>>
ubuntu 12.04 安装libpcap
查看>>