尝试编写 Vim 函数/命令?
我正在使用 Janus(尽管这对于理解这个问题并不是关键)。基本上他们所做的就是将 :e 重写为 :Edit 以与 NERDTree 一起使用,但 NERDTree 不支持强制打开文件(例如 e!)。所以我写了一些重写的东西:编辑!到 :e!,但我喜欢只使用 :Edit! 的好处,所以我试图欺骗它,就好像它已经内置一样。这就是我想到的:
ca Edit! e! <bar> Edit
唯一的问题是,你可以'对于尚未保存至少一次的文件,不要执行此操作。但我知道这样做
ca Edit! bd! <bar> Edit
会起作用:它将关闭未保存的缓冲区并继续前进,就像什么都没发生一样。我所需要做的就是编写逻辑,以便始终在正确的场景中使用正确的命令。最好逻辑不会在每个页面上运行:只有当我实际运行命令时,它才应该尝试找出答案。有什么想法吗?
编辑:我尝试询问 #vim 频道(给了我很多帮助)...他们说使用 Expand("%") 并检查它是否存在可能对我的情况有帮助?不知道,只是尽可能提供详细信息。
I'm using Janus (isn't pivotal to understand the question though). Basically what they do, is rewrite :e to be :Edit to work with NERDTree, but NERDTree doesn't support force opening a file (e.g. e!). So I had written something that rewrites :Edit! to :e!, but I like the benefits of using just :Edit!, so I'm trying to spoof if as if it was already built in. This is what I came up with:
ca Edit! e! <bar> Edit
The only problem, is that you can't do that for files that haven't been saved at least once. But I know doing
ca Edit! bd! <bar> Edit
will work: it will close the unsaved buffer and keep moving like nothing happened. All I need to do is write logic that will use the correct command in the right scenario all the time. Preferably the logic doesn't run on every page: only when I actually run the command should it attempt to figure it out. Any ideas?
Edit: I tried asking the #vim channel (gave me tons of help)... they said using expand("%") and checking to see if it exists might help my case? Don't know, just providing as much detail as I can.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个。定义一个这样的函数:
然后定义你的缩写,如下所示:
Try this. Define a function like this:
Then define your abbreviation like this: