在 vim 中跳转到下一个 python 类或函数

Sea*_*ene 8 python vim

我试图使用以下命令跳转到 vim 中的下一个 python 类或函数:

autocmd FileType python nnoremap <buffer> [[ ?^class|^\s*def<CR>
autocmd FileType python nnoremap <buffer> ]] /^class|^\s*def<CR>
Run Code Online (Sandbox Code Playgroud)

但这不起作用。Vim 提示:

Error detected while processing FileType Auto commands for "python":
E492: Not an editor command: ^\s*def<CR>
Run Code Online (Sandbox Code Playgroud)

如何解决这个问题?

Sea*_*ene 6

经过多次尝试,我发现以下代码有效。我需要\\在之前添加|

autocmd FileType python nnoremap <buffer> [[ ?^class\\|^\s*def<CR>
autocmd FileType python nnoremap <buffer> ]] /^class\\|^\s*def<CR>
Run Code Online (Sandbox Code Playgroud)

作为替代方法,我发现将两行放入~/.vim/ftplugin/python.vim更方便

nnoremap [[ ?^class\|^\s*def<CR>
nnoremap ]] /^class\|^\s*def<CR>
Run Code Online (Sandbox Code Playgroud)