14

GitHub - joshdick/dntw: dntw - [D]edicated [N]eovim per [t]mux [w]indow 🤯

 4 years ago
source link: https://github.com/joshdick/dntw
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

dntw - [D]edicated [N]eovim per [T]mux [W]indow exploding_head

dntw demo

dntw is a small shell script that allows you to have a dedicated Neovim instance per tmux window. It accomplishes this by acting as simple wrapper around the excellent tool neovim-remote.

Once Neovim is running inside a dntw-enabled tmux session, the first instance of Neovim that is running in a given tmux window will become the dedicated Neovim instance for that window. Subsequent invocations of Neovim from other panes in the same window will reuse the dedicated instance.

Any time I used tmux and Neovim together for software development, new panes I created in tmux inevitably became filled with redundant instances of Neovim.

I made dntw with the hope that it would automatically save me from myself.

Install

If you're comfortable in Neovim/tmux/editing your shell configuration, dntw is for you!

Here's how to install it:

  1. tmux and nvim are required for dntw to work. If you're not already using them, dntw may not be for you.

  2. Install neovim-remote, which is required for dntw to work.

    pip3 install neovim-remote

    If you have issues with this step, refer to neovim-remote's installation documentation for assistance.

  3. Clone the dntw git repository somewhere.

    $ git clone git://github.com/joshdick/dntw.git ~/.dntw
  4. Add the following line somewhere in your shell configuration (.zshrc/.bashrc/etc) to source dntw.sh, adjusting the path accordingly for whatever you chose in the previous step.

    . ~/.dntw/dntw.sh

    This configuration adds the dntw and dntw_edit functions to your shell.

  5. Create a function in your shell configuration that you will use to invoke dntw_edit as if it were Neovim.

    If you want to name the function nvim, or instruct dntw to use a specific nvim binary, you can set the environment variable $DNTW_NVIM_CMD to the location of your nvim binary.

    Here's an example:

    # If you need to bypass this function and run the real `nvim`
    # for some reason, just run `command nvim` instead.
    function nvim () {
      if [[ "$TERM_PROGRAM" == "vscode" ]]; then
        # If we typed "nvim" while inside the integrated Visual Studio Code terminal,
        # open the file in Code instead.
        code "$@"
      else
        # Invoke `dntw_edit` with an explicit `$DNTW_NVIM_CMD` since this function's
        # name conflicts with the real `nvim`.
        DNTW_NVIM_CMD=/usr/local/bin/nvim dntw_edit "$@"
      fi
    }
    
    # These convenience aliases simply invoke the function above.
    alias vi='nvim'
    alias vim='nvim'
  6. Re-source your shell configuriation/restart your shell, or open a new shell. You're now ready to use dntw.

Start a new dntw-enabled tmux session by running dntw.

Once tmux is running, start Neovim inside tmux by invoking the function you added during install.

Neovim will behave as described in the what section.

That's it!

Click on a question to see the answer.

Does this work with standard Vim?
Does this work on Windows?
Why do I see an error that starts with 'dntw error: "neovim-remote" is required, but does not appear to be installed.'?

License

Miscellany

The demo recording was created with asciinema and svg-term-cli.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK