I'm trying to jump to the next python class or function in vim with the following commands:
autocmd FileType python nnoremap <buffer> [[ ?^class|^\s*def<CR>
autocmd FileType python nnoremap <buffer> ]] /^class|^\s*def<CR>
But it doesn't work. Vim prompted:
Error detected while processing FileType Auto commands for "python":
E492: Not an editor command: ^\s*def<CR>
How to fix this?
After lots of trying, I found the following code worked. I need to add \\ before |
autocmd FileType python nnoremap <buffer> [[ ?^class\\|^\s*def<CR>
autocmd FileType python nnoremap <buffer> ]] /^class\\|^\s*def<CR>
As an alternative way, I found that putting the two lines in ~/.vim/ftplugin/python.vim is more convenient
nnoremap [[ ?^class\|^\s*def<CR>
nnoremap ]] /^class\|^\s*def<CR>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With