Question

When you are not in insert more in vim, and you delete something, this gets automatically in the clipboard. Does this clipboard work like a stack?

If the clipboard is a stack, how can I access previous entries in this stack? If the clipboard is not a stack, how does it work? Can it save multiple data entries in the same time? And how to access them?

What I want is to create a macro (recording) that gets the Nth entry in this clipboard stack or to get several data entries if they can be saved in the same time in memory.

Was it helpful?

Solution

I wouldn't say it is a stack. it works like stack ( for deletion) .

I think you need to take a look "numbered registers".

Vim has 0-9 numbered registers. If you think it as a stack, the size of the stack is 9 (1-9) for deletion.

Yanked things were stored in register 0 and "", no stack structure.

I said it works "stack like" but not stack (for deletion) because, with stack data structure, you could not randomly fetch element. you can just pop or push. but with vim's register, you could get any (0-9) element by "1 "3 "5 for example, and keep the "stack" without changing.

read :h registers for detail.

OTHER TIPS

The system clipboard (register "+) is not a stack, unless you use an external tool (e.g. ClipX on Windows, or Glipper on GNOME) to provide a history at the operating system-level.

I think you mean the default Vim registers. There, indeed, deletes and changes (of at least an entire line) are copied to the numbered registers. The current delete goes into "1, its contents move into "2, etc.

See :help quote_number for details.

Like any other register, you can access them via the p normal mode command (e.g. "1p), :put {reg}, <C-r>{reg} from insert mode, or via getreg() or @{reg} programmatically.

Kind of.

Vim uses registers for yanking and deleting.

  • The unnamed register, "", is always used except when you explicitly use the "black hole register".

  • The numbered registers, "0-9, are used when you yank or delete without using a specific register.

The exact mechanism is a bit tricky so I'd suggest you take a look at :h registers

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top