How can I delete the block

int Test()

when my cursor is before int (or even better when it is anywhere on that line)?

The shortest I could come up with is d<line>G where <line> is the line number of the closing brace, or d<diff>j where <diff> is the difference of the line number. I am not happy with either.


3 Answers 3


Motion ][: next } in the first column

V][d does what you want. More details can be found under :h ][ and :h 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.


If you are not familiar with the set of square bracket motions [[, [], ]], ][ and you struggle memorizing, maybe following grouping and hints help:

  1. [[ and ]] jump to the beginning (i.e. {) of the current/previous and next function
  2. [] 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

  1. beginning of function: square bracket must be repeated
  2. 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.


The paragraph (ip, ap) and curly brace (i{, a{) motions are good for this. The curly braces may need to be forced linewise with Va}, but they still wont capture the method declaration.

If, like me, you put blank lines between methods, the paragraph motion is suitable and succinct (and does not require memorization of which square bracket does what). dap (or dVap) rolls off my fingers because I use it so frequently.

  • 2
    I also quite like ip/ap. However, usually you cannot be sure that there are no blank lines within a function/method. Also iB/aB (= i{/a{ = i}/a}) do not select the 'header' line of the function (int Test()).
    – Hotschke
    Commented Oct 30, 2018 at 13:58
  • @Hotschke agreed, i hadnt thought about the inner body much. Though id argue blank lines in the body is an opportunity for refactoring :P i noted in answer about the declaration line.
    – D. Ben Knoble
    Commented Oct 30, 2018 at 14:21
  • va{V will capture the header declaration too Commented May 23, 2021 at 20:55
  • @SebastianNielsen isnt that the same as Va{, which I mention? And that’s only true in a style with the curly brace on the same line as the decl
    – D. Ben Knoble
    Commented May 23, 2021 at 23:43
  • @D.BenKnoble For me Va{ yeilds the same as va{, but that might just be because I am using .ideavim -- which is known to be rather buggy, and I can surely attest to that! Commented May 24, 2021 at 22:00

Vim often provides many ways to do things! Here are a couple of alternatives to the existing answers:

Using %


  • V Enter linewise visual mode
  • j Move down to the opening bracket
  • % Jump to the matching closing bracket
  • d Delete the selected text

Using a forced linewise motion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.