Warm tip: This article is reproduced from serverfault.com, please click
vim

How to enter multiple lines of commands from a register?

发布于 2020-12-02 00:34:34

How can I execute multiple lines of Vim Ex commands from a register? For example, if I copy some mappings I want to try, how can I execute these lines within the current buffer, from the register I've copied them to?

nnoremap <leader>b :tab split<cr>
nnoremap <buffer> ...
...

I've tried using : followed by <ctrl-r>" (assuming the lines are in the unnamed register) to paste the lines in command line mode, followed by hitting <cr>. The lines that are pasted appear to be separated by ^M, as opposed to newlines. The approach does not work.

I've also tried using q: to open the command-line window, followed by <ctrl-r>", and then hitting enter, but this only executes the current line, rather than all lines I've pasted.

I could paste the lines into a file, and then source that file, but I am looking for an alternative, more direct approach.

Questioner
dannyadam
Viewed
0
filbranden 2020-12-02 09:14:03

You can use :@" to run the contents of the default register as an Ex command.

See :help :@.