ps1.vim 2.6 KB

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