Hacker News new | ask | show | jobs
by whartung 35 days ago
I can't think of any, but I can share some examples.

When shredding things like log files, or raw data file, being able to do things like:

  :g/bad line/d
To delete all of the "bad lines". When manually paring down some files, you can use `ma` to do "Mark A" (vs `mb`, which is Mark B). So, I can be scrolling through the file, do the mark when I get to the top of a garbage section, and page or scroll or search to the next "keep" section, and then do `d'a` which means "delete to A", and so it removes all of the stuff I've skipped through.

Doing simple things like:

   !Gformat (! to shell out, G for "the entire buffer", format is the program)
Which runs the entire buffer through the `format` command to wrap paragraphs. I don't necessarily need that feature in my editor, I have a utility that I can use instead.

Of course, you can use `!'a` to a mark. or `!/thing` to run current line to the next "thing" (use `?` for previous).

Banging to utilities is a nice way to develop a pipeline, you basically get to see stuff step by step. So instead of:

    grep thing file | cut -f 1 | sort 
You can vi the file, `!Ggrep thing`, "Yup!", `!G cut -f 1`, "Ok!", `!G sort` and easily see the intermediate steps. (Not recommended on enormous files, since the entire region is replaced.)

The `.` is great for `/word` to find a "word", `cwnew-word`, and apply it selectively. `n` to "search next", and it you like it, `.` to do the `cw` again. Otherwise, keep using `n` until you find the one you like.

And I have no problem running a chunk through a bang command to see what's what, only to just `u`ndo it. (With modern `vim`, you can undo that all the way back to the start if you're doing that pipeline thing.)

And, I would routinely do something like:

  ma$%:'aw/tmp/x.x!vi other.txt then /wherever, :r /tmp/x.x
Mark A, `$` to EOL, `%` to closing brace (imagine a C function header), write from mark A to current line to /tmp/x.x, `!` to shell out to a new `vi` session, then read in the snippet.

Old school, single session, copy and paste. My /tmp is scattered with x.x, x.y, x.1, etc. files.

Along with regex replaces, this is 95% of how I use `vi`. I'm sure there's a bunch of other features, especially in `vim`, but these few bits are flexible and powerful enough to cover my needs. Since I haven't really been found "wanting", I'm not really "looking".

And it started because `vi` was a singular common denominator across all of the disparate UNIX minis I used to work on, so I just managed to work with what was available wherever I went.

1 comments

I'm roughly at the same level. The main improvement of vim over vi is the infinite undo, and more recently the UTF-8 support. I like the more elaborate status line and the syntax colouring, and I actually have cpoptions set to "downgrade" a few (but not all) features to how they were in vi ( notably vx$ so text you're changing remains visible while you're typing over it, and Esc actually executes the command line).