An extension for IdeaVim that adds text objects for manipulating
functions/methods in your code. Similar to how iw
operates on words or i"
operates on quoted strings, this plugin provides if
and af
to operate on
functions.
if
- "inner function" - selects the function body (excluding braces)af
- "around function" - selects the entire function (including braces and signature)
These text objects work with all Vim operators and in visual mode:
dif - delete the function body
caf - change the entire function
vif - visually select the function body
yaf - yank (copy) the entire function
This extension supports function/method selection in the following languages using the Jetbrains language plugins:
- C#
- Dart
- Go
- Java: : Already included default in IntelliJ
- JavaScript/ECMAScript 6/TypeScript: Already included default in IntelliJ
- Kotlin
- PHP
- Perl 5
- Python
- R
- Ruby
- Rust
- Scala
- Install IdeaVim if you haven't already
- Install this plugin:
- In IntelliJ IDEA: Settings/Preferences → Plugins → Marketplace → Search for "Vim FunctionTextObj"
- Or download from JetBrains Marketplace
- Add
set functiontextobj
to your~/.ideavimrc
file, then run:source ~/.ideavimrc
or restart the IDE.
Don't like the default f
mapping? You can remap the text objects in your
.ideavimrc
:
" Use 'm' instead
omap im <Plug>InnerFunction
omap am <Plug>OuterFunction
vmap im <Plug>InnerFunction
vmap am <Plug>OuterFunction