在Vim中,添加时间戳到配置文件中。

huangapple go评论53阅读模式
英文:

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 &lt;leader&gt;dt r! date &quot;+\%Y-\%m-\%d&lt;CR&gt;

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 &quot;+\%Y-\%m-\%d&lt;CR&gt; when you press &lt;leader&gt;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?

huangapple
  • 本文由 发表于 2023年2月14日 20:49:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/75448086.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定