Skip to content

Instantly share code, notes, and snippets.

@arunbear
Last active April 27, 2025 12:07
Show Gist options
  • Save arunbear/633b136713c7177a1432c8ac3d8b7157 to your computer and use it in GitHub Desktop.
Save arunbear/633b136713c7177a1432c8ac3d8b7157 to your computer and use it in GitHub Desktop.
Selecting a whole method in Vim (Java)
" Select the current method
"
" ]M move to the end of the method
" V enter visual line mode
" % move to the matching open brace
"
nnoremap <leader>m ]MV%
" Copy the current method and paste below
" Use this after the above
"
" y copy the selection
" ]M move to the end of the method
" p paste
"
vnoremap <leader>p y]Mp
" Select the current method and copy to below
" Combines the two above
" Also selects annotations above the method
"
nnoremap <leader>sp ]MV%{y]Mp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment