PowerCLI and VI // How-TO
jibbajabba
Member Posts: 4,317 ■■■■■■■■□□
I know there are a lot of free Powershell editor out there, including Powershell Plus, but for some reason I still prefer VI every now and then.
I am not 100% where I initially found it first as it's been ages, but here is how you can use VI inside Powershell and execute scripts you are working on directly from inside VI
Tools needed
VI / VIM for Windows
VI / VIM Powershell Syntax Coloring
1. Install VI for Windows and note the path, for example
2. Check if you got a Powershell profile
The file doesn't necessarily exist just yet, simply open it up with
3a. For added "fun" - add two functions too, to make it easier to edit your VI and PS profiles
4. Install the syntax coloring - simply copy the contents of the zip to
5. Edit your VI profile ; If you add the additional functions, simply hit
Add the following line to enable color syntaxing
6. To run PS1 files from inside VI / VIM, add the following as well
Now from within VI - you can execute the current file with
You can obviously change the syntax coloring, but here how it would look like without changing
So like mentioned, use :R to run the file
Which will simply run inside the VI session (you can see the icon in the top left corner)
I am not 100% where I initially found it first as it's been ages, but here is how you can use VI inside Powershell and execute scripts you are working on directly from inside VI
Tools needed
VI / VIM for Windows
VI / VIM Powershell Syntax Coloring
1. Install VI for Windows and note the path, for example
C:\Program Files (x86)\Vim\vim73\vim.exe
2. Check if you got a Powershell profile
PS C:\Users\xx> $profile C:\Users\xx\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
The file doesn't necessarily exist just yet, simply open it up with
PS C:\Users\xx> notepad $profile3. Add the VI executable
# Adding VI / VIM to profile $VIPATH = "C:\Program Files (x86)\Vim\vim73\vim.exe" Set-Alias vi $VIPATH Set-Alias vim $VIPATH
3a. For added "fun" - add two functions too, to make it easier to edit your VI and PS profiles
# for editing your PowerShell profile Function Edit-Profile { vim $profile } # for editing your Vim settings Function Edit-Vimrc { vim $home\_vimrc }
4. Install the syntax coloring - simply copy the contents of the zip to
C:\Program Files (x86)\Vim\vimfiles
5. Edit your VI profile ; If you add the additional functions, simply hit
PowerCLI C:\Scripts> Edit-Vimrc
Add the following line to enable color syntaxing
syntax on
6. To run PS1 files from inside VI / VIM, add the following as well
set shell=powershell set shellcmdflag=-command command R !./%
Now from within VI - you can execute the current file with
:R
You can obviously change the syntax coloring, but here how it would look like without changing
So like mentioned, use :R to run the file
Which will simply run inside the VI session (you can see the icon in the top left corner)
My own knowledge base made public: http://open902.com
Comments
-
undomiel Member Posts: 2,818Thanks for the info! vim is definitely my preference for some quick PowerShell work.Jumping on the IT blogging band wagon -- http://www.jefferyland.com/