Vim 常用配置

平时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
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值