Created
August 21, 2025 13:41
-
-
Save Maxiviper117/0ff6c88a8d9b1876835a6bff83aeede2 to your computer and use it in GitHub Desktop.
Open-NvimHere: Launch Neovim in a new Windows Terminal PowerShell 7 window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🛠️ Setup Instructions
Install prerequisites
wt.exeshould be on PATH)pwsh.exeshould be installed)Add the function to your PowerShell profile
Open your PowerShell 7 profile file:
notepad $PROFILEPaste the function and alias (
Open-NvimHereandnvh) into the file.Save and restart PowerShell 7.
Usage
nvh→ open the current folder in a new Windows Terminal window running Neovimnvh <path>→ open the given folder or file in Neovim (file’s parent folder becomes the working directory)Customizing
"PowerShell 7"), change the-p 'PowerShell'argument in the function.nvh) if you prefer a different shortcut.