Skip to content

Instantly share code, notes, and snippets.

@duff
Created October 7, 2010 19:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duff/615695 to your computer and use it in GitHub Desktop.
Save duff/615695 to your computer and use it in GitHub Desktop.
In your editor of choice,
Convert the following line:
context "when the transaction is successful", :focused => true do
To:
context "when the transaction is successful" do
Assume the cursor is on the comma.
@duff
Copy link
Author

duff commented Oct 7, 2010

One way in Vim:

d/ d

(that's d slash space d enter)

@austintaylor
Copy link

Shorter: d3E, but you have to count the WORDs.

(It's also d4e, but counting words is harder than WORDS because you have to remember what characters are considered word breaks.)

I wonder if I could create a text object for this. daa = delete an argument. It seems like there would be quite a few uses for that.

@austintaylor
Copy link

Hmm. "da," might be more intuitive to me.

@duff
Copy link
Author

duff commented Oct 7, 2010

I like the d3E. Hadn't thought of that! I'll play with it and see. One advantage of using the / is that it highlights it so you know right where it's gonna delete up to. Even so, it's a case I run into a bunch so having d3E could be a winner. I haven't created a text object - this sounds like it could be pretty interesting.

@lojic
Copy link

lojic commented Oct 7, 2010

Shortest in Emacs is probably: M-2 M-d which is 3 keypresses since you hold down the meta key and then type 2 d

Others:
M-4 M-z space
C-k space do

@jjthrash
Copy link

jjthrash commented Oct 7, 2010

I'd probably do:
f,dtd

@jjthrash
Copy link

jjthrash commented Oct 7, 2010

Well, assuming the cursor wasn't on the comma. Just wrote what sprang to mind.

@duff
Copy link
Author

duff commented Oct 7, 2010

Austin - I (like many people) use , as . I don't think that would confuse it, would it?

lojic - I dig it. Thanks!

@duff
Copy link
Author

duff commented Oct 7, 2010

jjthrash - dtd would delete up to the first d, right?

@austintaylor
Copy link

Shadowing is only a problem for prefixes. Since text objects are always prefixed with an action, they essentially have their own key space.

@duff
Copy link
Author

duff commented Oct 7, 2010

austin - excellent. I wonder if a plugin would be a good way to distribute it. Also wonder if your cool indent text object could be in a plugin to pull it out of my .vimrc.

@jjthrash
Copy link

jjthrash commented Oct 7, 2010

D'oh. That's why I often use visual mode so I don't have to think. Counting words doesn't work.

I might also do:
dtd.
after I noticed I didn't actually delete to the d that I wanted. :) I love the period operator.

@duff
Copy link
Author

duff commented Oct 7, 2010

Jimmy - Yup. I use visual mode a bunch as well. I learned the / trick when deleting something on the same line from @spicycode. It's nice because it acts a bit like visual mode and works even if there's more than one of the thing you're looking for (since you can keep typing what you're looking at and it'll eventually be highlighted).

I haven't done much counting of things either, but I'm going to experiment with the WORD counting a bit since I haven't tried it. I'm wondering if my brain'll just know how many WORDS there are (when there's only a few).

@austintaylor
Copy link

My first pass at the text object: http://github.com/austintaylor/vim-commaobject

It handles the case you show (da, will work anywhere between the comma, and the end), but it's still pretty easy to confuse it with nested lists. There's a list of caveats in the readme.

@austintaylor
Copy link

@duff
Copy link
Author

duff commented Oct 7, 2010

NICE. Your indent object plugin helped me delete a ton of stuff. I love it.

http://github.com/duff/dot_vim_directory/commit/2cb175deaa1f6a6a10e0dad26292a0b6d4e59424

@duff
Copy link
Author

duff commented Oct 7, 2010

Austin - OK. The commaobject is outstanding. I just sent you a pull request.

@dotemacs
Copy link

dotemacs commented Oct 8, 2010

@lojic even simpler:

M-d M-d

Thats 3 key presses too, meta held down

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment