Name, save and load buffers
buffer0 is renamed key and saved to ~/key.txt; ~/motd.txt is loaded as buffer motd.
Three commands, all typed at C-b :, all taking -b to say which buffer they act on:
setb -b old -n new- rename a buffer
saveb -b name path- write its contents to a file
loadb -b name path- read a file into a buffer with that name
Naming is the point: an automatic buffer is dropped once the pile passes 50, and a named one never is. ~ expands at the prompt, so ~/key.txt is /home/alpine/key.txt.
Press C-b :, type setb -b buffer0 -n key, Enter.
Only the name changed; the text is untouched.
Press C-b :, type saveb -b key ~/key.txt, Enter.
The buffer’s contents are now on disk.
Press C-b :, type loadb -b motd ~/motd.txt, Enter.
The file’s contents arrive as a new named buffer.
Press C-b =, then q.
The list shows key and motd, and no buffer0.
Creating a buffer directly
set-buffer -b name text creates a buffer outright, with no copying involved. Without -b, both set-buffer and load-buffer make a new automatic buffer instead.
Here is what just happened.
Only the name changed in step 1; the text stayed. save-buffer wrote that text to disk and load-buffer did the reverse into a fresh buffer, without touching any pane. Renaming first means the save does not depend on which number the buffer happens to have.
- Rename a buffer, turning an automatic buffer into a named one; setb -b name text creates one:setb -b old -n new
- Write a buffer's contents to a file:saveb -b name path
- Read a file into a buffer with the given name:loadb -b name path
Go further
setb -b foo barcreates named bufferfooholdingbarwith no copying.- Chain them on one line:
setb -b buffer0 -n key ; saveb -b key ~/key.txt.
- 1Everything here is typed at
C-b :.-bnames the buffer the command works on. - 2Rename:
setb -b buffer0 -n key. Save:saveb -b key ~/key.txt. - 3Load:
loadb -b motd ~/motd.txt.C-b =should then listkeyandmotd.
This is a live terminal. Typing goes to the machine, including Tab. Press Shift and Tab together to move focus back out to the page.
A real terminal, in this tab
Alpine Linux and tmux 3.4 on an x86 emulator. Nothing to install, and no server behind it.
about 15 MB, once
Done when
not started- buffer0 has been renamed to key and still holds the copied text— not done yet
- The key buffer was saved to ~/key.txt— not done yet
- motd.txt was loaded into a buffer named motd— not done yet