Explaining Vim’s Read-Only Registers (unnamed + 0–9)
- Vim is modal — meaning, the same actions have different effects based on the currently active mode.
- On modality: there’s a wonderful talk by Bret Victor about Larry Tesler’s crusade against modality in computing (https://youtu.be/PUv66718DII?si=i50uDIjQcofzFzgj&t=2291) — which was powerful principle strategically underpinning his effort.
- Looking at Djikstra’s argument presented in the Humble Programmer, vim could be understood as a tool for high-quality thinking; because (it is claimed that) tools determine thought.
The influence of the tool we are trying to use upon our own thinking habits. I observe a cultural tradition, which in all probability has its roots in the Renaissance, to ignore this influence, to regard the human mind as the supreme and autonomous master of its artefacts. But if I start to analyse the thinking habits of myself and of my fellow human beings, I come, whether I like it or not, to a completely different conclusion, viz. that the tools we are trying to use and the language or notation we are using to express or record our thoughts, are the major factors determining what we can think or express at all!
— https://www.cs.utexas.edu/~EWD/transcriptions/EWD03xx/EWD340.html
- In normal mode (there’s an insert, visual, replace, command-line, and operator-pending), you combine one of a few operators (d,y,c,g,!) with one of many motions (https://vimhelp.org/motion.txt.html#various-motions)
- Let’s focus on deletion operations — In vim,
d
andc
are not just deleting — they are cutting, as the removed content is automatically "clipped" (yanked) and moved to the unnamed register. - vim defaults to an unnamed register if the register name’s not prepended to the operator
- there is 10 built-in read-only registers (0–9) you can read from when pasting, but deliberately not write into with deleting or changing
- these read-only registers are numerical — 0 through 9 — and are your “historical records” registers.
- The first of them — register 0 — is special and will always contain the most recently yanked text — but never deleted text
- This is handy for performing a yank (copy) operation (after deletion still there) + at least one delete operation + and then pasting the text originally yanked with
"0p"
; theunnamed
register would already contain deleted text as delete/change == cut in vim - The registers 1–9 are for deleted text, with “1 referencing the most recently deleted text, “2 the text deleted before that, and so on up to “9.
- To print the content of registers, use
:reg
the command; the possible types of content is:
"c" for |characterwise| text
"l" for |linewise| text
"b" for |blockwise-visual| text
Example
:reg
Type Name Content
c "" ČINNOSTI V OBLASTI INFORMAČNÍCH TECHNOLOGIÍ
c "0 ČINNOSTI V OBLASTI INFORMAČNÍCH TECHNOLOGIÍ
l "1 /input/label:LOADER
l "2 /input/description:Redshift loader - prod1
l "3 /input/uuid:582c77e1-a981-411f-93b0-3313740b256f
l "4 /input/ssh_tunnel_enabled:false
l "5 /input/ssh_tunnel/local_port:
l "6 /input/ssh_tunnel/bastion_user:
l "7 /input/ssh_tunnel/bastion_port:22
l "8 /input/ssh_tunnel/bastion_host:
l "9 /input/database_iam_load_role_arn: