vi编程文件配置教程(Linux下)
作者:互联网
1.通过gedit .rmvic进入vi编程配置文件,将下面的指令复制粘贴进去保存退出就可以了
(可以根据需要修改其中的名字,邮箱等)
"set mouse-=a
set nu
syntax on
syntax enable
colorscheme desert
" TagList
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
" WinManager
let g:winManagerWindowLayout='FileExplorer|TagList'
nmap wm :WMToggle<cr>
" Omnicompletion
set nocp
filetype plugin indent on
set completeopt=longest,menu
" Indent
set smartindent
set expandtab
" 自动缩进
set autoindent
set cindent
" Tab键的宽度
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
" 将tab替换为空格
nmap tt :%s/\t/ /g<CR>
set foldenable " 允许折叠
set foldmethod=manual " 手动折叠
nmap <C-\>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-\>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-\>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-\>d :cs find d <C-R>=expand("<cword>")<CR><CR>
autocmd BufNewFile *.[ch],*.hpp,*.cpp exec ":call SetTitle()"
"加入注释
func SetComment()
call setline(1,"/*===============================================")
call append(line("."), "* 文件名称:".expand("%:t"))
call append(line(".")+1, "* 创 建 者: 张城 ")
call append(line(".")+2, "* 邮箱:zhangc_cd@hqyj.com ")
call append(line(".")+3, "* 创建日期:".strftime("%Y年%m月%d日"))
call append(line(".")+4, "* 描 述:")
call append(line(".")+5, "================================================*/")
endfunc
"定义函数SetTitle,自动插入文件头
func SetTitle()
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, "#endif")
call append(line(".")+10, "")
call append(line(".")+10, "#ifndef _".toupper(expand("%:t:r"))."_H")
call append(line(".")+11, "#define _".toupper(expand("%:t:r"))."_H")
elseif &filetype == 'c'
" call append(line(".")+10,"#include \<strings.h\>")
" call append(line(".")+10,"#include \<stdlib.h\>")
" call append(line(".")+10,"#include \<string.h\>")
call append(line(".")+6,"#include \<stdio.h\>")
call append(line(".")+7,"")
call append(line(".")+8,"int main(int argc, char *argv[])")
call append(line(".")+9,"{ " )
call append(line(".")+10,"" )
call append(line(".")+11," return 0;")
call append(line(".")+12,"} ")
elseif &filetype == 'cpp'
call append(line(".")+10,"#include \<iostream\>")
call append(line(".")+10,"using namespace std;")
endif
endfunc
"新建文件后,自动定位到文件第10行
autocmd BufNewFile * normal 10gg
set termencoding=utf-8
set encoding=utf8
set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030
新建界面格式如下
1 /*===============================================
2 * 文件名称:1.c
3 * 创 建 者: lfs
4 * 邮箱:xxx.com
5 * 创建日期:2022年02月27日
6 * 描 述:
7 ================================================*/
8 #include <stdio.h>
9
10 int main(int argc, char *argv[])
11 {
12
13 return 0;
14 }
标签:10,set,vi,编程,call,expand,Linux,line,append 来源: https://blog.csdn.net/Flow_river/article/details/123179413