| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 
 | command! -range -nargs=0 Vdfmt call FormatVerilogSignalDeclaration()
 function! FormatVerilogSignalDeclaration()
 
 let start_pos = getpos("'<")
 let end_pos = getpos("'>")
 
 
 let lines = getline(start_pos[1], end_pos[1])
 
 
 for i in range(len(lines))
 let line = lines[i]
 let new_line = substitute(line, '^\s*\(wire\|reg\)', '   \1', '')
 let lines[i] = new_line
 endfor
 
 
 for i in range(len(lines))
 let line = lines[i]
 let new_line = substitute(line, '^\s*\(input\|output\|inout\)', '   \1', '')
 let lines[i] = new_line
 endfor
 
 
 for i in range(len(lines))
 let line = lines[i]
 let new_line1 = substitute(line, 'input\s\+wire', 'input  wire', '')
 let new_line2 = substitute(new_line1, 'output\s\+wire', 'output wire', '')
 let new_line3 = substitute(new_line2, 'output\s\+reg', 'output reg', '')
 let lines[i] = new_line3
 endfor
 
 
 for i in range(len(lines))
 let line = lines[i]
 let new_line1 = substitute(line, 'wire\s\+\[', 'wire [', '')
 let new_line2 = substitute(new_line1, 'reg\s\+\[', 'reg  [', '')
 let lines[i] = new_line2
 endfor
 
 
 for i in range(len(lines))
 let line = lines[i]
 let line = substitute(line, '\[\(\%(\]\@!.\)*\)\]',
 \ '\=printf("[%s]", substitute(submatch(1), " ", "", "g"))', 'g')
 let lines[i] = line
 endfor
 
 
 call setline(start_pos[1], lines)
 
 
 execute "normal! gv"
 execute ":'<,'>Tabularize /\\(wire\\|reg\\)\\s*\\(\\[.*\\]\\)\\?\\s*\\zs\\w\\+/"
 
 
 execute "normal! gv"
 execute ":'<,'>Tabularize /\\(;\\|,\\)/"
 
 endfunction
 
 |