Skip to content

Instantly share code, notes, and snippets.

@leafgarland
Created October 16, 2014 12:56
Show Gist options
  • Select an option

  • Save leafgarland/f7a869091567aa08efc2 to your computer and use it in GitHub Desktop.

Select an option

Save leafgarland/f7a869091567aa08efc2 to your computer and use it in GitHub Desktop.
Powershell function to start GVim, making use of Vim's server features.
function Start-Vim {
if (!$global:VimServerName) {
$global:VimServerName = 'GVIM'
}
if ($args) {
gvim.exe --servername $global:VimServerName --remote-silent $args
} else {
$servers = (vim.exe --noplugin -u NORC --serverlist) | ? { $_ -eq $global:VimServerName }
if ($servers) {
vim.exe --noplugin -u NORC -c "call remote_foreground('$global:VimServerName')" -c 'quit'
} else {
gvim.exe --servername $global:VimServerName
}
}
}
@leafgarland
Copy link
Copy Markdown
Author

This allows you to keep using the same instance of GVim from the command line. If you call it with no arguments it will either start a new instance of GVim or bring a running instance to the foreground.

Make sure to set a more convenient alias, e.g. Set-Alias vi Start-Vim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment