Live data from Hacker News

Intermediate Vim

dn.ht

81–90 of 130 posts

Re: Intermediate Vim

#81
“If you’re like me and never learned to touch type properly, just use the arrow keys, it’s fine, don’t worry about it.”

Are touch typists rare these days? I feel like people these days forego even learning to type properly. I dont understand why they refuse to just learn it, it is such an essential skill to have.

Re: Intermediate Vim

#82

For anybody who's found more IDE-y activities a bit beyond the current generation of VIM plugins (looking at you Typescript), the Vim plugins for VsCode and Visual Studio are actually surprisingly good and I find myself at least as productive as I do in Vim. I imagine it might be quite a good starting point for somebody who's used to VsCode productivity but wanted to get into vim without going full vim!

The problem I have with those plugins is that I use a lot of split buffers not just for editing but also for exploring directories using :Explore for example. Some IDEs+vim plugins support horizontal splits but then when you have to jump between different modes such as explorer or console they use different shortcuts. Nevertheless, I think that VIM support for IDEs has improved a lot these past years. VSCode and Jet…

I've managed to get the classic vim `-w` + h|j|k|l working in VSCode. Sadly my convenient remapping of that doesn't work :(

My annoyances are pretty small: not being able to do `:e ` and then tab complete the directory structure and the fact that VSCode has splits with tabs rather than tabs with splits.

Re: Intermediate Vim

#83

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…

My favorite newish-to-me macro trick is to use "recursive macros" -- macros that call themselves at the end, eg `qa[do something]@aq`. The idea (at least for me so far) is to record a line-wise action that goes to the next line before calling itself and will fail on the first non-matching line. For example, if you need to put some text after the first `0`, using commands like `t` or `f` to get there will fail if ther…

A slight alternative to recursive macros, macros are repeatable actions, so this works: 100@a

I use it so I can run the macro in batches a couple times and check if I made any mistakes, before picking an absurdly high number to hit the whole file.

Re: Intermediate Vim

#84
I learned a new one recently. zt redraw so that current line is at top, zb redraw so that current line is at bottom, zz redraw so that current line is at the center.

If you are on twitter, you might want to follow MasteringVim. You'll learn one trick every day.

Re: Intermediate Vim

#85
post #53

Earlier quoted context omitted.

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.

Likewise - with visual mode it's normally pretty quick to select an area and do a basic regex, even for things like re-indentation (auto-completes to something like :' s/^/\t/) even though I'm sure there's a 'proper' way to do that

> for indent, < for un-indent

Re: Intermediate Vim

#86
One thing I always wished VIM had was the generalized ability to repeat the last navigation command with "," and ";". I mean if I use "[m" to go to the previous method, then I want to be able to repeat that with ",". Never understood why ",' and ";" are only for "f" and "F"

Re: Intermediate Vim

#87

“If you’re like me and never learned to touch type properly, just use the arrow keys, it’s fine, don’t worry about it.” Are touch typists rare these days? I feel like people these days forego even learning to type properly. I dont understand why they refuse to just learn it, it is such an essential skill to have.

Yeah, the cost-value benefit of learning touch typing will vastly eclipse the cost-value benefit of learning intermediate vim, that's for sure.

Re: Intermediate Vim

#88
post #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)

This does that in Vim: https://github.com/wellle/targets.vim

I use it all the time! The only reason I don't use Spacemacs is the startup time/GUI lag, but if it works for you keep at it!

Re: Intermediate Vim

#89
post #83

Earlier quoted context omitted.

My favorite newish-to-me macro trick is to use "recursive macros" -- macros that call themselves at the end, eg `qa[do something]@aq`. The idea (at least for me so far) is to record a line-wise action that goes to the next line before calling itself and will fail on the first non-matching line. For example, if you need to put some text after the first `0`, using commands like `t` or `f` to get there will fail if ther…

A slight alternative to recursive macros, macros are repeatable actions, so this works: 100@a I use it so I can run the macro in batches a couple times and check if I made any mistakes, before picking an absurdly high number to hit the whole file.

Another alternative, visually select the region you're interested in then:

:'normal @q

to apply the macro (in q) to that region. You might want to remap the above command to some shortcut if you find it useful often.

Re: Intermediate Vim

#90
post #60

Earlier quoted context omitted.

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.

For that same example, you can accomplish the job in one substitute command: :%s/.*/"&",/ The & special character gets replaced with the whole matched pattern.

How do you escape the & character? I have been bit by this (not escaping &) a few times but never enough to have found the answer.
Post reply on HN