英文:
Adding timestamp in vim, in config file
问题
我已经将以下行添加到我的vim配置文件中:
inoremap <leader>dt r! date "+\%Y-\%m-\%d<CR>"
为了添加一个快捷键以打印当前日期。但是当我在正常模式下使用快捷键时,它只会打印字符串:"r! date "+%Y-%m-%d
英文:
I have added the following line to my vim config file:
inoremap <leader>dt r! date "+\%Y-\%m-\%d<CR>
In order to add a shortcut for printing the current date. But when I use the shortcut in normal mode it only prints the string: "r! date "+%Y-%m-%d<CR>".
Why is that? What am I doing wrong?
答案1
得分: 0
But when I use the shortcut in normal mode it only prints the string: "r! date "+%Y-%m-%d".
Why is that?
但当我在正常模式中使用快捷方式时,它只打印字符串:"r! date "+%Y-%m-%d"。
这是因为你是在 插入模式 中操作,而不是在 "正常模式" 中。
What am I doing wrong?
你的问题可能在于你没有清楚地解释你究竟想要实现什么,而是要求修复你有问题的解决方案。这被称为 XY 问题,是一个很容易陷入的常见陷阱。实际上,由于你似乎对Vim完全按照你的要求操作感到惊讶,可能你自己也不太确定。你能否澄清一下这一点?请问你想要实现什么?
英文:
> But when I use the shortcut in normal mode it only prints the string: "r! date "+%Y-%m-%d".
You are doing that in insert mode, not "normal mode".
> Why is that?
Vim is doing exactly what you ask it to do, which is to insert the string r! date "+\%Y-\%m-\%d<CR>
when you press <leader>dt
in insert mode.
> What am I doing wrong?
The most salient item in the list would be that you didn't explain what, exactly, you are trying to achieve, asking instead for a fix to your flawed solution. This is known as the XY problem and a very common trap to fall into. In fact, since you appear to be surprised by Vim doing exactly what you ask it to do, it is possible that you are not sure about it yourself. Can you clarify this, please?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论