ubuntu 下 vim 的配置

set nocp  "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限

"set nu

syntax on

set autoindent

set smartindent

set ts=4

set shiftwidth=4

set ruler

set showmatch "设置匹配模式,类似当输入一个左括号时会匹配相应的那个右括号

set incsearch      "查询时非常方便    例如 : book  b, bo, boo

set nomore

 

"------解决乱码,不知有效否?-------------------------

 

set fileencodings=utf-8,gb18030,gbk,gb2312

set termencoding=utf-8

"set encoding=utf-8,gb18030

 

"---------------------------------------------

"定义函数SetTitle,自动插入文件头

func SetTitle()

if &filetype == 'c'

call setline(1, "#include <stdio.h>")

call setline(2, "#include <string.h>")

call setline(3, "")

call setline(4, "int main() {")

elseif &filetype == 'cpp'

call setline(1, "#include <iostream>")

call setline(2, "#include <cstdio>")

call setline(3, "#include <cstring>")

call setline(4, "#include <string>")

call setline(5, "#include <algorithm>")

call setline(6, "")

call setline(7, "using namespace std;")

call setline(8, "")

call setline(9, "int main() {")

endif

endfunc

 

set completeopt=longest,menu

"新建.c,.h,.sh,.java文件,自动插入文件头

autocmd BufNewFile *.[ch],*.sh,*.cpp,*.java exec ":call SetTitle()"

"--------------------------------------------- 

"定义CompileRun函数,用来调用进行编译和运行

func! CompileRun()

exec "w"

"C程序

if &filetype == 'c'

exec "!gcc % -g -o %<.exe"

exec "! ./%<.exe"

elseif &filetype == 'cpp'

exec "!g++ % -g -o %<.exe"

exec "! ./%<.exe"

"Java程序

elseif &filetype == 'java'

exec "!javac %"

exec "!java %<"

endif

endfunc

"结束定义CompileRun

"-------------------------

" ======= 编译 && 运行 ======= "

" 编译源文件

func! CompileCode()

    exec "w"

    if &filetype == "c"

        exec "!gcc -Wall -std=c99 %<.c -o %<"

    elseif &filetype == "cpp"

        exec "!g++ -Wall -std=c++98 %<.cpp -o %<"

    elseif &filetype == "java"

        exec "!javac %<.java"

    endif

endfunc

" 运行可执行文件

func! RunCode()

    exec "w"

    if &filetype == "c" || &filetype == "cpp" || &filetype == "haskell"

         exec "! ./%<"

    elseif &filetype == "java"

        exec "!java %<"

    endif

endfunc


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值