- **
vi编辑器是Linux和Unix上最基本的文本编辑器,工作在字符模式下。由于不需要图形界面,vi是效率很高的文本编辑器。尽管在Linux上也有很多图形界面的编辑器可用,但vi在系统和服务器管理中的功能是那些图形编辑器所无法比拟的。所以为了更好的使用vi编辑器,可以对vi进行一些个性化的配置,方便我们编程开发使用。
**
vi配置文件的本质就是shell脚本语句的集合。
配置vi的步骤:
-
首先使用命令 cd ~ 回到用户家目录下。
- -
再使用命令 vi .vimrc打开vi的配置文件。
-
以下代码是我自己的配置文件代码,当然,你也可以根据自己的需要进行一些更改。
"当创建.h .c .hpp .cpp .mk .sh等文件时自动调用SetTitle 函数 autocmd BufNewFile *.[ch],*.hpp,*.cpp,Makefile,*.mk,*.sh exec ":call SetTitle()" " 加入注释 func SetComment() call setline(1,"/*================================================================") call append(line("."), "* Copyright (C) ".strftime("%Y")." Sangfor Ltd. All rights reserved.") call append(line(".")+1, "* ") call append(line(".")+2, "* 文件名称:".expand("%:t")) call append(line(".")+3, "* 创 建 者:duan") call append(line(".")+4, "* 创建日期:".strftime("%Y年%m月%d日")) call append(line(".")+5, "* 描 述:") call append(line(".")+6, "*") call append(line(".")+7, "================================================================*/") call append(line(".")+8, "") call append(line(".")+9, "") endfunc " 加入shell,Makefile注释 func SetComment_sh() call setline(3, "#================================================================") call setline(4, "# Copyright (C) ".strftime("%Y")." Sangfor Ltd. All rights reserved.") call setline(5, "# ") call setline(6, "# 文件名称:".expand("%:t")) call setline(7, "# 创 建 者:duan") call setline(8, "# 创建日期:".strftime("%Y年%m月%d日")) call setline(9, "# 描 述:") call setline(10, "#") call setline(11, "#========================================================= =======") call setline(12, "") call setline(13, "") endfunc " 定义函数SetTitle,自动插入文件头 func SetTitle() if &filetype == 'make' call setline(1,"") call setline(2,"") call SetComment_sh() elseif &filetype == 'sh' call setline(1,"#!/system/bin/sh") call setline(2,"") call SetComment_sh() else call SetComment() if expand("%:e") == 'hpp' call append(line(".")+10, "#ifndef _".toupper(expand("%:t:r"))."_H") call append(line(".")+11, "#define _".toupper(expand("%:t:r"))."_H") call append(line(".")+12, "#ifdef __cplusplus") call append(line(".")+13, "extern \"C\"") call append(line(".")+14, "{") call append(line(".")+15, "#endif") call append(line(".")+16, "") call append(line(".")+17, "#ifdef __cplusplus") call append(line(".")+18, "}") call append(line(".")+19, "#endif") call append(line(".")+20, "#endif //".toupper(expand("%:t:r"))."_H") elseif expand("%:e") == 'h' call append(line(".")+10, "#pragma once") elseif &filetype == 'c' call append(line(".")+10,"#include<stdio.h>") call append(line(".")+11,"#include<string.h>") call append(line(".")+12,"#include<stdlib.h>") call append(line(".")+13,"#include<math.h>") call append(line(".")+14,"") :16 elseif &filetype == 'cpp' call append(line(".")+10, "#include \"".expand("%:t:r").".h\"") endif endif endfunc set tabstop=4 set softtabstop=4 set shiftwidth=4 "set autoindent set smartindent inoremap ' ''<ESC>i inoremap " ""<ESC>i inoremap ( ()<ESC>i inoremap [ []<ESC>i inoremap { {<CR>}<ESC>O set number