Live data from Hacker News

Intermediate Vim

dn.ht

11–20 of 130 posts

Re: Intermediate Vim

#11
post #6

Hey all, I'm the author. Feedback is welcome! :) The reason I wrote this is because I've been pair programming quite a bit lately and also mentoring some new vim users—so I wrote this little guide to help vim beginners level up their skills a bit. What I noticed is that a lot of vim beginners find composing commands and text-objects to be kind of mind blowing.. and even more experienced vim users mentioned that these…

I think the concerns others have mentioned about the title/content level are valid, but even though I knew most of the commands I enjoyed reading this! I quite liked your writing style and page design.

Re: Intermediate Vim

#13
post #6

Hey all, I'm the author. Feedback is welcome! :) The reason I wrote this is because I've been pair programming quite a bit lately and also mentoring some new vim users—so I wrote this little guide to help vim beginners level up their skills a bit. What I noticed is that a lot of vim beginners find composing commands and text-objects to be kind of mind blowing.. and even more experienced vim users mentioned that these…

> I've been pair programming quite a bit lately

Does it mean both party have to use the same editor? I wouldn't participate in a pair programmnig like that.

Pair programming is best when everyone can use one's favorite editor. When there is a pair switch there is also an editor switch if the other party prefers a different editor.

Re: Intermediate Vim

#15
I feel composing commands is where the real power of Vi(m) comes from. This can be really helpful to someone just starting out with Vim.

I got a boost in my Vim productivity after reading a similar StackOverflow answer a couple of years ago. It's a nice read for people familiar with Vim, and another good resource for new users.

"Your problem with Vim is that you don't grok vi." https://stackoverflow.com/a/1220118

Re: Intermediate Vim

#16
Maybe you can cover macros since they are conceptually very simple and very powerful.

They may seem a bit complex but are quite simple. Basically you just record your editing movements and play it back.

How macros work: press q x to record and q to end. Then repeat with @ x, where x is the name of the macro you want to use (you can have several macros). Anything you do will be played back. That's it... Conceptually simple.

A nice trick is to record a macro for a single line and place the cursor on the start of the next line at the end of the recording. This way it's possible to operate upon large blocks of text in a similar way by just repeating the macro. The key then is to use generic movements like "go to the beginning of line" (^), "go to the end of line" ($), "skip word" (w), etc.

As a silly toy example, if you have a list of strings in a text file, you can turn it into a list of quotes with (from the top of my head):

  qxi"$i",q
(Record macro, go to beginning of line, insert mode, write a quote, exit insert mode, go to end of line, insert mode, move right, write a quote and a comma, move down to next line, move to the beginning of line, exit insert mode, end macro recording)

Then to process 100 lines, you'd do:

100@x

That turns these:

  alpha
  bravo
  charlie
  delta
  ...
into

  "alpha",
  "bravo",
  "charlie",
  "delta",
  ...
If you have hundreds of lines of that you'll start to appreciate the easy automation.

I use macros to do drive-by mass-edits without resorting to sed, scripting, regular expressions etc. since the cognitive load of those is higher for me.

Edit: formatting

Re: Intermediate Vim

#17
One thing I miss on Vim I have on Spacemacs with the Evil layer is the "a" object (for "argument"). With it I can delete/change an argument of a function in a flash.

Example (cursor on the last arg):

  importAntigravity(usePython, crashTheUniverse)
  
  importAntigravity(usePython)

Re: Intermediate Vim

#18
post #3

As a Vim user one of my gripes when first using Vim was how cumbersome the built in help files were. I guess that's why there are so many "vim cheatsheets" out there, the built in documentation is a pain to use.

The biggest pain in vim is the escape key. And no, ctrl+[ isn't any better.

Re: Intermediate Vim

#20

Maybe you can cover macros since they are conceptually very simple and very powerful. They may seem a bit complex but are quite simple. Basically you just record your editing movements and play it back. How macros work: press q x to record and q to end. Then repeat with @ x, where x is the name of the macro you want to use (you can have several macros). Anything you do will be played back. That's it... Conceptually s…

I've used vim for a couple of decades, but never pushed to many advanced features. For your example above I'd do :%s/^/"/ and :%s/$/",/

Unless I use a feature regularly I find it's a higher cognative load. I use bash, sed and perl regexps on a near daily basis. Macros are very rare.

Post reply on HN