共用方式為


PowerShell syntax for Vim

Peter Provost did all the heavy lifting here.

Unfortunately, when I installed Vim 7.0, things were different enough that I wanted to post a bit of what I did, both to document it for the future and to get corrections from others in case what I did was "wrong" (it works for me, though :)

The biggest difference is that Peter mentions using the vimfiles subdir instead of the version-specific ("official") one (like vim70 in my case).  However, my vimfiles dir didn't have an existing filetype.vim file in it, and while I could have (maybe should have) created one, it was easier to just hop over and do the work in the vim70 dir instead, knowing it would live alongside the "official" ones that came with vim.

The modification to filetype.vim was smaller since the syntax seems to have changed a small bit, but here's what I have.  The red bit is what I actually added to the file - the bits above and below are just to give context on where in the file I added it.  I originally was going to put this in as a unified diff, but feared people would copy-paste the + characters into their files :)

" Yacc or racc
au BufNewFile,BufRead *.y call s:FTy()

" PowerShell
au BufNewFile,BufRead *.ps1,*.psc1 setf ps1

fun! s:FTy()
let n = 1
while n < 100 && n < line("$")

Ok, now on to the ftplugin file which I wrote to vim70/ftplugin/ps1.vim - this one stays pretty much like Peter's version, just modifying for the rename and split to 2 extensions.  I highlight the differences here.

" 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 comments=#
setlocal commentstring=#%s
setlocal formatoptions=tcqro
"setlocal iskeyword+=#

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

"-------------------------------
" Undo the stuff we changed.
let b:undo_ftplugin = "setlocal tw< cms< fo<" .
\ " | unlet! b:browsefilter"

" vim: ts=4:tw=0

The main file is exactly the official one, I just placed it into the vim70/syntax folder instead of vimfiles/syntax.  As I said before, if that's "wrong", I'm hoping to get corrected (by Peter or someone else). :)

Personally, I also go edit the _vimrc file in the Vim main directory and add these lines at the bottom, but that's definitely a personal preference :)

colorscheme darkblue
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set list listchars=tab:»·,trail:·