vim 如何快速创建调试消息
我正在 Rails 上使用 ruby,但这对于这个问题来说并不重要。假设我有一个这样的声明,
error = 'this is an error message'
我注意到我最终做了很多这样的
error = 'this is an error message'
puts "error = #{error.inspect}"
事情,我确信可以编写一个宏,它将完成最左边=左侧的工作,然后与模板一起创建另一行如上所示。
我在 mac 上使用 mvim。关于我应该从哪里开始寻找开发我想要的东西的任何指示。
I am using ruby on rails but that does not matter much for this question. Let's say that i have a statement like this
error = 'this is an error message'
I have noticed that I end up doing this a lot
error = 'this is an error message'
puts "error = #{error.inspect}"
I am sure a macro can be written which would take the work on the left hand side of left most = and then create another line along with template shown above.
I am using mvim on mac. Any pointer in terms of where I should start to look for developing what I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试截图:
http://www.vim.org/scripts/script.php?script_id= 2540
Try snipmate:
http://www.vim.org/scripts/script.php?script_id=2540
我录制了一个简单的宏来执行您的示例。要记录宏,请键入 q,后跟要放入宏的寄存器(约定要求 qq)。要播放宏,请输入 @,然后进行宏注册。您可以在
:help reporting
处查看此宏。要编写宏,请使用以下命令(这里是寄存器中的外观)
^
移动到第一个非空白yE
行的字符被拉到空格分隔的单词的末尾。
o
让您在下一行进入插入模式puts "error = #{
是您键入的文本^O
是 ctrl+O(大写字母 o) - 这允许下一个且仅下一个命令在命令模式下运行,即...p
放置被拉出的单词,运行此命令后您仍处于插入模式.inspect}"
是您键入的文本,最后...^[
是 < kbd>EscI recorded a simple macro that does your sample. To record a macro type q followed by what register you want the macro to be put in (convention calls for qq). To play the macro type @ then the macro register. You can view this at
:help recording
To write the macro, use the following commands (and here is how is should look in the register)
^
moves to the first non whitespace character of the lineyE
yanks to the end of the space separated word.o
Puts you in insert mode on the next lineputs "error = #{
is the text that you type out^O
is ctrl+O (capital letter o) - this allows the next, and only the next command to be run in command mode, which is...p
Puts the yanked word, after this command is run you're still in insert mode.inspect}"
is the text that you type and finally...^[
is Esc我会选择:
:s
展示了完成工作以及匹配分配的变量(如果有)的优势。使用yw
、p
等经典命令执行相同的操作会更加麻烦。如果模板变得更加复杂,我们可以依赖模板文件扩展器,只要它们能够轻松调用 viml 函数,例如
matchstr()
。当然,在这种情况下,我会使用 mu-template 和以下模板文件:I would go for:
:s
presents the advantage of doing the job plus matching the assigned variable if any. Doing the same thing with classical commands likeyw
,p
, etc would be more cumbersome.If the template become more complex, we can rely on template-file expanders as long as they easily permit to call viml function like
matchstr()
. Of course, in that case I would use mu-template with the following template-file:如果您正在即时执行这些操作,则片段片段可能如下所示:
另一方面,如果您只想输出预先存在的变量以进行调试。尼克-坎佐内里的宏可能更有用。
If you're doing these on the fly, a snipmate snippet could look like this:
If, on the other hand you're just wanting to output pre-existing variables for debugging purposes. Nick-Canzoneri's macro may be more useful.