Motion ][: next } in the first column
V][d does what you want. More details can be found under :h ][ and :h section:
*section*
[...]
The "]" and "[" commands stop at the '{' or '}' in the first column. This is
useful to find the start or end of a function in a C program. Note that the
first character of the command determines the search direction and the
second character the type of brace found.
Furthermore, vim's user manual has dedicated a paragraph about them within section 29.3 Moving through a program (:h 29.3).
Chapt. 50 Section Movement Theory in the free ebook Learn Vimscript the Hard Way by Steve Losh gives you more background about them and explains in a subsequent chapter how to adapt them for a new language.
Memorizing
If you are not familiar with the set of square bracket motions [[, [], ]], ][ and you struggle memorizing, maybe following grouping and hints help:
[[ and ]] jump to the beginning (i.e. {) of the current/previous and next function
[] and ][ jump to the end (i.e. }) of the previous and current/next function
As mentioned in the vim help page: the first square bracket you type determines the direction you move and the second bracket the type you are looking for. The second bracket is more difficult to grasp because the meaning can be seen as inconsistent: [ relates not to { and ] not to }.
I memorize it as
- beginning of function: square bracket must be repeated
- end of function: square bracket must be alternated
Are these not too specific to be generally useful aka exotic?
I think it is worthwhile to learn them: many languages use curly braces. Additionally, ftplugins in $VIMRUNTIME/ftplugin override them for many languages, which are not curly brace based, most prominently python, ruby, sql, and vimscript. They offer semantic equivalents for the respective languages.
Also third party ftplugins for latex (vimtex), markdown (vim-markdown by plasticboy), html/xml (xml.vim), manpages (vim-man) and more remap them (fugitive, jumpy.vim).
Note there are different expectations of what the equivalents should be. For instance, pythonsense provides alternatives for python. For markdown there are also several plugins which offer different versions: plasticboy/vim-markdown, vim-pandoc, gabrielelana/vim-markdown, pandoc-sections.vim.
UPDATE
nvim-treesitter-textobjects suggests to use them for movement in classes. IMHO this limits the usefulness of them: they should apply to classes and methods since pressing [[ and ]] is quick and navigating functions is more common.
Egyptian Brackets
For code which uses Egyptian Brackets for functions and classes, vim help suggests to customize [[, [], ]], ][:
If your '{' or '}' are not in the first column, and you would like to use "[["
and "]]" anyway, try these mappings: >
:map [[ ?{<CR>w99[{
:map ][ /}<CR>b99]}
:map ]] j0[[%/{<CR>
:map [] k$][%?}<CR>
[type these literally, see |<>|]
Typical languages are java, rust and go. Actually, the end of function motions could be left unchanged. $VIMRUNTIME/ftplugin/rust.vim and the third-party plugin vim-go remap only [[ and ]] for you. Also $VIMRUNTIME/ftplugin/php.vim remaps only [[ and ]] to jump to keywords like function or class regardless whether Egyptian style is used.
Also the plugin lh-dev by Luc Hermitte tries to help here.
V][d? – Hotschke Oct 30 '18 at 08:04Vj%d– Rich Oct 30 '18 at 11:16