jphalip / ideavim-switch

MIT License
1 stars 0 forks source link

IdeaVim Switch

An IdeaVim extension inspired from switch.vim to switch between related text segments.

Installation

  1. Install IdeaVim if you haven't already
  2. Install this plugin:
    • In IntelliJ IDEA: Settings/Preferences → Plugins → Marketplace → Search for "Vim-Switch"
    • Or download from JetBrains Marketplace
  3. Add set switch to your ~/.ideavimrc file, then run :source ~/.ideavimrc or restart the IDE.

Usage

Place your cursor on a term and use:

You might want to map these commands, for example:

" Map to <leader>s and <leader>S
nmap <leader>s :Switch<CR>
nmap <leader>S :SwitchReverse<CR>

" Or use - and +
nmap - :Switch<CR>
nmap + :SwitchReverse<CR>

Configuration

Enable patterns in your .ideavimrc either by group or individual patterns:

" Enable all patterns from multiple groups
let g:switch_definitions = 'group:basic,group:java,group:rspec'

" Enable specific patterns
let g:switch_definitions = 'basic_true_false,java_visibility,rspec_should'

" Mix groups and individual patterns
let g:switch_definitions = 'group:basic,java_visibility,rspec_should'

Built-in Patterns

Basic (group:basic)

Java (group:java)

JavaScript (group:javascript)

RSpec (group:rspec)

RSpec patterns:

Ruby (group:ruby)

Rust (group:rust)

Scala (group:scala)

String interpolation (scala_string), cycles through:

Markdown (group:markdown)

Custom Patterns

Define your own patterns using the provided VimScript functions:

let g:switch_custom_definitions = [
    " Basic word cycling (with word boundaries)
    \ switchWords(['debug', 'info', 'warn', 'error']),

    " Case-insensitive word cycling (with word boundaries)
    \ switchNormalizedCaseWords(['GET', 'POST', 'PUT', 'DELETE']),

    " Custom regex patterns (each pattern is a pair of [match, replacement])
    \ ['width:\s*(\d+)px', 'width: \1em'],
    \ ['height:\s*(\d+)px', 'height: \1em']
\ ]

Available functions: