ps1.vim 2.4 KB

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