Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #10839: Add powershell syntax highlighting to vim in rtf #103

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
67 changes: 67 additions & 0 deletions scripts/files/.vim/bundle/vim-ps1/README.markdown
@@ -0,0 +1,67 @@
ps1.vim
=======

If you are a Windows PowerShell user who uses Vim or Gvim for editing scripts,
then this plugin is for you.

It provides nice syntax coloring and indenting for Windows PowerShell (.ps1)
files, and also includes a filetype plugin so Vim can autodetect your PS1 scripts.

Includes contributions by:

* Jared Parsons <jaredp@beanseed.org>
* Heath Stewart <heaths@microsoft.com>
* Michael B. Smith
* Alexander Kostikov

Installation
------------

Copy the included directories into your .vim or vimfiles directory.

Or even better, use pathogen and simply pull it in like this:

cd ~/.vim/bundle
git clone https://github.com/PProvost/vim-ps1.git


Comments and Suggestions
------------------------

Please follow, fork or submit issues on [GitHub](https://github.com/PProvost/vim-ps1) and if you
find it useful, please vote for it on [vim.org](http://www.vim.org/scripts/script.php?script_id=1327).

License
-------

Copyright 2005-2012 Peter Provost

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Version History
---------------

* v2.9 (2012-03-08) Included tomasr's changes
* v2.81 (2012-03-05) Fixed a dumb typo
* v2.8 (2012-03-05) Better number scanning, multiline comments, missing keywords and constants
* v2.7 (2008-09-22) Begin, process & end keywords. Better highlighting of foreach and where
* v2.6 (2007-03-05) Added unary -not operator
* v2.5 (2007-03-03) Updates for here-strings, comment todos, other small cleanups
* v2.4 (2007-03-02) Added elseif keyword
* v2.3 (2007-02-27) Added param keyword
* v2.2 (2007-02-19) Missing keywords
* v2.1 (2006-07-31) Update for renaming
* v2.0 (2005-12-21) Big update from Jared Parsons
* v1.3 (2005-12-20) Updates to syntax elements
* v1.2 (2005-08-13) Fix foreach and while problem
* v1.1 (2005-08-12) Initial release
16 changes: 16 additions & 0 deletions scripts/files/.vim/bundle/vim-ps1/doc/ps1.txt
@@ -0,0 +1,16 @@
*ps1.txt* A Windows PowerShell syntax plugin for Vim

Author: Peter Provost <http://www.github.com/PProvost>
License: Apache 2.0
Version: 2.9

INTRODUCTION *ps1-syntax*

This plugin provides Vim syntax, indent and filetype detection for Windows
PowerShell.

ABOUT *ps1-about*

Grab the latest version or report a bug on GitHub:

http://github.com/PProvost/vim-ps1
3 changes: 3 additions & 0 deletions scripts/files/.vim/bundle/vim-ps1/doc/tags
@@ -0,0 +1,3 @@
ps1-about ps1.txt /*ps1-about*
ps1-syntax ps1.txt /*ps1-syntax*
ps1.txt ps1.txt /*ps1.txt*
9 changes: 9 additions & 0 deletions scripts/files/.vim/bundle/vim-ps1/ftdetect/ps1.vim
@@ -0,0 +1,9 @@
" Vim ftdetect plugin file
" Language: Windows PowerShell
" Maintainer: Peter Provost <peter@provost.org>
" Version: 2.9
" Project Repository: https://github.com/PProvost/vim-ps1
" Vim Script Page: http://www.vim.org/scripts/script.php?script_id=1327

au BufNewFile,BufRead *.ps1 set ft=ps1
au BufNewFile,BufRead *.psm1 set ft=ps1
26 changes: 26 additions & 0 deletions scripts/files/.vim/bundle/vim-ps1/ftplugin/ps1.vim
@@ -0,0 +1,26 @@
" Vim filetype plugin file
" Language: Windows PowerShell
" Maintainer: Peter Provost <peter@provost.org>
" Version: 2.9
" Project Repository: https://github.com/PProvost/vim-ps1
" Vim Script Page: http://www.vim.org/scripts/script.php?script_id=1327

" Only do this when not done yet for this buffer
if exists("b:did_ftplugin") | finish | endif

" Don't load another plug-in for this buffer
let b:did_ftplugin = 1

setlocal tw=0
setlocal commentstring=#%s
setlocal formatoptions=tcqro

" Change the browse dialog on Win32 to show mainly PowerShell-related files
if has("gui_win32")
let b:browsefilter = "PowerShell Files (*.ps1)\t*.ps1\n" .
\ "All Files (*.*)\t*.*\n"
endif

" Undo the stuff we changed
let b:undo_ftplugin = "setlocal tw< cms< fo<" .
\ " | unlet! b:browsefilter"
17 changes: 17 additions & 0 deletions scripts/files/.vim/bundle/vim-ps1/indent/ps1.vim
@@ -0,0 +1,17 @@
" Vim indent file
" Language: Windows PowerShell
" Maintainer: Peter Provost <peter@provost.org>
" Version: 2.9
" Project Repository: https://github.com/PProvost/vim-ps1
" Vim Script Page: http://www.vim.org/scripts/script.php?script_id=1327"

" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1

" PS indenting is like indenting C
setlocal cindent cinoptions& cinoptions+=+0

let b:undo_indent = "setl cin<"
152 changes: 152 additions & 0 deletions scripts/files/.vim/bundle/vim-ps1/syntax/ps1.vim
@@ -0,0 +1,152 @@
" Vim syntax file
" Language: Windows PowerShell
" Maintainer: Peter Provost <peter@provost.org>
" Version: 2.9
" Project Repository: https://github.com/PProvost/vim-ps1
" Vim Script Page: http://www.vim.org/scripts/script.php?script_id=1327"

" Compatible VIM syntax file start
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif

" PowerShell doesn't care about case
syn case ignore

" Sync-ing method
syn sync minlines=100

" Certain tokens can't appear at the top level of the document
syn cluster ps1NotTop contains=@ps1Comment,ps1CDocParam,ps1Function

" Comments and special comment words
syn keyword ps1CommentTodo TODO FIXME XXX TBD HACK NOTE contained
syn match ps1CDocParam /.*/ contained
syn match ps1CommentDoc /^\s*\zs\.\w\+\>/ nextgroup=ps1CDocParam contained
syn match ps1CommentDoc /#\s*\zs\.\w\+\>/ nextgroup=ps1CDocParam contained
syn match ps1Comment /#.*/ contains=ps1CommentTodo,ps1CommentDoc
syn region ps1Comment start="<#" end="#>" contains=ps1CommentTodo,ps1CommentDoc

" Language keywords and elements
syn keyword ps1Conditional if else elseif switch default
syn keyword ps1Repeat while for do until break continue foreach in
syn match ps1Repeat /\<foreach\>/ nextgroup=ps1Block skipwhite
syn match ps1Keyword /\<while\>/ nextgroup=ps1Block skipwhite
syn match ps1Keyword /\<where\>/ nextgroup=ps1Block skipwhite

syn keyword ps1Exception begin process end exit
syn keyword ps1Keyword try catch finally throw
syn keyword ps1Keyword return filter in trap param data dynamicparam
syn match ps1Keyword /&/
syn keyword ps1Constant $true $false $null
syn match ps1Constant +\$?+
syn match ps1Constant +\$_+
syn match ps1Constant +\$\$+
syn match ps1Constant +\$^+

" Keywords reserved for future use
syn keyword ps1Keyword class define from using var

" Functions and Cmdlets
syn match ps1Cmdlet /\w\+-\w\+/
syn keyword ps1Keyword function nextgroup=ps1Function skipwhite
syn keyword ps1Keyword filter nextgroup=ps1Function skipwhite
syn match ps1Function /\w\+-*\w*/ contained

" Type declarations
syn match ps1Type /\[[a-z0-9_:.]\+\(\[\]\)\?\]/
syn match ps1StandaloneType /[a-z0-9_.]\+/ contained
syn keyword ps1Scope global local private script contained

" Variables and other user defined items
syn match ps1Variable /\$\w\+/
syn match ps1Variable /\${\w\+:\\\w\+}/
syn match ps1ScopedVariable /\$\w\+:\w\+/ contains=ps1Scope
syn match ps1VariableName /\w\+/ contained

" Operators all start w/ dash
syn match ps1OperatorStart /-c\?/ nextgroup=ps1Operator
syn keyword ps1Operator eq ne ge gt lt le like notlike match notmatch replace split /contains/ notcontains contained
syn keyword ps1Operator ieq ine ige igt ile ilt ilike inotlike imatch inotmatch ireplace isplit icontains inotcontains contained
syn keyword ps1Operator ceq cne cge cgt clt cle clike cnotlike cmatch cnotmatch creplace csplit ccontains cnotcontains contained
syn keyword ps1Operator is isnot as join contained
syn keyword ps1Operator and or not xor band bor bnot bxor contained
syn keyword ps1Operator f contained

" Regular Strings
" These aren't precisely correct and could use some work
syn region ps1String start=/"/ skip=/`"/ end=/"/ contains=@ps1StringSpecial
syn region ps1String start=/'/ skip=/''/ end=/'/

" Here-Strings
syn region ps1String start=/@"$/ end=/^"@$/ contains=@ps1StringSpecial
syn region ps1String start=/@'$/ end=/^'@$/

" Interpolation
syn match ps1Escape /`./ contained
syn region ps1Interpolation matchgroup=ps1InterpolationDelimiter start="$(" end=")" contained contains=ALLBUT,@ps1NotTop
syn region ps1NestedParentheses start="(" skip="\\\\\|\\)" matchgroup=ps1Interpolation end=")" transparent contained
syn cluster ps1StringSpecial contains=ps1Escape,ps1Interpolation,ps1Variable,ps1Boolean,ps1Constant,ps1BuiltIn

" Numbers
" syn match ps1Number /\<[0-9]\+/
syn match ps1Number "\<\(0[xX]\x\+\|\d\+\)\([MGTP][B]\)\=\>"
syn match ps1Number "\(\<\d\+\.\d*\|\.\d\+\)\([eE][-+]\=\d\+\)\=[dD]\="
syn match ps1Number "\<\d\+[eE][-+]\=\d\+[dD]\=\>"
syn match ps1Number "\<\d\+\([eE][-+]\=\d\+\)\=[dD]\>"

" Constants
syn match ps1Boolean "$\%(true\|false\)\>"
syn match ps1Constant /\$null\>/
syn match ps1BuiltIn "$^\|$?\|$_\|$\$"
syn match ps1BuiltIn "$\%(args\|error\|foreach\|home\|input\)\>"
syn match ps1BuiltIn "$\%(match\(es\)\?\|myinvocation\|host\|lastexitcode\)\>"
syn match ps1BuiltIn "$\%(ofs\|shellid\|stacktrace\)\>"

" Folding blocks
syn region ps1Block start=/{/ end=/}/ transparent fold

" Setup default color highlighting
if version >= 508 || !exists("did_ps1_syn_inits")
if version < 508
let did_ps1_syn_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif

HiLink ps1Number Number
HiLink ps1Block Block
HiLink ps1Exception Exception
HiLink ps1Constant Constant
HiLink ps1String String
HiLink ps1Escape SpecialChar
HiLink ps1InterpolationDelimiter Delimiter
HiLink ps1Conditional Conditional
HiLink ps1Function Function
HiLink ps1Variable Identifier
HiLink ps1ScopedVariable Identifier
HiLink ps1VariableName Identifier
HiLink ps1Boolean Boolean
HiLink ps1Constant Constant
HiLink ps1BuiltIn StorageClass
HiLink ps1Type Type
HiLink ps1Scope Type
HiLink ps1StandaloneType Type
HiLink ps1Number Number
HiLink ps1Comment Comment
HiLink ps1CommentTodo Todo
HiLink ps1CommentDoc Tag
HiLink ps1CDocParam Todo
HiLink ps1Operator Operator
HiLink ps1Repeat Repeat
HiLink ps1RepeatAndCmdlet Repeat
HiLink ps1Keyword Keyword
HiLink ps1KeywordAndCmdlet Keyword
HiLink ps1Cmdlet Statement
delcommand HiLink
endif

let b:current_syntax = "powershell"