Live data from Hacker News

Intermediate Vim

dn.ht

71–80 of 130 posts

Re: Intermediate Vim

#71

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…

For that example I would open the document in Sublime Text, select all, and split selection into lines so that I have an independent caret on every line. Then I'd just type the quote at the beginning and end of each line - the home/end keys will put each caret at the beginning or end of its respective line.

Re: Intermediate Vim

#72

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 there is no `0`, but `/` will go to the next `0` on any line.

A macro like this will just keep calling itself until it fails, which is nice for files with thousands of lines and you want to make a change that is not conducive to a regex.

As a tip that took me a while to figure out, you can search within a visual selection using `\%V`, which may make it easier to reliably go to a specific part of the current line (compared to t or f like I mention above).

Also wanted to point out that iVim for iOS is pretty good, for those rare cases you want to do some text processing on the move that makes you miss Vim: https://itunes.apple.com/us/app/ivim/id1266544660?mt=8

A decent post on recursive macros: https://jovicailic.org/2018/06/recursive-macros-in-vim/

Re: Intermediate Vim

#74
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!

Re: Intermediate Vim

#75

Disappointingly elementary. Even I, an Emacs user who occasionally uses vi am familiar the material in this. Can anybody suggest any real intermediate vi material?

Beginner vim is being able to exit vim successfully, knowing how to hit i to insert text, and how to save your file. Just because you are familiar with it doesn't mean it isn't intermediate, it just means you are already intermediate.

Re: Intermediate Vim

#77

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…

Another simpler way (even simpler than macros) that works great for simple mass editing is visual blocks. In normal mode, press Ctrl + V and you get to select a literal block of text (not like visual mode, where the text is sequential). Then you can for example, do a "c" to change the selected text in each of the rows that your block covers. This is especially practical to remove a column. Just select the column, press d and voilà.

Re: Intermediate Vim

#78

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!

Just a warning for VSCode users, this issue still exists: https://github.com/VSCodeVim/Vim/issues/2007

Re: Intermediate Vim

#79

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…

For that example I would open the document in Sublime Text, select all, and split selection into lines so that I have an independent caret on every line. Then I'd just type the quote at the beginning and end of each line - the home/end keys will put each caret at the beginning or end of its respective line.

I've been using vim a lot recently. Multiple cursors for this exact scenario is the only thing I still miss about other editors.

Macros and other solutions are great, but for this very simple and surprisingly common task, multiple cursors are perfect.

Re: Intermediate Vim

#80

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 brains have done an awesome work integrating it to their software.

Post reply on HN