gvim usage

自動寫入tile

autocmd BufNewFile *.py,*.pl exec ":call SetTitle()"
"新建python
"定義函數SetTitle,自動插入文件頭
func SetTitle()  
    "如果文件類型爲.python文件  
    if &filetype == 'python'  
        call setline(1, "\#!/usr/bin/env python")  
        call append(line("."), "\# -*- coding=utf8 -*-")  
    endif
    if &filetype == 'perl'  
        call setline(1, "\#!/usr/bin/env perl")  
        call append(line("."), "##################################")  
    endif    
    call append(line(".")+1, "\# Author: vinson")  
    call append(line(".")+2, "\# Created Time : ".strftime("%c"))  
    call append(line(".")+3, "\# File Name: ".expand("%"))  
    call append(line(".")+4, "\# Description:")  
    call append(line(".")+5, "##################################")  

endfunc 

comment:

  可以通過:set filetype 查看當前文件類型

匹配begin / end

可以先參看

runtime macros/matchit.vim

在.vimrc中添加

" Let the matchit plugin know what items can be matched.
"
runtime! macro/matchit.vim
if exists('loaded_matchit')
let b:match_ignorecase=0
let b:match_words=
  \ '\<begin\>:\<end\>,' .
  \ '\<if\>:\<else\>,' .
  \ '\<module\>:\<endmodule\>,' .
  \ '\<class\>:\<endclass\>,' .
  \ '\<program\>:\<endprogram\>,' .
  \ '\<clocking\>:\<endclocking\>,' .
  \ '\<property\>:\<endproperty\>,' .
  \ '\<sequence\>:\<endsequence\>,' .
  \ '\<package\>:\<endpackage\>,' .
  \ '\<covergroup\>:\<endgroup\>,' .
  \ '\<primitive\>:\<endprimitive\>,' .
  \ '\<specify\>:\<endspecify\>,' .
  \ '\<generate\>:\<endgenerate\>,' .
  \ '\<interface\>:\<endinterface\>,' .
  \ '\<function\>:\<endfunction\>,' .
  \ '\<task\>:\<endtask\>,' .
  \ '\<case\>\|\<casex\>\|\<casez\>:\<endcase\>,' .
  \ '\<fork\>:\<join\>\|\<join_any\>\|\<join_none\>,' .
  \ '`ifdef\>:`else\>:`endif\>,' .
  \ '\<generate\>:\<endgenerate\>,'
endif

 

 

systemverilog gvim 摺疊

 

setlocal foldmethod=expr
set foldexpr=MyFoldExpr(v:lnum)
function! MyFoldExpr(line)
   let str = getline(a:line)   
   if str =~ '^\s*task\s' || str =~ '^\s*function\s'
      return 'a1'   
   elseif str =~ '^\s*endtask' || str =~ '^\s*endfunction'
      return 's1'
   elseif str=~'`uvm_\w*_utils_begin'
      return 'a1'   
   elseif str=~'`uvm_\w*_utils_end'
      return 's1'
   elseif str =~ '\sbegin\s*'
      return 'a2'
   elseif str =~ '\send\s*'
      return 's2'
   else
       return -1
   endif
endfunction

 

table換成空格

set tabstop=2     " (ts) width (in spaces) that a <tab> is displayed as
set expandtab     " (et) expand tabs to spaces (use :retab to redo entire file)
set shiftwidth=2  " (sw) width (in spaces) used in each step of autoindent (aswell as << and >>)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章