首先对vim进行配置,打开并编辑用户目录中的.vimrc文件
vim ~/.vimrc
基本配置,参考了原文链接:https://blog.csdn.net/qq_41467882/article/details/120274829的配置,下面的配置新建文件后,按下<F4>后可自动添加文件头注释,如果文件头已存在,按下<F4>会刷新Last modified时间和文件名。按下<F3>可打开新标签页。
syntax on
set cuc
set cul
set nu
set tabstop=4
set expandtab
set shiftwidth=4
set softtabstop=4
set autoindent
set completeopt=menu, preview, longest
autocmd FileType make set noexpandtab
map <F3>tabnew .<cr>
map <C-F3> \be
set foldenable
set foldmethod=manual
map <F4>call TitleDet()<cr>
function AddTitle()
call append(0,"timescale 1ns/1ps")
call append(1,"/*==================FILE HEADER=====================")
call append(2,"# Author: ****")
call append(3,"#")
call append(4,"# Department: ****")
call append(5,"#")
call append(6,"# Critical Timing:\t2024- -")
call append(7,"#")
call append(8,"# Last modified:\t". strftime("Y-%m-%d %H:M"))
call append (9,"#")
call append(10,"# Filename:\t\t\t". expand ("%:t"))
call append(11,"#")
call append(12,"# Description:\t\t". expand("%:t"))
call append(13,"#")
call append(14," VERSION DATE AUTHOR DESCRIPTOIN")
call append(15,"# 1.0 2024-XX-XX ****** initial")
call append(16,"#")
call append(17,"Synthesizable: YES")
call append(18,"#")
call append(19,"===================FILE HEADER======================*/")
call append(20,"")
call append(21,"module "expand("%:t:r"))
call append(22,"(")
call append(23,"")
call append(24,");")
call append(25,"")
call append(26,"")
call append(27,"endmodule")
echohl WarningMSG echo "Successful in adding the copyright."echohl None
endfunction
function UpdateTitle()
normal m'
execute '/#.*Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@'
normal ''
normal mk
execute '/#.*Filename:/s@:.*$@\=":\t\t".expand("%:t")@'
execute '/module/s@.*@\="module ".expand("%:t:r")@'
execute "noh"
normal 'k
echohl WarningMsg | echo "Successful in updating the copy right." | echohl None
endfunction
function TitleDet()
let n=1
while n < 17
let line = getline(n)
if line =~ '^\#\s*\S*Last\smodified:\S*.*$'
call UpdateTitle()
return
endif
let n = n + 1
endwhile
call AddTitle()
endfunction
新建并打开demo_top.v,按下<F4>,效果如图