Nvim :help
页面,生成 于 源代码,使用 tree-sitter-vimdoc 解析器。
import pynvim
@pynvim.plugin
class Limit(object):
def __init__(self, vim):
self.vim = vim
self.calls = 0
@pynvim.command('Cmd', range='', nargs='*', sync=True)
def command_handler(self, args, range):
self._increment_calls()
self.vim.current.line = (
'Command: Called %d times, args: %s, range: %s' % (self.calls,
args,
range))
@pynvim.autocmd('BufEnter', pattern='*.py', eval='expand("<afile>")',
sync=True)
def autocmd_handler(self, filename):
self._increment_calls()
self.vim.current.line = (
'Autocmd: Called %s times, file: %s' % (self.calls, filename))
@pynvim.function('Func')
def function_handler(self, args):
self._increment_calls()
self.vim.current.line = (
'Function: Called %d times, args: %s' % (self.calls, args))
def _increment_calls(self):
if self.calls == 5:
raise Exception('Too many calls!')
self.calls += 1
remote#host#RegisterPlugin
函数的调用,该函数负责在第一次使用声明的命令、自动命令或函数时启动主机。BufEnter *.java
,那么只有在 Nvim 加载与“*.java”匹配的缓冲区时才会生成 Java 主机。