Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?)"


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...


I'm the plugin writer. The should/should_not dance is something I keep doing when I write tests. Say I create a user with certain properties and I assert something about them:

    create(:user, :active => true).should be_active
Now, I want to change its properties and assert the opposite. I duplicate the line, change the property, and switch the "should" into a "should_not":

    create(:user, :active => false).should_not be_active
This is a very simple example, but I do things like this on a regular basis while writing tests. I assume other people have different workflows around this, but this works nicely for me. That's why I mentioned in the video that these are my own little timesavers, so you might not find them that useful :).

As for the predicate stuff, it's actually "true or (predicate?)". The idea is that switching to this would result in the first branch always being executed, unconditionally. I use this for view templates when I want to see how the page looks when, for example, there's no logged in user (it'd take more time to log out and then back in :)), or when the user has no trading accounts, or some other simple condition that I want to disable for just a sec to check out if some div got misaligned.

Really, the basic idea is simple -- if there's some code that you often need to change into some other code, you could store that transformation as a "switch" and avoid repeating yourself.


I'm guessing the latter is intended to help you add more conditions. Switch "if foo?" to "if true and (foo?)", which has the same meaning, then replace the "true" to get "if bar? and (foo?)". Seems unlikely to save much time in the long run, but there you have it.


I'm seeing a few places this will come in handy:

* toggling booleans in a config file.

* switching a string literal between 'single quotes', "double quotes #{so I can add interpolation}", and :symbols. I do this pretty often. The former is easy enough with surround.vim (cs'"), but the latter is a pain (ds'bi:<ESC>)

* the ability to add a "tap" and remove it with a single key combo is interesting for debugging.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: