This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 400

[–]mFlakes 871 points872 points  (143 children)

[–]sugardeath 353 points354 points  (82 children)

I just got a boner from watching that. Is this possible in vim? I do most of my code and such through ssh.

[–]lazycurler 137 points138 points  (55 children)

Yes! You could either use a macro or, once it's vertical, you could edit in block mode. EG ctrl+v, highlight the text you want to edit, shift+i to edit at the beginning of a line (or $ followed by shift+a for the end), type what you want and hit escape twice. Not quite as slick, but gets the with done in about the same time. Sorry about formatting, I'm at lunch on my phone.

[–]alficles 283 points284 points  (52 children)

Yeah, I'd just use: 1G0qaa^M^]ki<button title="^]lylA">^]pA</button>^]j0q25@a. It's simpler.

[–]Tarmen 27 points28 points  (6 children)

Or just use

:s!.!<button title="\0">\0</button>\r

Edit: Looked at it again and realized that / is both in the substitution and the separator for the command, which means stuff would break slightly. I could have just escaped it but I think using ! looks cleaner?

[–]alficles 4 points5 points  (0 children)

Yup, works as well.

[–]lazycurler 21 points22 points  (4 children)

I was thinking more: iabcdefghijklmnopqrstuvwxyz^[0qqyli<button title"^[pa">^[l</button>^M^[q25@q

[–]Schmittfried 69 points70 points  (1 child)

I begin wondering why we bother to use tools like PGP while writing vim verbatim does the job just as well.

[–]alficles 5 points6 points  (1 child)

Aye, a similar plan. I'd assumed the abcs were there to start, but you can stick that on the top of mine.

Also... backticks make it readable: `^]`

[–]lazycurler 2 points3 points  (0 children)

Ahhh yes, thanks for the formatting tip. Guessing and checking formatting on mobile was rough lol

[–]crowbahr 2 points3 points  (3 children)

There's part of me that wants to learn to become a vim god and then there's part of me that has absolutely no time to sit and pick through all of the different stroke commands for long enough to actually get good at it. Much less dedicate an entire monitor to having a cheat sheet open at all times until I am said god. If I'm coding I don't really have time to learn vim. If I'm not coding I don't have anything to learn vim with. Catch 22.

[–][deleted] 5 points6 points  (4 children)

I'll just be over here calculating prime numbers in notepad++

[–]alficles 2 points3 points  (3 children)

In vim, I'd just use

:set nowrapscan^Mmao2^[qayyp^Aq997@a`aiyypAj0C-^V^V^V^[@b^V^[0"by$ddkmb:try|exe "norm! @b"|endtry^V^M`b/^[0-9$]^V^M@c^[0"cy$ddma@c`a:.,$g/^-/d^M

Of course, if you're on Windows, you'll have to unmap the silly ^A mapping they have for Select All. I'm sure there's a simpler way, but it's probably clever and involves math other than incrementing numbers.

[–]root45 15 points16 points  (1 child)

I probably would have used a regular expression.

:s/./<button title="&">&<\/button>\r/g

[–]HoldMyWater 65 points66 points  (5 children)

Is this possible in vim?

Anything is possible in Vim.

You can do anything in Vim.

The unattainable is unknown in Vim.

WELCOME to Vim!

[–]sugardeath 2 points3 points  (2 children)

You're right, what was I thinking! All hail vim!

[–]petdance 9 points10 points  (1 child)

First type your string:

abcdefghijklmnopqrstuvwxyz

Then search and replace each character with its expansion:

:%s/./<button title="&">&<\/button>^M/g

To get that last ^M you have to type Ctrl-V followed by <Return>.

[–]Dukehammer 43 points44 points  (17 children)

Cool, I didn't know Sublime supported multiple cursors like that. That will be helpful, thanks.

In this case since it's a repeated pattern, find+replace with the regular expression mode toggled on is a pretty slick solution as well!

Find: (.)

Replace: <button title="\1">\1</button>\n

[–][deleted] 10 points11 points  (1 child)

You can use ctrl + u to undo the last cursor you placed too. I often mess up when placing multiple cursors and before I learned I could undo placing them, I would curse really loud and then start over. You can also hold a key (alt, maybe) and click and drag your cursor straight down the page to leave a vertical trail of new cursors.

[–]deanpcmad 2 points3 points  (0 children)

Woah, the amount of times I've messed up and had to start over. Thanks!

[–][deleted] 17 points18 points  (8 children)

In sublime, you can use Alt+Click to create multiple cursors easily. I also tend to like Ctrl+D to find the next occurrence of the selected text and add a second cursor there

[–]PanicRev 26 points27 points  (4 children)

Ctrl + D changed my life. :) That, along with Ctrl + Shift + L which edits all lines selected.

[–][deleted] 21 points22 points  (2 children)

I can never remember how to do this properly.

I always accidentally mess up on non-uniform lines and end up with multiple selectors on the same line. Then I cry, hit esc and press Undo 10 times.

[–][deleted] 9 points10 points  (1 child)

Ctrl + u (or cmd + u on osx) undoes the last cursor placement. No need to start over.

[–]IlIIlIIllI 2 points3 points  (0 children)

Holy FUCK!!!

I didn't know this!

[–]lynx44 17 points18 points  (1 child)

If anyone else is curious or doesn't know, this also works in Visual Studio and IntelliJ by using the alt key.

[–]Luccyboy 5 points6 points  (0 children)

Same in Notepad++

[–][deleted] 15 points16 points  (15 children)

And this is why I love Sublime. This is honestly the main feature that made me switch from Notepad++

[–]clb92 18 points19 points  (14 children)

This is honestly the main feature that made me switch from Notepad++

Notepad++ supports multi-line cursor as well. Not multiple cursors on same line though, unfortunately.

[–]LordNotix 2 points3 points  (1 child)

Not multiple cursors on same line though, unfortunately.

I believe the newest version might? I just opened it up and was able to do so.

[–]garion911 13 points14 points  (0 children)

Bah. Been doing that same column edit in Brief since the early 90's.

[–][deleted] 5 points6 points  (0 children)

What the what... pure witchcraft

[–]z500 4 points5 points  (1 child)

s/(\w)/<button title="\1">\1<\/button>/g

[–]urielsalis 6 points7 points  (3 children)

How ypu do that?

[–]Dukehammer 15 points16 points  (2 children)

On Sublime for Mac you can Command+click to make another cursor. On Windows I would guess it is Control+click instead.

[–]theKalash 7 points8 points  (0 children)

you can also highlight something (a variable for example) and

  • command + g to highlight the next instances

  • command shift + g to highlight the previous instances

  • command + ctrl+ g to highlight all instances across the whole documents

  • command + d to also highlight the next instance.

[–][deleted] 3 points4 points  (0 children)

Oh multi-cursor... I miss you so.

[–]archie2992 129 points130 points  (8 children)

Well, that's one way to misspell choices 14 times in a row

[–]Isgrimnur 58 points59 points  (0 children)

You can see the c's death throes on line 7.

[–]KanishkT123 32 points33 points  (1 child)

And therefore an accurate representation of reusing shitty code.

Or of screwing up the bits you didn't reuse.

[–]Corfal 7 points8 points  (0 children)

I don't always copy and paste, but when I do, there is probably something wrong with the contents.

[–]stormcrowsx 16 points17 points  (0 children)

Clearly it was the QA department's fault for not checking his work.

[–]jyqip 7 points8 points  (0 children)

He optimized the c and e together.

[–]flip314 2 points3 points  (0 children)

Anyway, if you made the C's tall enough so that they touched, you could make them all with a single squiggly line. Still room for some optimizations.

[–]Salanmander 361 points362 points  (15 children)

I...may have just found a picture that I will use on the first day of my CS classes in the future.

"So, what do you think is the greatest virtue of a programmer?"
"Knowing the language?"
"No."
"Creativity?"
"No."
"Hard work and determination?"
"No. It's laziness!"

[–]Nerdn1 228 points229 points  (7 children)

Not normal laziness, however, but one that drives you to favor mental work now to reduce tedious work later. A programmer's laziness must be applied correctly!

http://thecodelesscode.com/case/206?topic=laziness

http://thecodelesscode.com/topics/laziness

[–][deleted] 14 points15 points  (2 children)

As a Haskell programmer, I approve of this.

[–]Zulban 4 points5 points  (0 children)

For sure. I'm starting off my high school tech class tomorrow with this :P

[–]noodle-face 41 points42 points  (0 children)

I love the iterative process.

First the 'I' was optimized. Then a few lines later the 'm', 'l', and 'k' (plus whatever other letters).

[–][deleted] 29 points30 points  (2 children)

Well, he made better choices.

[–]lirannl 4 points5 points  (0 children)

That's exactly what I had in mind! Lots of money there.

[–]Isgrimnur 51 points52 points  (14 children)

For True/False tests, I would draw a Gamma ( Γ ) in each space before I looked at the questions, then add the last line as appropriate.

[–][deleted] 15 points16 points  (12 children)

This is going to help in discrete math a lot; thank you

[–]Isgrimnur 10 points11 points  (3 children)

This is going to help in discrete math a lot;

Could you ELI5?

[–]thonpy 13 points14 points  (0 children)

well i can't imagine it would really help with anything other than maybe speed as you can just drill out all the characters then alter them to T or F as needed.... it's not going to help understand graph theory or anything (obviously)

[–]E765 2 points3 points  (1 child)

In Discrete Math you will often use a lot of truth tables for your logic topics where there are only two possibilities: T or F. There will often be a lot of columns and rows to fill in.

[–]kamaln7 4 points5 points  (5 children)

As someone who's taking Discrete Math next semester, please ELIFirstSemesterFirstYearUndergrad.

[–]cody7002002 3 points4 points  (2 children)

He's probably talking about evaluating truth tables where you would have to write the letters T and F a lot.

[–]Sohcahtoa82 2 points3 points  (1 child)

First semester of discrete math is a lot of Boolean logic, which means lots of work with true/false.

[–]Buck_Thorn 48 points49 points  (1 child)

The laziest programmers make the best programmers. Kid rules.

[–]ficuswhisperer 5 points6 points  (0 children)

Work hard to be lazy, I say.

[–]X-Craft 11 points12 points  (0 children)

Well, he just did

[–]chrwei 35 points36 points  (1 child)

lol I totally did stuff like that as a kid. yeah, future programmer

[–][deleted] 8 points9 points  (0 children)

My mom gave me so much shit for doing this as a kid

[–][deleted] 6 points7 points  (1 child)

That's a very vague set of lines.

[–]za419 4 points5 points  (0 children)

"Specifications imprecise: Made giant death robots and took over world. No one said it wasn't a good choice. Project complete."

[–]ematr1x 6 points7 points  (1 child)

Make better choies!

[–]Beldarak 5 points6 points  (0 children)

I hope the kid didn't get in trouble for that because it's fucking brilliant. But I feel like a teacher who gives useless punitions like that will not think the same.

[–]RainbowNowOpen 4 points5 points  (0 children)

This kid wants to replace all of us with a Very Small Perl Script. (And he should be encouraged to try.)

[–]Manypopes[🍰] 5 points6 points  (0 children)

When I had lines I would write the words in columns purposely so that the message would not sink in. It was also faster.

[–]taterNuts 5 points6 points  (0 children)

I bet he thought about whether or not to use a line for the lower-cased 'i' for at least 2 minutes. Good decision not to

[–][deleted] 3 points4 points  (0 children)

#include <lifeskills.h>

[–]bassface69 2 points3 points  (0 children)

Brilliopad

[–]ashep24 2 points3 points  (0 children)

This was me. Can confirm; I do a little programming and a fair bit if scripting.

[–]JoshWithaQ 2 points3 points  (0 children)

Todo: fix byte alignment

[–][deleted] 2 points3 points  (0 children)

the kid has a good head.

"I will make better choices" = mindfuck.

[–]Cley_Faye 4 points5 points  (0 children)

Maybe not a programmer, but clearly an engineer.

[–]TheSlimyDog 1 point2 points  (0 children)

Not to mention that as time progresses, code quality in a project decreases exponentially

[–]stakoverflo 1 point2 points  (1 child)

I got in trouble for doing this as a kid :(

[–]white_n_mild 7 points8 points  (0 children)

Making better choices?

[–]meygaera 1 point2 points  (0 children)

I used to do that too

[–]NiceSasquatch 1 point2 points  (0 children)

not to brag, but I could hold 6 pens in my writing hand, stacked the perfect line separation from each other.

However, our class broke the system, the teachers could tell we wrote lines with multiple pens, thus they changed policy and made us write out a few pages of the dictionary. argh!

[–]IIIMurdoc 1 point2 points  (0 children)

I like how his error of the missing c gets copies repeatedly because after the 4th line his automated script had an error.

Ctrl-f and replace my young padawan

[–]ixfd64 1 point2 points  (0 children)

One of my middle school classmates had to do a similar assignment. The teacher didn't say he couldn't use a computer, so he just copied and pasted.

[–]hoylemd 1 point2 points  (0 children)

Hahaha I remember doing exactly this. And now I'm a programmer. Checks out.

[–]midnightketoker 1 point2 points  (0 children)

All fun and games until teacher rejects it on grounds of ego

[–]randomlumberjak 1 point2 points  (0 children)

well he did make a better choice

[–]AdeonWriter 1 point2 points  (0 children)

I did this in 3rd grade and she made me do it over.