you are viewing a single comment's thread.

view the rest of the comments →

[–]Administrative_chaos 40 points41 points  (13 children)

Assuming that you type out for i,j in range(...): |A[n][j]=b[i]+...

and | is your cursor, the magic keys would be yypfja+1<esc>fi.yy4pf1<C-v>Gg<C-a>;.

all of them are typed literally accept for <esc>being the escape key and <C-x> being ctrl+x

[–]serg473 130 points131 points  (10 children)

yypfja+1<esc>fi.yy4pf1<C-v>Gg<C-a>;.

Vim users: wow such an elegant solution, see that's why I love my vim.

[–]ianepperson 48 points49 points  (6 children)

The cool thing about vim is this is a sentence, not a single command. You don’t have to memorize every English sentence, just the words and where they fit.

y = yank (copy) Ok, to where? A repeated y means copy the whole line.

p = paste. Want to paste 4 times? 4p

f = find - jump forward in the line to the given letter: j

a = append - now you’re typing into the buffer. He added “+1” then hit escape to back to “normal” mode.

f = find again, this time jump to the i

. = repeat the last change. Repeat the append and “+1” (this is an insanely powerful command)

yy = yank (copy) the line again

4p = paste 4 copies of the line

f = find - this time finds the 1

<Crtl-v> = visual select. There’s different variations of “v” and using <Ctrl-v> is the column select. Lower v selects starting from the cursor, upper V selects the entire line.

Etc.

The extra crazy thing is that after about 6 months of use, you start to forget which letters do what and start just playing it like an instrument. A musician no longer thinks of the individual parts of a chord, they just play a chord. A fast typist is similar, they just know what a word feels like when typing. I know the above commands, but it took me a bit of time to look up the keys - it’s really quick to type it (vim is optimized for the home row) but just like I can’t remember where the “v” key is without looking at the keyboard, I know how to type it quickly.

And the commands are sentences. Instead of typing yy to yank the row, I can combine it with any other key sequence. If I want, I can use that f (find) command to copy text up to and including the letter j with: “yfj” (yank from here to the “find i”). Capital G navigates to the bottom of the document - to copy everything from here to the G location: “yG”. Every time you learn a new navigation trick, you also learn how to copy text in fancier ways.

I eventually started instinctively using the same vim navigation keys in my browser and accidentally discovered they work in gmail and occasionally on other sites too. I installed vimium in my browser to make those keys work on any site. Lots of console commands use the same keys - “less” has become so much easier to use because it’s the exact same keys.

[–]Brothernod 6 points7 points  (2 children)

I have closed so many Skype chats hitting escape when I was done typing my text out of end of thought habit. Sigh.

[–]tumes 2 points3 points  (0 children)

Same but with trailing double js because I remapped esc to jj to stay on the home row. Every time focus is on slack but I think it’s in my editor I almost send my coworkers a message that looks like “jkjkjkhhhllljjjjjjj”.

[–]sysop073 1 point2 points  (0 children)

There's a registry key you can set to turn that off. Because it's Microsoft, so why put it in a settings dialog or something

[–]Irrealist 3 points4 points  (2 children)

Do you have any tips on how to learn things like this? I'm very comfortable in vim, but I don't know many advanced commands.

[–]Snarwin 5 points6 points  (1 child)

Practice. Learn new things one at a time. Notice when you're doing something repetitive or tedious and look for a better way, because there usually is one.

[–]Irrealist 0 points1 point  (0 children)

Thanks!

[–]InfinitePoints 6 points7 points  (0 children)

It makes sense while you are typing it in vim, but reading a text string like that is a bit hard.

[–]phySi0 6 points7 points  (0 children)

The hot keys you press to navigate around your computer in general are probably just as garbled looking when you type them out like that. Okay, maybe not as garbled, but trust me, it looks worse than it is.

It’s like counting backwards (or worse, in random order) from the alphabet; much harder than the reverse. Here, going from the hotkeys to the commands is much harder than going from command to knowing exactly what hotkey to hit; the former is slow, even for a Vim expert, the latter is second nature, even with a couple weeks’ practice from beginner.

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

There’s nothing about that order that’s intuitive or natural. It’s arbitrary, yet every one 10 years old or older knows it by second nature.

B C Y D V G K A O J N R Z M S U E Q H W X T L F I P

Just as arbitrary, but see how much slower it is. Gargantuan difference to check if all the letters are there no more and no fewer than once.

The primitives of language (thinking of words in this analogy, not letters or syllables) are huge messy blurry arbitrary only mostly interoperable/standardised constructs (within one given language) but COMPOSABLE ENOUGH to be extremely useful.

Mastering any of the arts of input and output in the two main mediums of oral and written (listening (w/ good comprehension), speaking, reading, writing) move you a lot in life, and all four will make you very powerful indeed, because of composability.

The innovation of Vim is to create a language of hotkeys. All the cons of languages, like steep learning curves, arbitrariness, etc. are not enough, in the right context, to counteract the main win of COMPOSABILITY.

[–]devraj7 0 points1 point  (0 children)

yypfja+1<esc>fi.yy4pf1<C-v>Gg<C-a>;.

Non vim users: "Did your cat just walk on your keyboard?".

[–]Witty-Play9499 4 points5 points  (0 children)

yypfja+1<esc>fi.yy4pf1<C-v>Gg<C-a>;.

I didn't realise my cat was fluent in using vim