/Nvim-Unique-Instance

Launch one unique Neovim gui instance for every path

Primary LanguagePythonMozilla Public License 2.0MPL-2.0

Launch one unique Neovim gui instance for every path

简体中文

Brief

This project provides a way to launch a unique instance of the Nvim GUI for each workspace directory.

  • When the Nvim window is launched multiple times for the same workspace, the open file and location jump instructions are executed in the existing window, and no new window is opened.
  • When the previous window is reused, the window is called up and focused. (Currently, only Windows Terminal is supported)
  • When different workspaces are opened, the launcher launches a different window for each different workspace.

Dependency

pip3 install neovim-remote

pyinstaller

pip install pyinstaller
# or
conda install -c conda-forge pyinstaller

Install and get started setting up Windows Terminal

Installation

pyinstaller ./nvim_instance.py --nowindow

The nvim_instance executable is then generated in the dist/ directory.

Usage

<path_to_nvim_instance exec> [-h] --project PROJECT --file FILE [--line LINE] [--column COLUMN]

-h, --help            show this help message and exit
  --project PROJECT, -p PROJECT
                        project path, open same path will reuse previous window, necessary argument
  --file FILE, -f FILE  file name, necessary argument
  --line LINE, -l LINE  line number to jump to
  --column COLUMN, -c COLUMN
                        column number to jump to

Principle

The initiator uses paths to distinguish between different workspaces and assigns each path a unique named pipe. Named of the Pipe: nvim_instance_<path_basename>_<sha512 hex value for path>. At each startup, the initiator first attempts to connect to the existing instance using the generated pipe name. If the connection is successful, the file is opened in the existing instance and jumps to the specified location. If the connection fails, create a new instance and try again.

Test

Tested on Windows 10.

License

MPL 2.0 (c) 2023 Chrix