简体   繁体   English

如何在命令行模式下打印 vim 寄存器值?

[英]how can i print vim register value in command line mode?

Hey i want to print javap java.lang.Object in vim terminal but not for only 'Object' class but any class that i yanked in particular register. Hey i want to print javap java.lang.Object in vim terminal but not for only 'Object' class but any class that i yanked in particular register.

let say i yanked word Integer with "kyaw in vim so i want to print output of javap java.lang.Integer . let say i yanked word Integer with "kyaw in vim so i want to print output of javap java.lang.Integer .

For that i tried this command but that's not working.为此,我尝试了这个命令,但这不起作用。

:term javap "java.lang.${echo @k}"

but in vim terminal it's giving me error like但在 vim 终端中,它给了我类似的错误

zsh:1: bad substitution

i think that echo @k is not working in " so what i do to expand there particular keyword like Object or Integer .我认为echo @k"中不起作用,所以我要如何扩展特定的关键字,例如ObjectInteger

I think it's easier to build the command as a string then run it with :execute :我认为将命令构建为字符串然后使用:execute运行它更容易:

:execute 'term javap \"java.lang.'..@k..'\"'

or或者

:execute printf('term javap \"java.lang.%s\"', @k)

Note that the " are escaped with a backslash, and .. is the string concatenation operator.请注意, "使用反斜杠进行转义,而..是字符串连接运算符。

In the command-line, inserting the content of a register is done with :help c_ctrl-r .在命令行中,使用:help c_ctrl-r插入寄存器的内容。 In your case:在你的情况下:

:term javap java.lang.<C-r>k<CR>

Which could easily be turned into a simplistic mapping:这可以很容易地变成一个简单的映射:

nnoremap <key> :term javap java.lang.<C-r>k<CR>

And improved by using the word under the cursor directly instead of yanking something in a separate step:并通过直接使用 cursor 下的单词进行改进,而不是在单独的步骤中拉动某些东西:

nnoremap <key> :term javap java.lang.<C-r><C-w><CR>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM