平时linux下程序开发常用配置,个人感觉比较实用,这里做个记录,插件的安装请参考Vim自动补全
set nu " 显示行号
syntax on "语法高亮
" 自动缩进
set autoindent
set cindent
" 生成临时文件
" set backup
" set nobackup
" 为C语言提供自动缩进
set smartindent
" tabsize = 4
set tabstop=4
set shiftwidth=4
set expandtab
set softtabstop=4
set nocompatible " be iMproved, required
filetype off " required
"新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
""定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if expand("%:e") == 'sh'
call setline(1,"\#########################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: fas")
call append(line(".")+2, "\# Created Time: ".strftime("%c"))
call append(line(".")+3, "\#########################################################################")
call append(line(".")+4, "\#!/bin/bash")
call append(line(".")+5, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: fas")
call append(line(".")+2, " > Created Time: ".strftime("%c"))
call append(line(".")+3, " ************************************************************************/")
call append(line(".")+4, "")
endif
if expand("%:e") == 'cpp'
call append(line(".")+5, "#include<iostream>")
call append(line(".")+6, "")
call append(line(".")+7, "int main(int argc, char** atgv) {")
call append(line(".")+8, "")
call append(line(".")+9, " return 0;")
call append(line(".")+10, "}")
endif
if expand("%:e") == 'c'
call append(line(".")+5, "#include<stdio.h>")
call append(line(".")+6, "")
call append(line(".")+7, "int main(int argc, char** atgv) {")
call append(line(".")+8, "")
call append(line(".")+9, " return 0;")
call append(line(".")+10, "}")
endif
endfunc
" 按下F5根据文件类型编译程序,仅限与当前单个文件的编译,该功能还是比较便捷的。
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!gcc % -o %<"
exec "! ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %< --std=c++11"
exec "! ./%<"
elseif &filetype == 'sh'
:!./%
endif
endfunc
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
Plugin 'fatih/vim-go'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required