vim

Fork of vim, an acceptable text editor
git clone git://git.laack.co/vim.git
Log | Files | Refs | README | LICENSE

ps1.vim (2758B)


      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 "              2025 Jul 22 by phanium (use :hor term #17822)
      9 "              2026 Jul 10 by Vim Project (quote K argument, prevent command injection)
     10 "              2026 Sep 01 by Vim Project (use correct terminal feature test)
     11 
     12 " Only do this when not done yet for this buffer
     13 if exists("b:did_ftplugin") | finish | endif
     14 
     15 " Don't load another plug-in for this buffer
     16 let b:did_ftplugin = 1
     17 
     18 let s:cpo_save = &cpo
     19 set cpo&vim
     20 
     21 setlocal tw=0
     22 setlocal commentstring=#\ %s
     23 setlocal formatoptions=tcqro
     24 " Enable autocompletion of hyphenated PowerShell commands,
     25 " e.g. Get-Content or Get-ADUser
     26 setlocal iskeyword+=-
     27 
     28 " Change the browse dialog on Win32 and GTK to show mainly PowerShell-related files
     29 if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
     30 	let b:browsefilter =
     31 				\ "All PowerShell Files (*.ps1, *.psd1, *.psm1, *.ps1xml)\t*.ps1;*.psd1;*.psm1;*.ps1xml\n" .
     32 				\ "PowerShell Script Files (*.ps1)\t*.ps1\n" .
     33 				\ "PowerShell Module Files (*.psd1, *.psm1)\t*.psd1;*.psm1\n" .
     34 				\ "PowerShell XML Files (*.ps1xml)\t*.ps1xml\n"
     35 	if has("win32")
     36 		let b:browsefilter .= "All Files (*.*)\t*\n"
     37 	else
     38 		let b:browsefilter .= "All Files (*)\t*\n"
     39 	endif
     40 endif
     41 
     42 " Undo the stuff we changed
     43 let b:undo_ftplugin = "setlocal tw< cms< fo< iskeyword<" .
     44 			\ " | unlet! b:browsefilter"
     45 
     46 " Look up keywords by Get-Help:
     47 " check for PowerShell Core in Windows, Linux or MacOS
     48 if executable('pwsh') | let s:pwsh_cmd = 'pwsh'
     49   " on Windows Subsystem for Linux, check for PowerShell Core in Windows
     50 elseif exists('$WSLENV') && executable('pwsh.exe') | let s:pwsh_cmd = 'pwsh.exe'
     51   " check for PowerShell <= 5.1 in Windows
     52 elseif executable('powershell.exe') | let s:pwsh_cmd = 'powershell.exe'
     53 endif
     54 
     55 if exists('s:pwsh_cmd')
     56   if exists('*term_start')
     57     command! -buffer -nargs=1 GetHelp call term_start([s:pwsh_cmd, '-NoLogo', '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'RemoteSigned', '-Command', "Get-Help -Full '" . substitute(<q-args>, "'", "''", 'g') . "'" . (executable('less') ? ' | less' : '')])
     58   else
     59     command! -buffer -nargs=1 GetHelp echo system([s:pwsh_cmd, '-NoLogo', '-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'RemoteSigned', '-Command', "Get-Help -Full '" . substitute(<q-args>, "'", "''", 'g') . "'"])
     60   endif
     61   setlocal keywordprg=:GetHelp
     62   let b:undo_ftplugin ..= " | setl kp< | sil! delc -buffer GetHelp"
     63 endif
     64 
     65 let &cpo = s:cpo_save
     66 unlet s:cpo_save