custom vim functions

function! Git_status()

:new | 0read ! git status -s

endfunction

command! GitStatus :call Git_status() " List git status in new buffer


function! Git_status_cp()

:new | 0read ! git status -s | perl -ne 's/^\s*M\s+(.*)/cp \$REF_ROOT\/\1 \$REPO_ROOT\/\1/; print' | perl -ne 's/^\s*\?\?\s+(.*)/cp -i \$REF_ROOT\/\1 \$REPO_ROOT\/\1/; print'

endfunction

command GitStatusCp :call Git_status_cp() " Create copy script based on git modifiedd files



function! Git_status_cp_inline()

:%!git status -s | perl -ne 's/^\s*M\s+(.*)/cp \$REF_ROOT\/\1 \$REPO_ROOT\/\1/; print' | perl -ne 's/^\s*\?\?\s+(.*)/cp -i \$REF_ROOT\/\1 \$REPO_ROOT\/\1/; print'

endfunction

command GitStatusCpInline :call Git_status_cp_inline() " Create copy script inline based on git modifiedd files


function! InstGen()

let s:fname = 'temp'

w temp

!perl -p -i -e "s/\)\s*;/);/" temp

:new | 0read !perl ${HOME}/.vim/custom/tbGen/tbGen.pl -f temp -d

!rm temp temp_temp

:set syn=systemverilog

endfunction

command! InstGen :call InstGen() " Generate instantion template of system verilog module


function! InstAlign()

:'<,'>s/(/:(/

gv

:'<,'>s/)/:)/

gv

:'<,'>s/\/\//:\/\//

gv

:'<,'>!column -t -s ":"

endfunction

command! InstAlign :call InstAlign() " Generate instantion template of system verilog module

vnoremap <C-i> :<C-U>InstAlign<CR>


function! PortAlign()

:'<,'>s/\] *\[/][/

gv

:'<,'>s/logic *\(\w\)/logic [0:0] \1/

gv

:'<,'>s/_t *\(\w\)/_t [0:0] \1/

gv

:'<,'>s/ */ /g

gv

:'<,'>!column -t

gv

:'<,'>s/\[0:0\]/ /

endfunction

command! PortAlign :call PortAlign() " Align the SV port declaration

vnoremap <C-p> :<C-U>PortAlign<CR>


function! InstGenOutputOnly()

let s:fname = 'temp'

w temp

!perl -p -i -e "s/\)\s*;/);/" temp

:new | 0read !perl ${HOME}/.vim/custom/tbGen/tbGen_mod.pl -f temp -d

!rm temp temp_temp

:set syn=systemverilog

endfunction

command! InstGenOutputOnly :call InstGenOutputOnly() " Generate instantion template with output only declaration


function! TbGen()

let s:fname = 'temp'

:execute 'w' s:fname

!perl -p -i -e "s/\)\s*;/);/" temp

!perl ${HOME}/.vim/custom/tbGen/tbGen.pl -f temp -gentb

:execute '!rm' s:fname

:let tbName = "tb_".expand('%:t')

:execute 'sp' tbName

endfunction

command! TbGen :call TbGen() " Generate instantion template of system verilog module


function! UsefulCodeSegment()

echo 'Add rdy-val to signal:'

echo ' s/\(^ *output *\w\w* *\(\w\w*\)\),/\1,\r output logic \2_val,\r input logic \2_rdy,\r/'

echo ' s/\(^ *input *\w\w* *\(\w\w*\)\),/\1,\r input logic \2_val,\r output logic \2_rdy,\r/'

echo ' ia always_ff always_ff@(posedge clk,negedge rst_n)<CR>begin<CR> if(!rst_n)<CR> begin<CR> <CR> end<CR> else<CR> begin<CR> <CR> end<CR><CR>end<CR>'

echo ' :r ! git status -s'

echo ''

endfunction

command! UsefulCodeSegment :call UsefulCodeSegment() " Some useful piece of code


function! UsefulCommandSegment()

echo 'In gvimdiff:'

echo ' do - diff obtain'

echo ' dp - diff put'

echo " In visual mode, it needs diffget and diffput i.e. :'<,'>diffget"

echo ''

endfunction

command! UsefulCommandSegment :call UsefulCommandSegment() " Some useful commands


function! ListMyFunctions()

: !egrep "^ *command" ${HOME}/.vim/custom/vimFn/vimFn.vim | awk '{print $2":-->:"$0;}' | sed 's/command.*"//' | column -t -s ":"

endfunction

command! ListMyFunctions :call ListMyFunctions() " List all custom functions


function! SwapIO()

:%s/^\( *\)input /\1QQQQQQ/

:%s/^\( *\)output/\1input /

:%s/QQQQQQ/output/

endfunction

command! SwapIO :call SwapIO() " Swap input and output ports in system verilog file


function! CommentLine()

:s/\(.*\)/\/\/TBR \1/

endfunction

command! CommentLine :call CommentLine() " C style single line comment

map <c-m> :CommentLine<CR>


function! GoMod()

<C-]>

endfunction

command! GoMod :call GoMod() " Enter the module file - based on ctags