How to map `df` in vim to delete the file under cursor

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

How to map `df` in vim to delete the file under cursor

问题

  1. df 在 vim 中有任何原始(默认)功能吗?
  2. 如何将 df 映射到 删除光标下的文件
英文:

I know gf opens the file under cursor, which is so nice. But I want delete the file under cursor. Here are two questions.

  1. Does df have any original(default) function in vim?
  2. How to map df to delete the file under cursor?

答案1

得分: 4

绑定按键盲目删除文件是危险的,应该避免。另一方面,交互式地输入这样的命令并不难:

:!rm <ctrl-r><ctrl-f><enter>

因此,只需大约八次按键即可安全执行。

英文:

Binding keys to blindly delete file is dangerous and should be avoided. On the other hand, it is not so hard to type such command interactively:

:!rm &lt;ctrl-r&gt;&lt;ctrl-f&gt;&lt;enter&gt;

So it takes only about eight key hits to do it safely.

答案2

得分: 1

我想删除Markdown的图像文件。

这是我的解决方案:

noremap df :call system("rm -f ".expand("<cfile>"))<cr>

当光标位于斜杠上时,我按下 df,但什么都没有被删除。

英文:

I want delete the image file of markdown.

well, here is my solution

noremap df :call system(&quot;rm -f &quot;.expand(&quot;&lt;cfile&gt;&quot;))&lt;cr&gt;

I press df when the cursor is on a slash, and nothing is deleted.

huangapple
  • 本文由 发表于 2023年5月18日 13:47:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76278057.html
匿名

发表评论

匿名网友

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

确定