r/programming • • May 23 '17

Stack Overflow: Helping One Million Developers Exit Vim

https://stackoverflow.blog/2017/05/23/stack-overflow-helping-one-million-developers-exit-vim/
9.2k Upvotes

1.1k comments sorted by

View all comments

2

u/michaelpaoli May 24 '17

vim annoys me ... lots. Typical examples:

:q
E37: No write since last change (add ! to override)
:q!
E37: No write since last change (add ! to override)
E162: No write since last change for buffer "[No Name]"
:q!!
E488: Trailing characters

Lots more examples:
vim annoyances
nvi(1) rocks! :-) nvi(1) is also vi(1) on BSD systems.

1

u/bart2019 May 24 '17

Annoyances? How about this one.

When you press "a" to append on the current line, it doesn't move the cursor at the end of the line. Instead, it moves it to the position of the last character, for example, on the last letter.

W...T...F...

2

u/michaelpaoli May 24 '17

Nothin' unexpected there, standard vi/nvi behavior,
a to append after the current cursor position
A to append at the end of the line

In general with vi/nvi standard behavior, uppercase does/impacts something bigger or more general than the otherwise similar lowercase,
e.g. b vs. B, e vs. E, h vs. H, l vs. L, r vs. R, s vs. S, u vs. U, w vs. W, etc. But that's just in general. There are also highly useful (often slight) exceptions/variations, e.g.: f vs. F vs. ^F (forward vs. backwards vs. screenful), i vs. I (before vs. before first non-whitespace on line (or beginning of line if no non-whitespace on line)), n vs. N (forward vs. backwards), o vs. O (below vs. above), p vs. P (after vs. before), t vs. T (forward vs. backwards), x vs. X (current vs. to left).

"slide" set I've used many times for vi training presentations:
vi - basic introduction through advanced tips and "tricks" (works best along with the verbal presentation and fair number of quick demonstrations along the way, and some other handout materials - including ye olde vi (not vim!) quick reference card (best printed as double sided 11" x 8.5" tri-fold), and tutorial introduction:
Ex/Vi Quick Reference
An Introduction to Display Editing with Vi

1

u/superbad May 24 '17

Try "A" to append to the end of the line.

1

u/CaptainDickbag May 24 '17

Shift-$ to go to the end of a line. Shift-^ to go to the beginning. i for insert, a for append, o to insert a newline and edit.

1

u/MrHartreeFock May 24 '17

It's $ and ^, not shift+ those (that would be impossible on qwerty since it's required anyway, actually that is probably what gave you the wrong idea). If you want to see what I mean, change your layout to something that allows you to press ^ and $ without shift (eg azerty), you won't need shift at all then.

And they aren't opposites, 0 is the opposite of $, which brings you to the start or end of the line, ^ (or _) brings you to the first non-blank character of a line. g_ is the counterpart to ^

1

u/CaptainDickbag May 24 '17

Good points, thanks for the corrections.

1

u/DuBistKomisch May 24 '17

huh? :q! forces a quit in vim for me, even with an unsaved file

dark blue being unreadable is your terminal emulator's fault

don't really understand what case vim would only shows the tail of the path, I've never seen it, is it just a really long path?

afaik :se compatible is the default if invoked as vi, complaining about having to configure stuff is retarded

wouldn't have to worry about swap files so much if you weren't killing vim processes all the time...

1

u/michaelpaoli May 24 '17

Yes, :q! should always work to quit, but in vim(1), sometimes it does not!!!
(another work-around I've found when it gives that behavior is set the file to /dev/null, write it out, and then quit, e.g.:

:f /dev/null
:w!
:q!

That seems to (mostly?) work when :q! fails in vim )

And tail of the path, yes, vim(1) screws with that and doesn't give the full literal, notably also including in % and # substitutions - this can be highly annoying, e.g.:

 $ cd /some_deep_path && vi /some_deep_path/[ab]

We'll say we have files a and b in that directory. Let's say we jump between the files a bit with :n, :rew, etc. Now, within vim, use cd to change to some other directory. With nvi and true vi, % and # reference /some_deep_path/a and /some_deep_path/b, whereas with vim they'll be a and b - this violates principle of least surprise and can cause serious problems, e.g. execute a command in vi using % and #, should reference /some_deep_path/a and /some_deep_path/b, not a and b - remember we changed directories within the editor. If I wanted % and # to be a and b and not their full paths, I would have used a and b as arguments upon invocation, but I explicitly and intentionally didn't - and generally for darn good reason. E.g. I may be editing a bunch of index.* files in various directories - and editor not referencing what I told it to can create all kinds or problems. Anyway, just one of many many many issues/problems with vim.

Nothing "retarded" about complaining about configuring stuff, an no, invoking vim as vi isn't sufficient - at least in many cases, to get it into it's (so-called) "compatible" mode.

Uhm, dark blue on black being unreadable isn't terminal editor's fault - that's a horrible combination for readability. If I wanted comments to be damn near invisible I wouldn't have written them, or I'd strip the things out. Anyway, vim sucks lots ... quite annoying. Thus far I've only found one thing that vim got right that nvi didn't get exactly right (and that is also correct in classic vi).

Note also that some of vim's behavior is inconsistent - not all of these bugs/issues show up all of the time, but most of them show up quite frequently enough to be quite annoying/problematic.

Anyway, a whole lot of what vim does and its default, options, behavior, etc. - highly sub-optimal, and significantly not compatible with vi!