An IdeaVim extension inspired from switch.vim to switch between related text segments.
set switch
to your ~/.ideavimrc
file, then run :source ~/.ideavimrc
or restart the IDE.Place your cursor on a term and use:
:Switch
to cycle forward through alternatives:SwitchReverse
to cycle backwardYou 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>
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'
group:basic
)basic_binary
): 0
↔ 1
basic_up_down_left_right
): up
↔ down
↔ left
↔ right
(case insensitive)basic_logical_ops
): &&
↔ ||
basic_bitwise_ops
): &
↔ |
basic_true_false
): true
↔ false
(case-insensitive)basic_and_or
): and
↔ or
(case-insensitive)basic_equality
): ==
↔ !=
basic_is_is_not
): is
↔ is not
basic_quotes
): "string"
↔ 'string'
↔ `string`
group:java
)java_assert_equals
): assertEquals
↔ assertNotEquals
java_assert_true_false
): assertTrue
↔ assertFalse
java_assert_null
): assertNull
↔ assertNotNull
java_visibility
): private
↔ protected
↔ public
java_optional_check
): isPresent()
↔ isEmpty()
group:javascript
)javascript_function
): Transform between function syntaxes
function name() {
↔ const name = () => {
async function name() {
↔ const name = async () => {
javascript_arrow_function
): function(x) {
↔ (x) => {
javascript_es6_declarations
): var
↔ let
↔ const
group:rspec
)RSpec patterns:
rspec_should
): should
↔ should_not
rspec_to
): .to
↔ .not_to
↔ .to_not
rspec_be_truthy_falsey
): be_truthy
↔ be_falsey
rspec_be_present_blank
): be_present
↔ be_blank
group:ruby
)ruby_hash_style
): :key => value
↔ key: value
ruby_oneline_hash
): Similar to hash_style but for compact syntaxruby_lambda
):
lambda { |x| }
↔ -> (x) { }
lambda { }
↔ -> { }
ruby_if_clause
):
if condition
↔ if true or (condition)
if true or (condition)
↔ if false and (condition)
if false and (condition)
↔ if condition
ruby_array_shorthand
): ['a', 'b']
↔ %w(a b)
ruby_fetch
): hash[key]
↔ hash.fetch(key)
ruby_assert_nil
): assert_nil x
↔ assert_equal nil, x
group:rust
)rust_void_typecheck
):
let x =
↔ let x: () =
rust_turbofish
):
parse()
↔ parse::<Todo>()
rust_string
):
"text"
↔ r"text"
↔ r#"text"#
rust_is_some
): is_some
↔ is_none
rust_assert
): assert_eq!
↔ assert_ne!
cargo_dependency_version
):
package = "1.0"
↔ package = { version = "1.0" }
group:scala
)String interpolation (scala_string
), cycles through:
"text"
s"text"
f"text"
"""text"""
s"""text"""
, f"""text"""
group:markdown
)markdown_task_item
): - [ ] Buy milk
↔ - [x] Buy milk
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:
switchWords(words)
: Creates patterns that cycle through words in order, matching exact words with word boundaries
switchWords(['yes', 'no'])
matches exactly 'yes' or 'no' and cycles between themswitchNormalizedCaseWords(words)
: Like switchWords
but case-insensitive
switchNormalizedCaseWords(['GET', 'POST'])
matches 'GET'/'get'/'Get' and cycles to 'POST'/'post'/'Post' preserving the original case