Windows PowerShell + Vim

This semester I’m taking a course at Seneca College about “Malware Analysis and Penetration Testing“, which by the way, is an awesome course that I highly recommend!

And as you can imagine, since the most targeted platform by malicious attackers is Windows I’m having to get my hands dirty and sharpen up my Windows skills again.

Later on I’ll blog about the network config I have setup for my virtual environment, but just to get started I wanted to share how to configure PowerShell Profiles and set vi as the default editor.

1. Creating your profile

First thing fire up your PowerShell with admin privileges.
To find the location of your profile type, you should see something like:
> $profile C:UsersyourUserNameDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1

That’s the profile for your user only.
The profile for all users of the system is located at:
> C:WindowsSystem32WindowsPowerShellv1.0profile.ps1

To create the profile file you can run this command:
> new-item -path $env:windirSystem32WindowsPowerShellv1.0profile.ps1 -itemtype file -force

For more info about the command here

2. Configuring your profile

Now that you’ve created the profile it is time to configure it.
Open your $profile and add the following:

$SCRIPTPATH = “C:apps”
$VIMPATH = $SCRIPTSPATH + “C:appsgvimVimvim74vim.exe”

Set-Alias vi $VIMPATH
Set-Alias vim $VIMPATH

// for editing your PowerShell profile
Function Edit-Profile {
vim $profile

The code snipped was taken from here
It basically just creates an alias to access the vim executable and a function to quickly edit the profile.

3. Configuring vi

Vi has a plethora of settings to configure and allows for a very flexible and powerful configuration.
Below is just a few settings that I always like to have whenever I need to use vi:

 set number
set tabstop=2
set shiftwidth=2
set expandtab
:syntax on
:colorscheme peachpuff

Just add the code above to > $PATH_TO_YOUR_VIM_INSTALLVim_vimrc

And that’s all you need to edit file directly from the PowerShell command line with vi on Windows.


More info can be found: