版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://bb2hh.blogbus.com/logs/31100127.html
下载地址:http://bb2hh.blogbus.com/files/12271773140.vim
只要了几个功能:)
更新了下,把begin放在了下面。
同时增加了一个功能。就是按下保存会自动修改Last Modifited的时间:)比较实用:)使用此功能在启动文件中加入:autocmd BufWritePre,FileWritePre *.v ks|call LastModified()|'s
vimrc中修改调用命令的快捷键:
:inoremap <A-a> <ESC>:Allpn<CR>
map <A-a> :Allpn<CR>
:inoremap <A-c> <ESC>:Allcom<CR>
map <A-c> :Allcom<CR>
:inoremap <A-z> <ESC>:Aheader<CR>
map <A-z> :Aheader<CR>
:inoremap <A-l> <ESC>:Acontent<CR>
map <A-l> :Acontent<CR>
1.当输入<=的时候会自动将<=改成<= #1,
2.当按下Alt+z(可以自己在vimrc中修改)的时候会自动加入会自动加入头信息,如下:
可以去下载的vim插件中,修改头信息:)
当修改完以后,按下保存,或者自己设置的保存热键,会变成如下:(修改时间自动调整)
3.当按下Alt+a的时候,会自动生成时序电路的always
这里要首先声明本module的clock和reset,不支持多时钟:)
当按下alt+c的时候会自动生成组合逻辑的always:)
按下alt+l会自动加入注释
附件:vlog_plugin.vim
if exists("b:vlog_plugin")
finish
endif
let b:vlog_plugin = 1
iabbrev <= <= #1
command Aheader :call AddHeader()
command Allpn :call AddAlways("posedge", "negedge")
command Allcom :call AddAlways("", "")
command Acontent :call AddContent()
"===============================================================
" Add File Header
"===============================================================
function AddHeader()
call append(0, "//================================================================================")
call append(1, "// Created by : KTT Ltd.com")
call append(2, "// Filename : ".expand("%"))
call append(3, "// Author : Python_Wang")
call append(4, "// Created On : ".strftime("%Y-%m-%d %H:%M"))
call append(5, "// Last Modified : ")
call append(6, "// Update Count : ".strftime("%Y-%m-%d %H:%M"))
call append(7, "// Description : ")
call append(8, "// ")
call append(9, "// ")
call append(10, "//================================================================================")
endfunction
"===============================================================
"
"===============================================================
function AddContent()
let curr_line = line(".")
call append(curr_line, "//================================================================================")
call append(curr_line+1, "//Function : ")
"call append(curr_line+2, "// ")
call append(curr_line+2, "//Arguments : ")
"call append(curr_line+4, "// ")
call append(curr_line+3, "//================================================================================")
endfunction
"===============================================================
" Add an always statement
"===============================================================
function AddAlways(clk_edge, rst_edge)
for line in getline(1, line("$"))
if line =~ '^\s*\<input\>.*//\s*\<clock\>\s*$'
let line = substitute(line, '^\s*\<input\>\s*', "", "")
let clk = substitute(line, '\s*;.*$', "", "")
elseif line =~ '^\s*\<input\>.*//\s*\<reset\>\s*$'
let line = substitute(line, '^\s*\<input\>\s*', "", "")
let rst = substitute(line, '\s*;.*$', "", "")
elseif line =~ '^\s*\<reg\>.*//\s*\<clock\>\s*$'
let line = substitute(line, '^\s*\<reg\>\s*', "", "")
let clk = substitute(line, '\s*;.*$', "", "")
elseif line =~ '^\s*\<reg\>.*//\s*\<reset\>\s*$'
let line = substitute(line, '^\s*\<reg\>\s*', "", "")
let rst = substitute(line, '\s*;.*$', "", "")
endif
endfor
let curr_line = line(".")
if a:clk_edge == "posedge" && a:rst_edge == "posedge"
call append(curr_line, "always @(posedge ".clk." or posedge ".rst.")")
call append(curr_line+1, "begin")
call append(curr_line+2, " if (".rst.") begin")
call append(curr_line+3, " end")
call append(curr_line+4, " else begin")
call append(curr_line+5, " end")
call append(curr_line+6, "end")
elseif a:clk_edge == "negedge" && a:rst_edge == "posedge"
call append(curr_line, "always @(negedge ".clk." or posedge ".rst.")")
call append(curr_line+1, "begin")
call append(curr_line+2, " if (".rst.") begin")
call append(curr_line+3, " end")
call append(curr_line+4, " else begin")
call append(curr_line+5, " end")
call append(curr_line+6, "end")
elseif a:clk_edge == "posedge" && a:rst_edge == "negedge"
call append(curr_line, "always @(posedge ".clk." or negedge ".rst.")")
call append(curr_line+1, "begin")
call append(curr_line+2, " if (!".rst.") begin")
call append(curr_line+3, " end")
call append(curr_line+4, " else begin")
call append(curr_line+5, " end")
call append(curr_line+6, "end")
elseif a:clk_edge == "negedge" && a:rst_edge == "negedge"
call append(curr_line, "always @(negedge ".clk." or negedge ".rst.")")
call append(curr_line+1, "begin")
call append(curr_line+2, " if (!".rst.") begin")
call append(curr_line+3, " end")
call append(curr_line+4, " else begin")
call append(curr_line+5, " end")
call append(curr_line+6, "end")
elseif a:clk_edge == "posedge" && a:rst_edge == ""
call append(curr_line, "always @(posedge ".clk.")")
call append(curr_line+1, "begin")
call append(curr_line+2, "end")
elseif a:clk_edge == "negedge" && a:rst_edge == ""
call append(curr_line, "always @(negedge ".clk.")")
call append(curr_line+1, "begin")
call append(curr_line+2, "end")
else
call append(curr_line, "always @(*)")
call append(curr_line+1, "begin")
call append(curr_line+2, "end")
endif
endfunction
"autocmd BufWritePre,FileWritePre *.v ks|call LastModified()|'s
fun LastModified()
let l = line("$")
exe "1," . l . "g/Last Modified :/s/Last Modified :.*/Last Modified : " .
\ strftime("%Y-%m-%d %H:%M")
endfun
文章评论(0条评论)
登录后参与讨论