ps1.vim 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. " Vim filetype plugin file
  2. " Language: Windows PowerShell
  3. " URL: https://github.com/PProvost/vim-ps1
  4. " Last Change: 2021 Apr 02
  5. " Only do this when not done yet for this buffer
  6. if exists("b:did_ftplugin") | finish | endif
  7. " Don't load another plug-in for this buffer
  8. let b:did_ftplugin = 1
  9. let s:cpo_save = &cpo
  10. set cpo&vim
  11. setlocal tw=0
  12. setlocal commentstring=#%s
  13. setlocal formatoptions=tcqro
  14. " Enable autocompletion of hyphenated PowerShell commands,
  15. " e.g. Get-Content or Get-ADUser
  16. setlocal iskeyword+=-
  17. " Change the browse dialog on Win32 to show mainly PowerShell-related files
  18. if has("gui_win32")
  19. let b:browsefilter =
  20. \ "All PowerShell Files (*.ps1, *.psd1, *.psm1, *.ps1xml)\t*.ps1;*.psd1;*.psm1;*.ps1xml\n" .
  21. \ "PowerShell Script Files (*.ps1)\t*.ps1\n" .
  22. \ "PowerShell Module Files (*.psd1, *.psm1)\t*.psd1;*.psm1\n" .
  23. \ "PowerShell XML Files (*.ps1xml)\t*.ps1xml\n" .
  24. \ "All Files (*.*)\t*.*\n"
  25. endif
  26. " Look up keywords by Get-Help:
  27. " check for PowerShell Core in Windows, Linux or MacOS
  28. if executable('pwsh') | let s:pwsh_cmd = 'pwsh'
  29. " on Windows Subsystem for Linux, check for PowerShell Core in Windows
  30. elseif exists('$WSLENV') && executable('pwsh.exe') | let s:pwsh_cmd = 'pwsh.exe'
  31. " check for PowerShell <= 5.1 in Windows
  32. elseif executable('powershell.exe') | let s:pwsh_cmd = 'powershell.exe'
  33. endif
  34. if exists('s:pwsh_cmd')
  35. if !has('gui_running') && executable('less') &&
  36. \ !(exists('$ConEmuBuild') && &term =~? '^xterm')
  37. " For exclusion of ConEmu, see https://github.com/Maximus5/ConEmu/issues/2048
  38. command! -buffer -nargs=1 GetHelp silent exe '!' . s:pwsh_cmd . ' -NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command Get-Help -Full "<args>" | ' . (has('unix') ? 'LESS= less' : 'less') | redraw!
  39. elseif has('terminal')
  40. command! -buffer -nargs=1 GetHelp silent exe 'term ' . s:pwsh_cmd . ' -NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command Get-Help -Full "<args>"' . (executable('less') ? ' | less' : '')
  41. else
  42. command! -buffer -nargs=1 GetHelp echo system(s:pwsh_cmd . ' -NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command Get-Help -Full <args>')
  43. endif
  44. endif
  45. setlocal keywordprg=:GetHelp
  46. " Undo the stuff we changed
  47. let b:undo_ftplugin = "setlocal tw< cms< fo< iskeyword< keywordprg<" .
  48. \ " | unlet! b:browsefilter"
  49. let &cpo = s:cpo_save
  50. unlet s:cpo_save