Skip to content

Instantly share code, notes, and snippets.

@Maxiviper117
Created August 21, 2025 13:41
Show Gist options
  • Save Maxiviper117/0ff6c88a8d9b1876835a6bff83aeede2 to your computer and use it in GitHub Desktop.
Save Maxiviper117/0ff6c88a8d9b1876835a6bff83aeede2 to your computer and use it in GitHub Desktop.
Open-NvimHere: Launch Neovim in a new Windows Terminal PowerShell 7 window
# Open-NvimHere.ps1
# Add this function to your PowerShell 7 $PROFILE
# Usage:
# nvh → open current folder in new WT window with nvim
# nvh <path-or-file> → open that path (or file’s folder) in new WT window with nvim
function Open-NvimHere {
[CmdletBinding()]
param(
[string] $Path
)
if (-not $Path) { $Path = (Get-Location).Path }
try {
$resolved = (Resolve-Path -LiteralPath $Path).Path
} catch {
Write-Error "Path not found: $Path"
return
}
if (Test-Path -LiteralPath $resolved -PathType Leaf) {
$workDir = Split-Path -LiteralPath $resolved
} else {
$workDir = $resolved
}
# Launch a new Windows Terminal window:
# -w 0 always spawns a new window
# -p <ProfileName> sets the WT profile (adjust if your profile is "PowerShell 7")
# -d sets working directory
# -- separates WT args from the shell command
$wtArgs = @(
'-w', '0'
'-p', 'PowerShell'
'-d', $workDir
'--'
'pwsh', '-NoExit', '-Command', "nvim `"$resolved`""
)
Start-Process wt.exe -ArgumentList $wtArgs | Out-Null
}
Set-Alias nvh Open-NvimHere
@Maxiviper117
Copy link
Author

🛠️ Setup Instructions

  1. Install prerequisites

  2. Add the function to your PowerShell profile

    • Open your PowerShell 7 profile file:

      notepad $PROFILE
    • Paste the function and alias (Open-NvimHere and nvh) into the file.

    • Save and restart PowerShell 7.

  3. Usage

    • nvh → open the current folder in a new Windows Terminal window running Neovim
    • nvh <path> → open the given folder or file in Neovim (file’s parent folder becomes the working directory)
  4. Customizing

    • If your Windows Terminal profile for PowerShell 7 is named something else (e.g. "PowerShell 7"), change the -p 'PowerShell' argument in the function.
    • You can rename the alias (nvh) if you prefer a different shortcut.

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