对vim编译器的实用配置修改

对vim编译器的实用配置

输入vim ~/.vimrc,将下面的代码补充到 ~/.vimrc中,行底模式下输入:wq保存退出,使文件生效。

" 显示行号
set number

" 设置Tab键的宽度
set tabstop=4

" 设置自动缩进
set autoindent

" 设置自动缩进的宽度
set shiftwidth=4

" 设置智能缩进
set smartindent

" 设置不备份
set nobackup

" 设置不产生临时文件
set noswapfile

" 在插入模式下快速地返回正常模式
imap jj <ESC>

" 定义保存退出函数
func! SaveExit()
exec "wq"
endfunc

" 映射Ctrl+z键调用保存退出函数
map <C-z> :call SaveExit()<CR>
imap <C-z> <ESC> :call SaveExit()<CR>
vmap <C-z> <ESC> :call SaveExit()<CR>

" 定义保存编译并执行代码函数
func! ComplieCode()
exec "w"
if &filetype == "c"
exec "!gcc -std=gnu99 % -lm && ./a.out"
endif
endfunc

" 映射Ctrl+x键调用编译并执行函数
map <C-x> :call ComplieCode()<CR>
imap <C-x> <ESC> :call ComplieCode()<CR>
vmap <C-x> <ESC> :call ComplieCode()<CR>

" 定义添加头文件和Main函数
func! InsertMain()
if &filetype == "c"
call setline(1,"#include <stdio.h>")
call setline(2,"")
call setline(3,"int main(int argc,const char* argv[])")
call setline(4,"{")
call setline(5,"\t")
call setline(6,"}")
exec "5"
endif
endfunc
map <C-p> :call InsertMain()<CR>i<TAB>


" 自动添加头文件卫士
func! InsertIfndef()
call setline(1,"#ifndef ".toupper(expand("%:t:r"))."_H")
call setline(2,"#define ".toupper(expand("%:t:r"))."_H")
call setline(3,"")
call setline(4,"#endif//".toupper(expand("%:t:r"))."_H")
endfunc

autocmd BufNewFile *.h :call InsertIfndef()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值