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…
Intermediate Vim
11–20 of 130 posts
Re: Intermediate Vim
#12Shift+k on a word to enter the corresponding man-page if such one exists :)
Re: Intermediate Vim
#13Hey 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…
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
#14Re: Intermediate Vim
#15I 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
#16They 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
#17Example (cursor on the last arg):
importAntigravity(usePython, crashTheUniverse)
importAntigravity(usePython)Re: Intermediate Vim
#18As 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.
Re: Intermediate Vim
#19Adding one to the great article: Shift+k on a word to enter the corresponding man-page if such one exists :)
Re: Intermediate Vim
#20Maybe 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…
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.