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