Tuesday, November 17, 2009

Using Vim and Ctags to edit Powershell

To use vim with a new language you need a few things firstly: indent, syntax and file type plugins. These can be found here .

Next, you need ctags support (this is how vim implements 'goto function'). Ctags doesn't natively support powershell yet, but luckily ctags supports adding languages dynamically. From the command line you can add powershell support to ctags via:

c:\> ctags.exe --langdef=powershell --langmap=powershell:.ps1 --regex-powershell="/^function[\t ]*([a-zA-Z0-9_]+)/\1/d,definition/" --regex-powershell="/^filter[\t ]*([a-zA-Z0-9_]+)/\1/d,definition/" * 

Alternatively you can pass this information into your ctags configuration file. Note that on the command line regexps are in quotes.

C:\> type %USERPROFILE%\ctags.cnf
--langdef=powershell
--langmap=powershell:.ps1
--langmap=powershell:.psm1
--regex-powershell=/^function[\t ]*([a-zA-Z0-9_-]+)/\1/d,definition/
--regex-powershell=/^filter[\t ]*([a-zA-Z0-9_-]+)/\1/d,definition/


Happy PS1Viming.

No comments: