Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Vim and PowerShell paths

34 views
Skip to first unread message

David Trimboli

unread,
Jul 13, 2007, 10:31:40 AM7/13/07
to
No doubt the PowerShell folks will think this is a Vim question, and the
Vim folks will think this is a PowerShell question.

When I try to edit a file with Vim 7.1 from Windows PowerShell, Vim
seems to require a full path to the file. For instance, if I'm in "H:\My
Documents\WindowsPowerShell" and I type "vim profile.ps1" or even "vim
.\profile.ps1" I find myself editing "H:\profile.ps1".

This behavior is apparently unique to PowerShell; in CMD and CSH Vim
lets me use relative paths the way one would expect. Is there a way to
adjust Vim (or PowerShell!) to let me use relative paths when calling
Vim from PowerShell?

--
David
Stardate 7530.7


Jason

unread,
Jul 13, 2007, 1:11:19 PM7/13/07
to
Hi David:

Here's a function you can put into your $profile so that you can pipe into
vim (e.g., "dir c:\ | vim") and which may also help get around the relative
path issue:

function vim ( $path = $null )
{
$vimpath = 'C:\Progra~1\Vim\vim71\vim.exe'
if ($path -ne $null) {invoke-expression "$vimpath $path"}
elseif ( $input.movenext() )
{
$input.reset()
$input | out-string | out-file "$env:TEMP\vimtempfile.txt"
invoke-expression "$vimpath $env:TEMP\vimtempfile.txt"
remove-item "$env:TEMP\vimtempfile.txt"
}
else { invoke-expression "$vimpath" }
}


Cheers,
Jason


------------------------------------------------------
PowerShell Training at SANS Conferences
http://www.WindowsPowerShellTraining.com
------------------------------------------------------

Martin Krischik

unread,
Jul 13, 2007, 1:20:16 PM7/13/07
to
David Trimboli wrote:

Well repeat your example above - but now once vim has started call
Vims ":pwd" command. The output should be "H:\My
Documents\WindowsPowerShell" ! If not them powershell just might be
powerfull but it certainly is not propper shell.

Martin
--
mailto://kris...@users.sourceforge.net
Ada programming at: http://ada.krischik.com

David Trimboli

unread,
Jul 13, 2007, 1:50:17 PM7/13/07
to
Jason <nos...@nospam.com> wrote:
> Here's a function you can put into your $profile so that you can pipe
> into vim (e.g., "dir c:\ | vim") and which may also help get around
> the relative path issue:

Thanks, Jason. That works!

--
David
Stardate 7531.1


David Trimboli

unread,
Jul 13, 2007, 1:59:12 PM7/13/07
to
David Trimboli <trim...@cshl.edu> wrote:
> Jason <nos...@nospam.com> wrote:
>> Here's a function you can put into your $profile so that you can pipe
>> into vim (e.g., "dir c:\ | vim") and which may also help get around
>> the relative path issue:
>
> Thanks, Jason. That works!

Er, well, mostly. I'll have to tweak it to allow Vim's command-line
parameters.

--
David
Stardate 7531.1


David Trimboli

unread,
Jul 13, 2007, 1:59:53 PM7/13/07
to
David Trimboli <trim...@cshl.edu> wrote:
> Jason <nos...@nospam.com> wrote:
>> Here's a function you can put into your $profile so that you can pipe
>> into vim (e.g., "dir c:\ | vim") and which may also help get around
>> the relative path issue:
>
> Thanks, Jason. That works!

Er, well, mostly. I'll have to tweak it to allow Vim's command-line

PSApple

unread,
Jul 20, 2007, 1:56:25 PM7/20/07
to
I'm using a different editor (Textpad) but same need.

The $path expression gets ugly with spaces?
if I do this
>vim "C:\program files\test bin\config.txt"

It won't envoke with the right file name.


"Jason" <nos...@nospam.com> wrote in message
news:%231MUWDX...@TK2MSFTNGP05.phx.gbl...

David Trimboli

unread,
Aug 14, 2007, 1:03:16 AM8/14/07
to

Aha! I found the answer: doskey!

I stuck these lines in my PowerShell profile:

doskey /exename=powershell.exe vim="&"
$env:programfiles\vim\vim71\vim.exe $*
doskey /exename=powershell.exe gvim="&"
$env:programfiles\vim\vim71\gvim.exe $*

David
Stardate 7617.2


drag...@gmail.com

unread,
Jun 29, 2016, 12:35:41 PM6/29/16
to
I pulled this from a couple other blog posts around Vim in Powershell, but I think it is fairly elegant.

# Finds Vim, puts it into an alias so you don't have to do magic to pass it arguments. Can use "vim $profile" to edit or the "verb-noun" version.

$VIMPATH = ${env:ProgramFiles(x86)} + "\Vim\vim74\vim.exe"
Set-Alias vi $VIMPATH
Set-Alias vim $VIMPATH

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

# for editing your Vim settings
Function Edit-Vimrc
{
vim $home\_vimrc
}

Function vf ()
{
$filepaths = $input | Get-Item | % { $_.fullname }
vim $filepaths
}

Jürgen Exner

unread,
Jun 29, 2016, 1:12:47 PM6/29/16
to
On Wed, 29 Jun 2016 09:35:40 -0700 (PDT), drag...@gmail.com wrote in
microsoft.public.windows.powershell:

>I pulled this from a couple other blog posts around Vim in Powershell, but I think it is fairly elegant.

You do realize that the OP found his solution 9 years ago already?

jue
0 new messages