From cdd7b0fc2fb2185ec783f63229c35d491e3a3d51 Mon Sep 17 00:00:00 2001 From: Staffan Gustafsson Date: Sat, 3 May 2014 16:30:01 +0200 Subject: [PATCH] Inital commit if PSVim Start-VimErrorFile --- README.md | 36 ++++++++++++++ vim/errorfile.ps1 | 118 ++++++++++++++++++++++++++++++++++++++++++++++ vim/vim.psd1 | Bin 0 -> 5208 bytes vim/vim.psm1 | 15 ++++++ 4 files changed, 169 insertions(+) create mode 100644 vim/errorfile.ps1 create mode 100644 vim/vim.psd1 create mode 100644 vim/vim.psm1 diff --git a/README.md b/README.md index bb751ac..b71a83a 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,39 @@ PSVim ===== Gems for using PowerShell with vim. + +This module is intented for the gigantic intersection of PowerShell and Vim users. + +Usage +----- +To start using, just import the module + +```powershell +Import-Module vim +``` + +Start-VimErrorFile +------------------ + +Using the --errorfile option of gvim to quickly jump between files or matches from Select-String. + +In the same way as you can jump between compilation errors in vim, you can now jump between files or matches piped into +Start-VimErrorFile + +```powershell +Get-ChildItem -Recurse -Filter *.cs | Select-String throw | Start-VimErrorFile + +ls *.txt | stve + +# open a new gvim window +ls *.ps1 | sls function | stve -newinstance +``` +The above examples open gvim with all locations where an exception in the error list + +By adding the following to _vimrc it is quick and easy to jump between the hits with F2 or F3 +``` +nnoremap :bn +nnoremap :bp +nnoremap :cn +nnoremap :cp +``` diff --git a/vim/errorfile.ps1 b/vim/errorfile.ps1 new file mode 100644 index 0000000..e2db387 --- /dev/null +++ b/vim/errorfile.ps1 @@ -0,0 +1,118 @@ +function LaunchVim +{ + param + ( + [System.String] + $errorFile, + + [System.Management.Automation.SwitchParameter] + $NewInstance + ) + + if ($NewInstance) + { + gvim -q $errorfile + } + else + { + # Make sure we have a running instance to send commands to + if(!(vim --serverlist | Select-String "$reuseInstanceName" -q)) + { + gvim '--servername' $reuseInstanceName + Start-Sleep -Milliseconds 1000 + } + gvim --servername $reuseInstanceName --remote-send ":cf $errorFile" + } +} + + +function Start-VimErrorFile +{ +<# +.Synopsis + Starts the Vim editor with an error file. +.Description + This command starts creates an errorfile from the pipeline input and starts gvim with that file as an argument. + This enables easy navigations + +.Example + PS> Get-ChildItem *.txt | Start-VimWithErrorInfo + + PS> Select-String 'Foo' *.txt | Start-VimWithErrorInfo + +.Link + +.Notes +NAME: Start-VimErrorInfo +#Requires -Version 2.0 +#> + [CmdletBinding( + DefaultParameterSetName='input')] + param( + [Parameter(ParameterSetName='ErrorFile',Position=0, Mandatory=$true, ValueFromPipelineByPropertyName=$true)] + [string] $errfile, + [Parameter(ParameterSetName='input',Position=0, Mandatory=$true, ValueFromPipeline=$true)] + [ValidateNotNull()] + [PSObject[]] $data, + [switch] $NewInstance + ) + + begin{ + $lines = New-Object System.Collections.Generic.list[string] 100 + } + process { + if ($PsCmdLet.ParameterSetName -eq 'ErrorFile') + { + LaunchVim (Get-Item $errFile).FullName -forceNewInstance:$NewInstance + return + } + foreach($d in $data) + { + if($d -is [Microsoft.PowerShell.Commands.MatchInfo]) + { + $lines += '{0}({1}) : {2}' -f $d.path, $d.LineNumber, $d.Line + continue + } + if ($d -is [System.IO.FileInfo]) + { + $lines += '{0}(1) : File: {1}' -f $d.FullName, $d.Name + continue + } + if ($d -is [System.IO.DirectoryInfo]) + { + continue + } + if ($d.PSPath) + { + $lines += (Resolve-Path $d.PSPath).ProviderPath | ForEach-Object {'{0}(1) : File: {1}' -f $_, (Split-Path -Leaf $_)} + continue + } + if ($d -is [string]){ + $lines += $d + continue + } + + Write-Error -targetobject $data -message 'Invalid type of input' + + } + } + end + { + if($lines) + { + $outfile = [io.path]::GetTempFileName() + '.vimerror' + $output = [string]::join("`n", $lines) + Set-Content -encoding Ascii -Path $outfile -Value $output + LaunchVim (Get-Item $outfile).fullname -NewInstance:$NewInstance + } + } +} + +function Set-VimReuseInstanceName{ + param + ( + [string] $name = 'PsVim' + ) + + $script:reuseInstanceName = $name +} diff --git a/vim/vim.psd1 b/vim/vim.psd1 new file mode 100644 index 0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