Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having `f =` move to either => or ⇒

Tags:

vim

scala

I edit a lot of Scala code in Vim, which means I hit f = a lot, as I head to the RHS of a case statement (or whatever else):

case PatternMatch(a, b, c) => RHS Here

But Scala supports unicode characters, which means that a lot of people will use instead of => and that makes f ... a pain in the butt. Does anyone know how if there's a way to make f = move to the next = or , whichever comes first?

like image 242
Derek Wyatt Avatar asked Jan 11 '23 14:01

Derek Wyatt


2 Answers

Try adding this to your vimrc:

nmap f= :call search('=\\|⇒')<CR>

That will alias (map) f= to a call to the search function that will jump to the next = or .

like image 143
bundacia Avatar answered Jan 17 '23 14:01

bundacia


bundacia's answer is the one you asked for. Another option is to use digraphs. You can type in vim by typing <C-k>=> in insert mode. You can also use this digraph with the f command (e.g. f<C-k>=>). No need for mappings etc. though it may be somewhat inconvenient to type.

I prefer this solution since it preserves other operator pending commands such as df=, cf=, etc. and allows the use of F, t, etc.

like image 26
Conner Avatar answered Jan 17 '23 13:01

Conner