Skip to content

Make vim-plugin "Tagbar" to support Powershell

To make Tagbar supports PowerShell, do the followings

  1. Add g:tagbar_type_ps1 to .vimrc
  2. Add PowerShell language definition to ctags config file

For 1, add the following code to .vimrc

let g:tagbar_type_ps1 = {
    \ 'ctagstype' : 'powershell',
    \ 'kinds'     : [
        \ 'f:function',
        \ 'i:filter',
        \ 'a:alias'
    \ ]
\ }

For 2, the path to the ctags config file varies dependent on which ctags is used:

  • For Exuberant-ctags: $HOME/.ctags
    • (Linux) $HOME/.ctags.d/powershell.ctags
    • (Windows) $HOMEDRIVE$HOMEPATH/ctags.d/powershell.ctags
      • The document suggests "$HOMEDRIVE$HOMEPATH/.ctags.d", while the commit suggests "$HOMEDRIVE$HOMEPATH/ctags.d".

Create the ctags config fileĀ powershell.ctags and add the following code to the file:

--langdef=powershell
--langmap=powershell:.ps1.psm1
--regex-powershell=/^[Ff]unction[\t ]*([a-zA-Z0-9_-]+)/\1/f,function/
--regex-powershell=/^[Ff]ilter[\t ]*([a-zA-Z0-9_-]+)/\1/i,filter/
--regex-powershell=/^[sS]et-[Aa]lias[\t ]*([a-zA-Z0-9_-]+)/\1/a,alias/

REFERENCE