Skip to content

A tmux plugin that helps opening files in a Neovim pane

License

Notifications You must be signed in to change notification settings

xhd4/tmux-open-nvim

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

tmux-open-nvim

A tmux plugin that helps opening files in a Neovim pane

Demo

(click thumbnail)

Installation

Using TPM, add this to your .tmux.conf

set -g @plugin 'trevarj/tmux-open-nvim'

Reload tmux config (<prefix>-I). Also you may want to start a fresh session to reload $PATH into your environment.

Usage

CLI

The plugin will add a helper script called ton to your path while inside a tmux session.

The target use case of this plugin is when you have a tmux window that already has a pane running nvim and a pane with a terminal:

$ ton file.txt # optionally add :[line]:[col] to the end, i.e file.txt:40:5
# Opens file.txt in nvim pane

Caveat

Upon launch of a fresh tmux session, the script will not be in the first pane due to how an environment is loaded, I guess. I think the only way to resolve this is by adding the ~/.tmux/plugins/tmux-open-nvim/scripts directory to your path permanently or with tmux -e PATH=$PATH:~/.tmux/plugins/tmux-open-nvim/scripts

When you create a session, it creates window 0 automatically, which fires off a shell. So, for that shell, setenv doesn't work and you have to send-keys. But when you create a new window, like with split-window, the new window gets the environment from the setenv. The example shows that both windows have the environment whether set explicitly via export or via setenv.

See:

tmux-fingers (or tmux-open)

An optimal workflow using tmux-fingers:

Add this to your .tmux.conf:

# Overrides matching file paths with :[line]:[col] at the end
set -g @fingers-pattern-0 "((^|^\.|[[:space:]]|[[:space:]]\.|[[:space:]]\.\.|^\.\.)[[:alnum:]~_-]*/[][[:alnum:]_.#$%&+=/@-]+)(:[[:digit:]]*:[[:digit:]]*)?"
# Launches helper script on Ctrl+[key] in fingers mode
set -g @fingers-ctrl-action "xargs -I {} tmux run-shell 'cd #{pane_current_path}; ~/.tmux/plugins/tmux-open-nvim/scripts/ton {} > ~/.tmux/plugins/tmux-open-nvim/ton.log'"s

Now you can enter fingers mode and use Ctrl+[key] to launch a file in nvim

Future Features

  • A fzf-like selector that can target exactly which neovim instance you want to open a file in
  • Fix "caveat" above (maybe?)

About

A tmux plugin that helps opening files in a Neovim pane

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 100.0%