tmux is a terminal multiplexer. It splits one terminal window into several panes, groups them into sessions, and keeps those sessions running when you close the window or lose an SSH connection. Neovim does not need tmux, and has its own terminal with <leader>ft. tmux earns its place when you work on a remote machine, or when you want the editor, the running app and a shell to survive a disconnect together.

When tmux is worth it

Skip tmux if you work on your own laptop and one terminal window with Neovim is enough. Use it when:

  • You edit on a server over SSH. If the connection drops, the session, the editor and the running app are still there; tmux attach brings them back.
  • You want several long-running things side by side, such as Neovim, ./mvnw spring-boot:run and a shell for curl, without opening more windows.

Everything else in this series works the same with or without tmux.

Four settings Neovim cares about

Neovim’s health check has a tmux section that inspects your tmux settings. Run :checkhealth vim.health inside tmux to see it. These lines in ~/.tmux.conf make every check pass:

set -sg escape-time 10
set -g focus-events on
set -g default-terminal "tmux-256color"
set -as terminal-features ",xterm-256color:RGB"

nvim-spring-ide: extras/tmux.conf

What each one does:

  • escape-time 10. tmux waits after an Escape key to see whether more keys follow. The default wait is long enough that leaving insert mode feels slow. Ten milliseconds fixes that.
  • focus-events on. tmux tells Neovim when you switch to and from its pane. Neovim uses that to notice files changed outside the editor, for example by git checkout in the next pane.
  • default-terminal and terminal-features. These give programs inside tmux full 24-bit colour. Replace xterm-256color with the value of $TERM outside tmux if your terminal uses another one.

On our test machine, with these lines and an outer terminal of type xterm-256color, the tmux section reported escape-time: 10 and focus-events: on as OK and no colour warnings. Reload the file with tmux source-file ~/.tmux.conf, or restart tmux.

Two more lines are worth adding. set -g mouse on lets you resize panes and scroll with the mouse. set -g set-clipboard on helps copies reach your local clipboard, as Part 13 explains.

A layout for the catalog app

A practical layout for module 9 of the companion code uses one window with three panes. tmux’s default prefix key is Ctrl-b: press it, release, then press the next key.

  1. Start a session named after the project: tmux new -s shop, and run nvim in the repository root.
  2. Split the window below the editor with Ctrl-b ". In the new pane, start the app: ./mvnw -pl module-09-catalog spring-boot:run.
  3. Split that pane side by side with Ctrl-b % and keep it for a shell: curl 'localhost:8080/catalog?page=0&size=2', git status, and jcmd from Part 10.

Move between panes with Ctrl-b and an arrow key, and make a pane fill the window for a moment with Ctrl-b z; press it again to restore the layout. Detach with Ctrl-b d, and tmux attach -t shop brings everything back exactly as it was, the app still running.

When you debug with (Part 7), the debugger starts its own JVM, so stop the app in the second pane first to free port 8080, or use a run configuration with another port (Part 9).

What we left out

Popular tmux setups add more, such as plugins that move between Neovim splits and tmux panes with the same keys, or session managers that restore layouts after a reboot. They are useful, but they are a matter of taste, and we did not test them for this series. The four settings above and the layout cover what an IDE-like setup needs.

Recap

  • tmux splits a terminal into panes and keeps sessions alive across disconnects; it is most useful over SSH.
  • Set escape-time 10, focus-events on, default-terminal "tmux-256color" and an RGB terminal feature; :checkhealth vim.health checks them.
  • Add mouse on and set-clipboard on for comfort and clipboard forwarding.
  • One window with Neovim, the running app and a shell covers daily work; Ctrl-b d detaches and tmux attach resumes.

Series: Neovim as a Java IDE. Previous: Copy and paste between Neovim and the system clipboard · Next: A ready-made Neovim config for Spring Boot

Sources

Official documentation and well-known tutorials read while writing this article. The wording here is our own.