

Code Substitution Done Right - Switch.vim - vesln
http://www.vimninjas.com/2012/09/12/switch/

======
dasil003
I'm a couple years into full time MacVim use. At this stage I'm simplifying
and dropping plugins in favor of mastering builtins. I'm also separating
graphical config from standard and working on a repeatable system to push a
barebones config up to new servers as I access them.

So I'll pass on this plugin for the time being. That said, this new blog is
fantastic and I'm bookmarking all the articles for later.

------
graywh
I don't get it. How often do you need to change between complete opposites?
(should/should_not, true/false, &&/||) And what's the point of changing
"predicate?" to "true and (predicate?)" or "false or (predicate?)"

~~~
zefhous
I wrote a similar plugin called vim-cycle, it's a bit different but basically
the same concept.

<https://github.com/zef/vim-cycle>

I really use it all the time and find it extremely useful, but not exactly in
the way he seems to in the video. One of the ways I frequently use it is for
CSS, where there are related words that can frequently change, like
margin/padding, top/bottom, class/id, png/gif/jpg, absolute/relative, or in
Ruby if/unless, present/blank, else/else if. Things like that...

The mapping I use is the same as is used to increment and decrement numbers in
Vim, which is very natural to me so it's a really easy way to switch things
much more quickly than typing them.

You can see the pairs I define by default in my plugin here:

[https://github.com/zef/vim-
cycle/blob/master/plugin/cycle.vi...](https://github.com/zef/vim-
cycle/blob/master/plugin/cycle.vim)

------
loeschg
Annnnnd another tutorial that shows me how vastly underwhelming my vim skills
are.

Though looking back a year ago, I struggled to navigate, let alone copy and
paste. Step at a time, right? RIGHT?!

~~~
martswite
I recently moved to vim as well. Everything I'm doing I'm pretty much aware
that I could probably be doing it in some superdooper quick way...

I'll get there though. Eventually.

~~~
johncoltrane
Just keep going and refrain from copying verbatim other people's config and
using too many plugins.

------
ktusznio
This looks cool but I'd like filetype-independent definitions. For example, to
convert a ruby dictionary pasted into a .js file.

~~~
AndrewRadev
Well, in your case, you could put a definition for javascript. The built-in
"ruby hash style" transformation should work for this:

    
    
        " in ftplugin/javascript.vim
        let b:switch_definitions =
              \ [
              \   g:switch_builtins.ruby_hash_style
              \ ]
    

With this, in a javascript file, you can turn ":foo => 'bar'" entries into
"foo: 'bar'" ones.

If you do need global (non-filetype) switches, you could define some by
placing them in the g:switch_definitions variable. Read up on the docs if you
want more information.

