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

标签 python vim

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

autocmd FileType python nnoremap <buffer> [[ ?^class|^\s*def<CR>
autocmd FileType python nnoremap <buffer> ]] /^class|^\s*def<CR>

但它不起作用。 Vim 提示:

Error detected while processing FileType Auto commands for "python":
E492: Not an editor command: ^\s*def<CR>

如何解决这个问题?

最佳答案

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

之前添加 \\
autocmd FileType python nnoremap <buffer> [[ ?^class\\|^\s*def<CR>
autocmd FileType python nnoremap <buffer> ]] /^class\\|^\s*def<CR>

作为替代方式,我发现将这两行放在~/.vim/ftplugin/python.vim中更方便

nnoremap [[ ?^class\|^\s*def<CR>
nnoremap ]] /^class\|^\s*def<CR>

关于python - 在 vim 中跳转到下一个 python 类或函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34625912/

相关文章:

python - 为什么 `for lst in lst:` 有效?

python - 我如何知道 Windows 中正在运行哪些 python 脚本?

vim : expand in :h

vim - 如何让帮助窗口始终在同一位置打开?

git - Vim:在没有 Fugitive 的 lightline 状态行中显示当前的 git 分支

jquery - 如何在 Backbone.js 中加载具有外键关系的子模型?

尽管存在 Mac,Python pandas read_csv 返回 FileNotFoundError

python - python Tkinter 中带有 strftime 的七段数字时钟与系统时间

vim - CTRL+空格在 Vim 中起什么作用?

用于更改目录的 Vim 别名