🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] # 新建文件模板配置 为了完成根据新建文件的后缀不同,使用不同的模板,我新建了`~/.vim/mconf/file_auto.vim`文件,特地用来配置文件模板的,该违建内容如下: ```vim "本文件配置vim新建文件时自动生成的内容" "=========== "配置新建文件的模板(自动化完成) "=========== "==============================================================================" "cpp文件自动生成模板" autocmd BufNewFile *.cpp exec ":call SetTitle()" func SetTitle() call setline(1,"/**") call append(line("."), " * Copyright (C) ".strftime("%Y")." All rights reserved.") call append(line(".")+1, " *") call append(line(".")+2, " * FileName :".expand("%:t")) call append(line(".")+3, " * Author :hpy") call append(line(".")+4, " * Email :yuan_hp@qq.com") call append(line(".")+5, " * Date :".strftime("%Y年%m月%d日")) call append(line(".")+6, " * Description :") call append(line(".")+7, " */") call append(line(".")+8, "") endfunc "自动将光标定位到末尾" "autocmd BufNewFile * normal G" "==============================================================================" "配置shell脚本新建时的模板" autocmd BufNewFile *.sh exec ":call SetShTitle()" func SetShTitle() call setline(1,"#!/usr/bin/env bash") call append(line("."), "#-------------------------------------------------------") call append(line(".")+1, "# FileName : ".expand("%:t")) call append(line(".")+2, "# Author :hpy") call append(line(".")+3, "# Date :".strftime("%Y年%m月%d日")) call append(line(".")+4, "# Description :") call append(line(".")+5, "#-------------------------------------------------------") call append(line(".")+6, "") endfunc "==============================================================================" "配置verilog脚本新建时的模板" autocmd BufNewFile *.v exec ":call SetVTitle()" func SetVTitle() call setline(1,"`timescale 1ns / 1ps") call append(line("."), "// ********************************************************************") call append(line(".")+1, "// FileName : ".expand("%:t")) call append(line(".")+2, "// Author :hpy") call append(line(".")+3, "// Email :yuan_hp@qq.com") call append(line(".")+4, "// Date :".strftime("%Y年%m月%d日")) call append(line(".")+5, "// Description :") call append(line(".")+6, "// --------------------------------------------------------------------") call append(line(".")+7, "module " .expand("%:r") ."(") call append(line(".")+8, " input clk, ") call append(line(".")+9, " input rst_n") call append(line(".")+10, ");") call append(line(".")+11, " ") call append(line(".")+12, "always@(posedge clk or negedge rst_n)") call append(line(".")+13, "begin") call append(line(".")+14, " if(!rst_n)begin") call append(line(".")+15, " ") call append(line(".")+16, " end ") call append(line(".")+17, " else begin ") call append(line(".")+18, " ") call append(line(".")+19, " end ") call append(line(".")+20, "end") call append(line(".")+21, " ") call append(line(".")+22, "endmodule") endfunc "==============================================================================" "配置tcl脚本新建时的模板" autocmd BufNewFile *.tcl exec ":call SetTclTitle()" func SetTclTitle() call setline(1,"#!/usr/bin/env tclsh") call append(line("."), "#-------------------------------------------------------") call append(line(".")+1, "# FileName : ".expand("%:t")) call append(line(".")+2, "# Author :hpy") call append(line(".")+3, "# Email :yuan_hp@qq.com") call append(line(".")+4, "# Date :".strftime("%Y年%m月%d日")) call append(line(".")+5, "# Description :") call append(line(".")+6, "#-------------------------------------------------------") call append(line(".")+7, "") endfunc "==============================================================================" "配置python3脚本新建时的模板" autocmd BufNewFile *.py exec ":call SetPyTitle()" func SetPyTitle() call setline(1,"#!/usr/bin/env python3") call append(line("."), "# -- coding:utf-8 --") call append(line(".")+1, "#-------------------------------------------------------") call append(line(".")+2, "# FileName : ".expand("%:t")) call append(line(".")+3, "# Author :hpy") call append(line(".")+4, "# Email :yuan_hp@qq.com") call append(line(".")+5, "# Date :".strftime("%Y年%m月%d日")) call append(line(".")+6, "# Description :") call append(line(".")+7, "#-------------------------------------------------------") call append(line(".")+8, "") endfunc "自动将光标定位到末尾" autocmd BufNewFile * normal G ``` # 编辑快捷键设置 为了提高编辑的效率,我新建了`~/.vim/mconf/key.vim`文件,主要配置了bash,verilog,tcl,python的一些编辑快捷键,并添加了铆点,使得可以尽量减少使用鼠标的需要。 该文件内容如下所示: ```vim "===================================================================" "===========" "配置markdown编辑时的快捷键" "===========" autocmd Filetype markdown inoremap // <Esc>/<CR>:nohlsearch<CR>c4l "加粗" autocmd Filetype markdown inoremap /b **** <Esc>F*hi "添加代码块" autocmd Filetype markdown inoremap /[ ```<Enter><++><Enter>```<Enter><Enter> "添加行内代码" autocmd Filetype markdown inoremap /e ``<++><Esc>F`i "===================================================================" "===========" "配置shell编辑时的快捷键" "===========" autocmd Filetype sh inoremap // <Esc>/<++><CR>:nohlsearch<CR>c4l "加粗" autocmd Filetype sh inoremap /e echo "<++>"<++><Esc>/<++><CR>:nohlsearch<CR>c4l "引用" autocmd Filetype sh inoremap /y $(<++>) <++><Esc>/<++><CR>:nohlsearch<CR>c4l "算数运算" autocmd Filetype sh inoremap /a $[<++>]<++><Esc>/<++><CR>:nohlsearch<CR>c4l "if流程" autocmd Filetype sh inoremap /i if [ <++> ];then<Enter><Tab><++><Enter>fi<Esc>/<++><CR>:nohlsearch<CR>c4l "case流程" autocmd Filetype sh inoremap /c case <++> in<Enter><Tab><++>)<++>;;<Enter>esac<Esc>/<++><CR>:nohlsearch<CR>c4l "单引号" autocmd Filetype sh inoremap ' ''<Esc>F'i "双引号" autocmd Filetype sh inoremap " ""<Esc>F"i "花括号" autocmd Filetype sh inoremap { {}<Esc>F}i "小括号" autocmd Filetype sh inoremap ( ()<Esc>F)i "中括号" autocmd Filetype sh inoremap [ []<Esc>F]i "字符串替换" autocmd Filetype sh inoremap /t ${/<++>/<++>}<++><Esc>F/F/i "===================================================================" "===========" "配置verilog编辑时的快捷键" "===========" autocmd Filetype verilog inoremap // <Esc>/<++><CR>:nohlsearch<CR>c4l "always语句" autocmd Filetype verilog inoremap /aa always@(<++>)<Enter>begin<Enter><Tab><++><Enter>end <Esc>/<++><CR>:nohlsearch<CR>c4l "if 语句" autocmd Filetype verilog inoremap /ii if()begin<++>end<Esc>F)i "else 语句" autocmd Filetype verilog inoremap /ee else beginend<++><Esc>Fei "initial 语句" autocmd Filetype verilog inoremap /in initial beginend<Esc>Fei "assign 语句" autocmd Filetype verilog inoremap ass assign = <++><Esc>F=i "module例化 设置" autocmd Filetype verilog inoremap /. .(<++>)<++><Esc>F(i "display 语句" autocmd Filetype verilog inoremap /dd $display()<++><Esc>F)i "parameter 语句" autocmd Filetype verilog inoremap /p parameter <++> = <++>;<Esc>/<++><CR>:nohlsearch<CR>c4l "localparam 语句" autocmd Filetype verilog inoremap /l localparam <++> = <++>;<Esc>/<++><CR>:nohlsearch<CR>c4l "reg 语句" autocmd Filetype verilog inoremap /r reg[ : 0 ] <++><Esc>F:i "wire 语句" autocmd Filetype verilog inoremap /w wire[ : 0 ] <++><Esc>F:i "常量 语句" autocmd Filetype verilog inoremap /d <++>'d<++><Esc>/<++><CR>:nohlsearch<CR>c4l "case 语句" autocmd Filetype verilog inoremap /cc case()<++>endcase<Esc>F)i "begin 语句" autocmd Filetype verilog inoremap /bb beginend<Esc>Fei "function 语句" autocmd Filetype verilog inoremap function function [ <++> : 0 ]<++>;<Enter><++><Enter>endfunction<Esc>/<++><CR>:nohlsearch<CR>c4l "中括号" autocmd Filetype verilog inoremap [ []<Esc>F]i "大括号" autocmd Filetype verilog inoremap { {}<Esc>F}i "小括号" autocmd Filetype verilog inoremap ( ()<Esc>F)i "===================================================================" "===========" "配置 python 编辑时的快捷键" "===========" autocmd Filetype python inoremap // <Esc>/<++><CR>:nohlsearch<CR>c4l "print 语句" autocmd Filetype python inoremap /p print()<++><Esc>F)i "多行注释" autocmd Filetype python inoremap /n '''<++>'''<++><Esc>/<++><CR>:nohlsearch<CR>c4l "if语句" autocmd Filetype python inoremap if if :<++><Esc>F:i "else语句" autocmd Filetype python inoremap else else: "elif语句" autocmd Filetype python inoremap elif elif :<++><Esc>F:i "while 语句" autocmd Filetype python inoremap while while :<++><Esc>F:i "for 语句" autocmd Filetype python inoremap for for <++> in <++> :<++><Esc>/<++><CR>:nohlsearch<CR>c4l "def 函数语句" autocmd Filetype python inoremap def def () :<++><Esc>F(i "input 语句" autocmd Filetype python inoremap input input()<++><Esc>F)i "中括号" autocmd Filetype python inoremap [ []<Esc>F]i "大括号" autocmd Filetype python inoremap { {}<Esc>F}i "小括号" autocmd Filetype python inoremap ( ()<Esc>F)i "单引号" autocmd Filetype python inoremap ' ''<Esc>F'i "双引号" autocmd Filetype python inoremap " ""<Esc>F"i ``` # 个人.vimrc配置文件 自己的vim配置文件,在这里用于备份,文件包括配置了字体,自动对齐,语法高亮,tab键设置,markdown预览插件,文件树插件,自动模板和按键快捷方式,自动完成等。 文件内容如下所示: ```vim set rtp+=~/.vim/bundle/Vundle.vim "显示行号 set nu "忽略大小写 set ignorecase "开启文件类型检测 filetype plugin indent on "不忽略大小写 "set noignorecase "开启高亮 syntax on "显示光标当前位置 set ruler "启用鼠标 set mouse=a "显示状态栏 set laststatus=2 "设置字体 set gfn=Noto\ Mono\ 12 "set guifont=Noto\ Mono\:h12 "设置配色方案 gotham256效果较好 "colorscheme industry "colorscheme gotham256 colorscheme gruvbox "设置深色背景 set background=dark "设置背景透明 hi Normal ctermfg=252 ctermbg=none "设置语言环境 set fileencodings=utf-8,gb2312,gb18030,gbk,ucs-bom,cp936,latin1 set enc=utf8 set fencs=utf8,gbk,gb2312,gb18030 "============ "设置缩进" "============ set smartindent " 开启新行时使用智能自动缩进 "set cindent " 按照C语言语法自动缩进 set shiftwidth=4 " 配置缩进空格数为4 set tabstop=4 " 配置TAB键移动距离为4个空格 set autoindent "自动对齐 "============ "设置语法折叠" "============ set foldenable " 开始折叠 set foldmethod=syntax " 设置语法折叠 set foldcolumn=0 " 设置折叠区域的宽度 setlocal foldlevel=1 " 设置折叠层数为 "======== "括号匹配" "======== "set showmatch " 插入括号时,短暂地跳转到匹配的对应括号 "set matchtime=2 " 短暂跳转到匹配括号的时间 "=========== "配置共用剪切板 "=========== set clipboard=unnamed "实现自动生成匹配的括号" "inoremap ( ()<LEFT> " inoremap { {}<LEFT> inoremap [ []<LEFT> "inoremap ' ''<LEFT> "inoremap " ""<LEFT> "inoremap < <><LEFT> "插件管理安装 call vundle#begin() Plugin 'gmarik/Vundle.vim' "加载nerdtree Plugin 'preservim/nerdtree' Plugin 'suan/vim-instant-markdown' "markdown预览插件 Plugin 'ferrine/md-img-paste.vim' "vim编辑markdown放图插件 call vundle#end() "配置开关nerdtree的快捷键 map <f3> :NERDTreeToggle<cr> "配置打开刷新nerdtree的快捷键 map <f4> :NERDTree<cr> "修改树的显示图标 let g:NERDTreeDirArrowExpandable = '+' let g:NERDTreeDirArrowCollapsible = '-' ""窗口位置 let g:NERDTreeWinPos='left' ""窗口尺寸 let g:NERDTreeSize=30 ""窗口是否显示行号 let g:NERDTreeShowLineNumbers=1 ""不显示隐藏文件 let g:NERDTreeHidden=0 "markdown图片插件配置 let g:mdip_imgdir = 'img' let g:mdip_imgname = 'image' "粘贴图片快捷键 autocmd FileType markdown nnoremap <silent> <C-p> :call mdip#MarkdownClipboardImage()<CR> "自定义函数 "执行shell的函数 第一个字母大写,小写时会自动运行 "在vim中使用不 :call Eshell() 可将正在编辑的文档执行 ./file命令 func Eshell() !./%< endfunction "nmap <silent> <C-B> :call Eshell()<CR>" "模板配置" source ~/.vim/mconf/file_auto.vim "各文件编辑时快捷键配置配置" source ~/.vim/mconf/key.vim ```