Vim 脚本:缓冲区/CheatSheet 切换
我想做一个 vim 备忘单插件。这真的很简单:
- 我想切换我的备忘单。 vertsplit 切换,如 Taglist 或 NERDTree。
- 我希望备忘单是特定于文件类型的。因此,当我打开 .cpp 文件时,我会切换我的 C++ 备忘单。
- 我希望备忘单水平分割。所以它显示了两个文件,我的语法备忘单和我的片段触发器备忘单。
我已经收集了这些备忘单,采用 vimhelp 格式,但现在我必须手动打开它们。
我还没有真正编写过任何 vim 脚本,但我想这会很容易组合在一起。我有点厌倦了在谷歌上搜索不相关的代码片段,所以我在这里问的是:
有人能给我一个关于 vim 脚本我需要学习的简短总结吗?我很难找到如何切换缓冲区窗口。
如果您知道任何介绍性教程涵盖了我启动并运行此程序所需的材料,请提供一个链接。
TX,
活动b
I want to make a vim cheat sheet plugin. It's real simple:
- I want to toggle my cheatsheets. A vertsplit toggle, like Taglist or NERDTree.
- I want the cheatsheet to be filetype specific. So I toggle my c++ cheatsheet when I have opened a .cpp file.
- I want the cheatsheet to be horizontally split. So it shows two files, my syntax cheat sheet and my snippet trigger cheat sheet.
I already have a collection of these cheatsheets, in vimhelp format, but now I have to manually open them.
I haven't really done any vim scripting, but I imagine this would be really simple to put together. I'm sorta sick of googling unrelated codesnippets, so what I'm asking here is:
Could anyone give me a short sum-up of what I need to learn in regards to vim scripting to piece this together. What I have a hard time finding is how to toggle the buffer window.
If you know any intro tutorials that covers the material I need to get this up and running, please provide a link.
tx,
aktivb
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面的函数可能无法完全满足您的要求,而且我还没有测试过它,但它应该可以给您一些想法。
主要思想是该函数读取当前缓冲区的文件类型(您可以通过键入
:echo &ft
进行测试),然后设置适当的备忘的路径。如果存在,则在拆分窗口中打开该路径(只读且不可修改)。然后,您可以按照您希望的方式调用此函数,例如将其映射到 {F5} 键,如图所示。我不确定切换的可能性(这真的比关闭分割窗口更容易吗?),但您可以查看 bufloaded() 函数,该函数返回当前是否正在访问给定文件。
希望这有帮助。如果有任何不清楚的地方,或者您想了解更多,请大声喊出来。
The function below may not do exactly what you want, and I haven't tested it, but it should give you some ideas.
The main idea is that the function reads the filetype of the current buffer (you can test this by typing
:echo &ft
) and then sets the path of the appropriate cheat sheat. If it exists, this path is then opened (read-only and non-modifiable) in a split window. You can then call this function any way you wish, for example by mapping it to the {F5} key as shown.I'm not sure about the toggling possibilities (is this really easier than just closing the split window?) but you could look at the bufloaded() function, which returns whether or not a given file is currently being accessed.
Hope this helps. Just shout if anything is unclear, or you want to know more.
我已经忘记了这一点,直到我收到 Eduan 的回答。自从我发布这个问题以来,我已经编写了相当多的 vim 脚本,包括让它工作:
I had forgotten about this until I got a notice about Eduan's answer. Since I posted this question I've done quite a bit of vim scripting, including getting this to work:
我想我应该补充一下炖牛肉的答案。
我认为为了实现切换,您只需使用一些 if 语句和全局变量即可。
希望这能弄清楚这个逻辑。 :)
Thought I would add to Goulash's answer.
I think in order to implement the toggle you would simply use some if statements and a global variable.
Hope this figures out that logic. :)