r/programming • • Sep 24 '15

Vim Creep

http://www.norfolkwinters.com/vim-creep/
1.2k Upvotes

844 comments sorted by

View all comments

Show parent comments

147

u/jollybobbyroger Sep 24 '15

A big difference between Vim and your 813 hotkeys is that Vim has a structure to the key bindings. Where you have to memorize individual hotkeys for each command in VS, Vim commands are simple languages. So when you learn a new action or scope, you can combine that with everything else you already know.

E.g. I know how to indent the entire file. Cool. Then I learn about the block scope, so I immediately know how to indent the block. Then I learn how to format text to be confined within the set text width. Now I immediately know how to format the entire file and a text block. Then I learn about the "from cursor to character X" scope and now I can perform all known actions on this scope as well.

Note that the scopes are not like selections. They are controlled by keyboard input, even though in Vim, selections are just another action as well and now that I know the key for that, I know how to select any of the scopes I already know.

For VS and other IDE's and editors, each permutation of these scopes and actions would require its own hotkey, or it can only work with a selection and for that you have to spam ctrl+arrow/pg{up,down}/{home,end}, which to a Vim user are clunky and imprecise.

This is of course just scratching the surface of all the power of Vim that are accessible through a few key presses..

60

u/Darkmoth Sep 24 '15

A big difference between Vim and your 813 hotkeys is that Vim has a structure to the key bindings

No, I agree. That was my first thought when looking at them all. It'll take quite a while to memorize the ones I need (which isn't really all 813). To be fair, that also makes it funnier.

5

u/temp3298463 Sep 25 '15 edited Sep 25 '15

For VS and other IDE's and editors, each permutation of these scopes and actions would require its own hotkey, or it can only work with a selection and for that you have to spam ctrl+arrow/pg{up,down}/{home,end}

I don't know what other editors you're using, but mine lets me select a block, the entire file, or every occurance of a word with a single keystroke.

8

u/jollybobbyroger Sep 25 '15

What about "from the cursor to the {first,last} occurrence of character X", or within/around/surrounding the pair of quotes, parenthesis, html tag, brackets, sentence, function argument, block, paragraph .. ?

3

u/dpash Sep 25 '15

"Here to where I was before"

1

u/jollybobbyroger Sep 25 '15

`` should have you covered.

→ More replies (1)

3

u/temp3298463 Sep 25 '15

within/around the surrounding pair of parens, HTML tag, brackets, function arg (mostly), block (indentation-delineated or brackets-delineated), and paragraph are all a single keystroke.

To the first/last occurance of X it doesn't do, and is the one thing from VIM that I've seriously missed.

Then again, it does have VIM mode, so I could just set it to behave exactly like VIM.

1

u/jollybobbyroger Sep 25 '15

within/around the surrounding pair of parens

Do you have the ability to change the exact pairs of HTML tags, brackets, quotes, etc? Not the text within or including these paired objects, but the actual objects themselves? Change single quotes to double quotes, surround text with curly braces? These are the ones I cannot live without.. and I've just come out of a three hour long session in ipython notebook. I missed these so badly..

→ More replies (1)

2

u/Ran4 Sep 25 '15

That's the vim way of doing this though. It's really hard to compare things.

For example, going to the end of the line is super important for most editors, but in vim it's the overly clunky $. Why is it like this? Because going to the end of the line in vim just isn't very important, there's so many other ways of doing things. E.g. o to get a new line below the current one, or yy to copy the entire line.

2

u/argv_minus_one Sep 25 '15 edited Sep 25 '15

from the cursor to the {first,last} occurrence of character X

Why would you want to?

within/around/surrounding the pair of quotes, parenthesis, html tag, brackets, sentence, function argument, block, paragraph .. ?

In IDEA, press Ctrl-W (“Extend Selection”) to do that.

6

u/kqr Sep 25 '15

Why would you want to?

If you have

post_to_reddit(ur"/r/programming", "test post please ignore")
               ^

where ^ is your cursor, then pressing vt, gets you to a state where

post_to_reddit(ur"/r/programming", "test post please ignore")
               ^^^^^^^^^^^^^^^^^^

That's convenient.

In IDEA, press Ctrl-W (“Extend Selection”) to do that.

That's one thing, but it's kinda weak in comparison.

<a href="/r/programming">A Subreddit</a>
   ^

press va" and you get

<a href="/r/programming">A Subreddit</a>
        ^^^^^^^^^^^^^^^^

press vit and you get

<a href="/r/programming">A Subreddit</a>
                         ^^^^^^^^^^^

It's much more powerful than just extending the selection.

Though I have to say you rarely select text in Vim, you combine the selecting motion with the operation you want to perform on it.

1

u/argv_minus_one Sep 25 '15 edited Sep 25 '15

Ctrl+→ is used to move the cursor across words. So, move it to the appropriate place with that, then Ctrl+W the appropriate number of times.

Alternatively, press Ctrl+W enough times to select the entire start-tag, then press → to move the cursor into the text after it, then press Ctrl+W again to select the text.

2

u/kqr Sep 25 '15

If you can reach Ctrl+→ without moving your hands from the home row position, I'm impressed.

It also starts becoming more a game of navigation and less a game of somewhat semantic text editing. "I want to change what's inside those quotes" is a far more natural thought to me than "I want to press Ctrl+→ three times, then Ctrl+W two times."

2

u/argv_minus_one Sep 25 '15

If you can reach Ctrl+→ without moving your hands from the home row position, I'm impressed.

The only reason you can is that your arrow keys are artificially mapped onto the HJKL keys, because of the ancient terminal vi was originally made for, and then only when in the proper mode. Arrow keys, by contrast, have exactly one function that is always available.

Anyway, I have functioning arms with a functioning musculature. Moving my hands from the home row position is not a constraint.

"I want to change what's inside those quotes" is a far more natural thought to me than "I want to press Ctrl+→ three times, then Ctrl+W two times."

Apples and oranges. Controlling vi also involves mapping abstract actions (“change what's inside those quotes”) into concrete commands (va").

→ More replies (1)
→ More replies (2)

4

u/guepier Sep 25 '15

Why would you want to?

I do that at least (!) once a day. Even more commonly I use a special case of that to select/copy/delete/replace the contents of something that’s in quotes/parentheses/braces/brackets. At least several times a day.

→ More replies (2)

3

u/temp3298463 Sep 25 '15

Why would you want to?

This is actually the one thing I really miss from VIM. I frequently want to use it when I'm editing repetitive text that obeys (or obeys in the cases I'm dealing with) character-delimited rules. For examle, 10 rows of "string 1", "string 2", "string 3", and I want to replace the second string on each row. It makes it easy if you can hop over to the next double quote, or the next double quote not preceded by a backslash.

1

u/jollybobbyroger Sep 25 '15

I use this movement all the time, when I rename parts of a symbol and ctrl-W sounds like spamming to me.

4

u/dpash Sep 25 '15 edited Sep 25 '15

Like when you learn about markers and then you're like "cool, I can reformat all the paragraphs from here to that marker I made earlier".

I can never remember how to make markers, which means I normally only ever use `` because I don't have an `a set. I should really look that up.

I do use Vim's block selection all the time. That's really handy.

6

u/blargtastic Sep 25 '15

Marks are insanely useful. How many times have you ever wanted to do something in one function that involves checking something from another? (Hint: all the time). Just do ma to set a as a mark right here and then go off and check the other function. Then do `a to return. The advantage is that in large files you often forget exactly where the original spot was when hunting down what you need to know, which wastes time.

8

u/Rusky Sep 25 '15 edited Sep 25 '15

Another awesome way to go back to where you were is ^o and ^i, which go backward and forward in jump history.

2

u/Amadan Sep 25 '15

Another awesome way to go back to where you were is :earlier 40m. :D (Note to self: commit more often... :P)

1

u/note-to-self-bot Sep 26 '15

A friendly reminder:

commit more often...

→ More replies (2)
→ More replies (1)

9

u/[deleted] Sep 25 '15

I don't use Vim itself (UI bugs me so I use Sublime Text with Vintageous) but I've always considered Vim's keybindings to be akin to a language.

4

u/tolos Sep 25 '15

"Your problem with Vim is that you don't grok vi."

akin to a language

I think most people would agree.

→ More replies (11)