简体   繁体   English

gvim弹出菜单项仅在Nerdtree窗口中

[英]gvim popup menu item only in Nerdtree window

I have a following menu item 我有以下菜单项

nnoremenu 1.120 PopUp.Add\ &To\ &&Path          :call NERDTreeAddNodeToPath()<CR>

but I want it to show only in Nerdtree window, how do I do it? 但是我希望它仅在Nerdtree窗口中显示,我该怎么做?

I think I've cracked this, but it's not as pretty as I had hoped. 我认为我已经破解了,但是它没有我希望的那么漂亮。 I have written a function NERDTreeMenuToggle() which adds the line to the popup menu if the current buffer is filetype "nerdtree", otherwise the line is removed from the menu: 我编写了一个函数NERDTreeMenuToggle() ,如果当前缓冲区的文件类型为“ nerdtree”,则将该行添加到弹出菜单,否则从菜单中删除该行:

function! NERDTreeMenuToggle()
    if &ft == "nerdtree"
        nnoremenu 1.120 PopUp.Add\ To\ Path :call NERDTreeAddNodeToPath()<CR>
    else
        silent! nunmenu PopUp.Add\ To\ Path
    endif
endfunction

Note that nunmenu must be called silently to suppress errors if the menu item doesn't exist. 请注意,如果菜单项不存在, nunmenu必须静默调用nunmenu以抑制错误。 Next we must set this function to be called on the MenuPopup event (ie just before the menu is displaued). 接下来,我们必须将此函数设置为在MenuPopup事件上MenuPopup (即,在菜单不受欢迎之前)。

au! MenuPopup * :call NERDTreeMenuToggle()

That seems to do the trick (although I am not a regular user of NERDTree, so I may be missing some subtleties. 这似乎可以解决问题(尽管我不是NERDTree的常规用户,所以我可能会遗漏一些细节。

Another approach would be to add the line to menu in a new filetype plugin (just put the nnoremenu line in a file called nerdtree.vim in $VIM/vimfiles/ftplugin) but this still leaves the problem of removing the line for non-NERDTree buffers, so I think my solution above is slightly cleaner. 另一种方法是将行添加到新文件类型插件的菜单中(只需将nnoremenu行放在$ VIM / vimfiles / ftplugin中名为nerdtree.vim的文件中),但这仍然留下了删除非NERDTree行的问题缓冲区,所以我认为上面的解决方案稍微干净一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM