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 attachbrings them back. - You want several long-running things side by side, such as Neovim,
./mvnw spring-boot:runand a shell forcurl, 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 bygit checkoutin the next pane.default-terminalandterminal-features. These give programs inside tmux full 24-bit colour. Replacexterm-256colorwith the value of$TERMoutside 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.
- Start a session named after the project:
tmux new -s shop, and runnvimin the repository root. - Split the window below the editor with
Ctrl-b ". In the new pane, start the app:./mvnw -pl module-09-catalog spring-boot:run. - 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, andjcmdfrom 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 anRGBterminal feature;:checkhealth vim.healthchecks them. - Add
mouse onandset-clipboard onfor comfort and clipboard forwarding. - One window with Neovim, the running app and a shell covers daily work;
Ctrl-b ddetaches andtmux attachresumes.
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.
Comments