r/ProgrammerHumor • • Apr 20 '15

vim

Post image
1.3k Upvotes

427 comments sorted by

View all comments

102

u/[deleted] Apr 20 '15

And many more hours trying to figure out how to use it in the first place. (For context, written by an occasional vim user).

38

u/ngildea Apr 20 '15

Maybe if you used if more than occasionally you wouldn't be so confused! :P

45

u/Neekoy Apr 20 '15 edited Sep 08 '26

Marvelous coordinated pause smile cough blanket

This post was anonymized with Redact

21

u/gellis12 Apr 20 '15

You forgot :w to save, and :wq to save and close the file.

5

u/[deleted] Apr 20 '15

And :x

7

u/in_n0x Apr 20 '15

Team :x, reporting.

→ More replies (5)

6

u/Neekoy Apr 20 '15 edited Sep 08 '26

Public unite important vase tie almond

This post was anonymized with Redact

10

u/gellis12 Apr 20 '15

I had never heard of ZZ before today, but I'll probably be using it from now on! Thanks!

7

u/abchiptop Apr 20 '15

:x save and quit

→ More replies (9)
→ More replies (1)

7

u/Tarmen Apr 20 '15

To be fair, you are missing a lot when ignoring text objects. Stuff like cib to delete what was in the next pair of brackets, go into insert mode and lets you type a replacement. Afterwards you can type . to repeat.

Not really necessary to use it but super helpful.

→ More replies (1)

0

u/[deleted] Apr 20 '15

[deleted]

7

u/Bosun_Tom Apr 21 '15

Put this in your .vimrc: set clipboard=unnamedplus

4

u/paraffin Apr 20 '15

i for insert mode, ctrl+shift+v or shift+insert to paste

3

u/the_omega99 Apr 21 '15

Note that you probably have to set paste mode, otherwise vim will likely try to format your pasted text and possible screw it up. You could do this with :set paste and :set nopaste, but more ideally you should make a shortcut for this. I use this in my .vimrc:

map <leader>pp :setlocal paste!<cr>

This lets you type <leader>pp to toggle paste mode. IIRC, <leader> is backslash by default, but that's a pain in the ass to type, so most people change it to , (comma) with:

let mapleader = ","
let g:mapleader = ","

Thus, ,pp will toggle paste mode.

4

u/[deleted] Apr 21 '15

Well, if you know how to do yank (y) and put (p), system clipboard is "+y and "+p which is fairly easy to remember I think.

→ More replies (3)

5

u/MoragX Apr 20 '15

It's not so much that Vi is so hard, but rather that with a modern text editor, most of the shortcuts are standard to the rest of the computing world and so you don't have to memorize anything. So Vi isn't hard, but everything else is so easy.

→ More replies (1)

3

u/pehnn_altura Apr 21 '15

:%s/foo/bar/g

Find and replace all instances of foo with bar. Great shortcut if you need to rename a variable!

0

u/[deleted] Apr 21 '15

[deleted]

→ More replies (5)

2

u/minno Apr 21 '15

I prefer :%s/foo/bar/gc so that I don't accidentally change a part of the file I didn't mean to.

→ More replies (1)

2

u/VictoryGin1984 Apr 21 '15

Or better yet, :%s/\<foo\>/bar/g, so you only match the whole word "foo".

2

u/Endur Apr 21 '15

Took me a while to remember that syntax. I still need to look it up to remember what letter does confirmation and all that other stuff

→ More replies (1)

3

u/kpthunder Apr 21 '15

cw for change word. It's useful for interactive rebasing in Git.

3

u/the_omega99 Apr 21 '15

Two other useful things that vim users should know (because while the stuff you listed are the essentials, they don't really do anything that you can't do in virtually every editor):

  • Macros: hit q<letter> to start recording and save the macro into <letter> (this lets you record multiple macros). Do whatever actions you want, then hit q to stop recording. Now whenever you type @<letter>, you'll perform the recorded actions. If you specify a number before @<letter>, you'll perform the macro that many times.

    Incredibly useful for avoiding repetitive commands. Macros can easily be the #1 time saver, since repetitive commands are a strong thing to stamp out.

  • ci<symbol> to change within some kind of enclosing symbol ({, [, ", etc). For example, if our text is:

      <someXml attribute="value" />

    Then inside of the double quotes, we could type ci" and it'll change the text to

      <someXml attribute="" />

    And put the cursor in insert mode after the starting double quote. Similarly, typing ci< will change the text to

      <>

    And put the cursor after the starting angle bracket.

2

u/Endur Apr 21 '15

Got anymore useful and more advanced commands?

I use a vim plugin for my IDE and use all the above commands above, it's great!

The one command I probably use the most is D. It cuts everything from the cursor to the end of the line. I can't remember if it puts you in insert mode, but you can always follow up with an A to put you in insert mode at the end of the line.

→ More replies (1)

2

u/Nowin Apr 21 '15

My god none of those are intuitive at all.

→ More replies (4)