blog til projects meta feed
~ / til / Persistent Neovim terminals with `tmux` 2025-11-08 | 2 minutes
Do you use Neovim’s built-in terminal? Do you (always) accidentally close Neovim and lose the terminal? Well, I may have a solution for you.
tmux is a terminal multiplexer. It allows you to split your terminal into windows and tabs, and is very useful when you need to do a lot of work in a single terminal e.g over an ssh connection. The killer feature, however, is that tmux will persist everything, even when the window or connection is closed. This is what I use to keep my Neovim terminals open:
vim.api.nvim_create_user_command('Term',
function()
vim.cmd('term tmux new -A -t nvim')
vim.cmd('startinsert')
end,
{})
vim.api.nvim_create_user_command('Termtab',
function()
vim.cmd('tabnew')
vim.cmd('term tmux new -A -t nvim')
vim.cmd('startinsert')
end,
{})
These are lua functions to include in your nvim config. They add two new user commands :Term and :Termtab, to open the persistent terminal in your current buffer or a new tab, respectively.
Neovim allows you to run a command when you open a terminal, by putting it after the term command. The command tmux new -A -t nvim will open a new tmux session called nvim or connect to the existing session with that name if it exists.
You can now run :Term, which will create a new persistent terminal. You can now safely close Neovim, and if you open it up again and run :Term you’ll get back into the same session. It’s even better if you use Neovim sessions, as it will automatically connect back to the terminal when you load the session. Here it is in action:

A couple of notes. I added startinsert to the end of the functions so that it drops me right into the terminal and I can start typing. Without this, you’ll still need to press i to type something into the terminal. Secondly, if you are a heavy tmux user, you may end up opening an nvim terminal inside an existing tmux session. If you do this, you’ll need to press the command key sequence (default Ctrl-B) twice to run a tmux command in the nvim window. I’ve found out that doing Ctrl-B-B works fine, which might be easier for you.
Articles from blogs I follow around the net
Switching from GPG to age
It’s been several years since I went through all the trouble of setting up my own GPG keys and securing them in YubiKeys following drduh’s guide. With that approach, you generate one key securely offline and store it on multiple YubiKeys, along with a back…
via Luke Hsiao's blog November 4, 2025Computer Says No: Error Reporting for LTL
Quickstrom is a property-based testing tool for web applications, using QuickLTL for specifying the intended behavior. QuickLTL is a linear temporal logic (LTL) over finite traces, especially suited for testing. As with many other logic systems, when a formu…
via Oskar Wickström November 1, 2025Cosytober 2025
Cosytober 2025 CosyTober is a “cosy alternative to #Inktober”. The idea is the same, all during October, each day a prompt is given and artists are asked to draw, paint or otherwise create something inspired by the prompt and post it to social media. I'…
via splitbrain.org - blog October 31, 2025Generated by openring
Last updated: 2025-11-08 16:06:19 +0000
v25.16.p1108
© Andrew Conlin 2023-2025
All rights reverse engineered