Reputation: 1587
I know that Vim has "[[" and "]]" shortcuts to move between functions. But how can I add this functionality not only for C but for Pascal syntax?
Upvotes: 4
Views: 177
Reputation: 172778
Some filetypes redefine the built-in ]]
mappings to jump to the beginning of the next function. For example, have a look $VIMRUNTIME/ftplugin/vim.vim
:
" Move around functions.
nnoremap <silent><buffer> [[ m':call search('^\s*fu\%[nction]\>', "bW")<CR>
vetlocal foldmethod< foldtext< foldexpr< | delcommand FoldToggle oremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*fu\%[nction]\>', "bW")<CR>
You can define similar mappings (e.g. to the begin
/ end
keywords) in ~/.vim/after/ftplugin/pascal.vim
.
If you want a comfortable plugin that makes it easy to setup those mappings, supports [count], and also offers text objects to select an entire function, have a look at my CountJump plugin. There's even an example about Pascal in its help:
:call CountJump#Motion#MakeBracketMotion('<buffer>', '', '', '\c^begin\n\zs', '\c^.*\nend', 0)
Upvotes: 1