Discussion:
Vim and PowerShell paths
(too old to reply)
David Trimboli
2007-07-13 14:31:40 UTC
Permalink
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
2007-07-13 17:11:19 UTC
Permalink
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
------------------------------------------------------
David Trimboli
2007-07-13 17:50:17 UTC
Permalink
Post by Jason
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
Thanks, Jason. That works!
--
David
Stardate 7531.1
David Trimboli
2007-07-13 17:59:12 UTC
Permalink
Post by David Trimboli
Post by Jason
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
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
2007-07-13 17:59:53 UTC
Permalink
Post by David Trimboli
Post by Jason
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
Thanks, Jason. That works!
Er, well, mostly. I'll have to tweak it to allow Vim's command-line
parameters.
--
David
Stardate 7531.1
PSApple
2007-07-20 17:56:25 UTC
Permalink
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.
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" }
}
Martin Krischik
2007-07-13 17:20:16 UTC
Permalink
Post by David Trimboli
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?
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://***@users.sourceforge.net
Ada programming at: http://ada.krischik.com
David Trimboli
2007-08-14 05:03:16 UTC
Permalink
Post by David Trimboli
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?
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
d***@gmail.com
2016-06-29 16:35:40 UTC
Permalink
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
2016-06-29 17:12:46 UTC
Permalink
Post by d***@gmail.com
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

Loading...