Because, why not.
And because I am stuck in Windows Land while at work.
And because I found myself playing around with Windows Power Shell. It’s not as good as Bash by a long stretch, but it is a significant improvement on the old Windows cmd almost-terminal. And, because I like to be able to move from task to task, without having to constantly switch windows, I thought I would give it a try.
The first thing to do, of course, is install a decent text editor. This is easy, a Windows binary exists for Vim so I downloaded and installed it. Then comes the fun bit.
Getting it to work in Powershell isn’t exactly difficult, but there are a few hoops that need to be jumped through and no clear overview of what and where these hoops happen to be. And that’s why I am posting this.
First, you need to allow scripts to run. This is not enabled by default because, obviously, if you have a scripting environment, the last thing you are going to want to do is execute scripts. Fortunately, this is easily checked and altered by means of the execution policy.
To see the current state of your execution policy, use:
Get-ExecutionPolicy
This will probably tell you it’s restricted, in which case you need to tell it to run scripts by typing (or pasting):
Set-ExecutionPolicy RemoteSigned
(You can also set the execution policy to AllSigned
or Unrestricted
, but RemoteSigned
is sufficient for now.)
Next, you need a Powershell profile (why is it that Windows terms all feel like they should be wrapped in a blink tag?), which can be created by typing (or pasting):
new-item -path $profile -itemtype file -force
And now you need to edit your profile to add a Vim alias. You’ll need to do this in Notepad:
notepad $profile
And then paste the following:
set-alias vim "C:/Program Files (x86)/Vim/Vim74/./vim.exe"
# To edit the Powershell Profile
# (Not that I'll remember this)
Function Edit-Profile
{
vim $profile
}
# To edit Vim settings
Function Edit-Vimrc
{
vim $HOME_vimrc
}
(Obviously, you will need to amend the Vim path name to match the reality on your system.)
And you’re done.
I’m not sure how much use I will actually get out of Vim at work as my workflow often involves copying and pasting text from one application to another – and for that Notepad++ is probably still a better fit. However, having an additional tool certainly does no harm and I can certainly see cases where having the power of Vim available will be useful. For now, I will use both and see how each fits into my workflow.
And finally, this post was brought you you with the help of Microsoft, Marlon Abastar and Julian Kay.