is "vi" worth learning in 2022?

I used to edit thousands of lines of assembler code with a line editor in the 8-bit era.
The downside of line editors is the amount of key typing.
ex(1) is easier to use than ed(1) because you can use :set nu.
I think ed(1) would be useful for here-document.
 
if you're serious about learning UNIX
Absolutely. As the "SECOND STEP TO BECOME EXPERTS/WIZARDS". But does not fit for the "FIRST STEP" nowadays.

You might be thinking, what has that got to do with gnome/kde/web etc. The answer is that those things are not unix. They are all add-ons that have been added on top, later.
Agreed. It's the "SECOND STEP FOR HOW TO CONFIGURE THE WHOLE SYSTEM". There are usually multiple choices on single OS.
 
And cursor dissapears when it is on UTF-8 characters and reappear when backed on ASCII equivalent characters.
In /usr/bin/vi the cursor does not disappear and wide character can be erased as a single character.
This is different from ee(1).
It seems that /usr/src/contrib/nvi/common/encoding.c considers UTF-8.
 
The essence of vi(1), ed(1), ee(1) or editors/vim is that the editor should work at boot and root level of a machine -- in TTY / CLI without any graphical things.

This is needed to manage configuration at a very basic level. It is for the box you're working at or remote maintenance.

So IMHO there is and will always be a need to know those editors.

Being able to work at the basic level of a machine is a real beauty and mastery of a system. Imagine a box that errors on starting the graphical environment. When you can choose to re-install the OS or editing the configs bare bone, I'd choose the latter.

Not only in 2022, but in all possible automated future.
 
In /usr/bin/vi the cursor does not disappear and wide character can be erased as a single character.
The behaviour of cursor depended on terminal emulators.

On x11/qterminal, cursor disappears when on CJK characters.​
On x11/kitty and x11/mate-terminal, it looks flawless.​
On vty (vt on efifb), cursor is shown on the right half of CJK characters only.​

In all cases, deletion with "x" and backspace in insert mode works fine.
 
An all-too realistic scenario.

The wuhan test lab (where the companys new test team has been set up) have been testing the latest overnight build, which contains the code you checked in yesterday. The machine logs have filled up with some unknown garbage error messages and then your code crashed both horribly and spectacularly in a way you have never seen before. The testers raise a code red urgent defect report which your boss assigns to you to look at first thing this afternoon, he has been in the conference call in the project war room for the last 4 hours with his second line in new york since he got to work this morning.

The product launch date is in three days time and they desparately need to get through this last test cycle to make the date, so missing it likely to be a "career-limiting" event. Naturally you are completely unable to reproduce the problem on the machine you've been unit testing it on locally here in san jose, and are perplexed as to why its failing. Your boss is starting to get concerned about your soft skills too, maybe you don't understand team dynamics after all, and the HR lady isn't too sure about your EQ either.

The box in wuhan is a headless 2U server in a rack buried somewhere down on the test floor. You discover no-one there has time to go down to the basement from the fourth floor to fix the broken KVM switch, so there is no console access, and anyway they're all off and out of the office for the next three days in a couple of hours time because it's the spring festival national holiday, a fact your boss somehow forgot to mention to you earlier. Luckily you are able to ssh into the box over the company intranet so you can investigate the system; you have about 2 hours left today to get this fixed, while the testers are still at work in wuhan to re-run the regression test suite.

The only editor on the box is vi, because that is what was installed as standard with the operating system, nothing else is installed anyway because this is a stripped-down pre-production build. All of the operating system software on the box is mounted on a read-only flash drive as part of the product security policy, so you can't install any new software. In addition the test lab's security policy prohibits you from scp'ing any new software onto their machines over the intranet link you're using, so you don't have a cats chance in hell of putting nano, pico, teco, or anything else onto it. Since the last guy they fired tried to run a crypto mine on some of those big SMP servers, the test lab security team are being extra strict.

You rummage around and find the problem, some of the perl scripts have been screwed up by a bum install process when one of the testers knocked the power cable out of the box during the install, a fact he somehow forgot to mention in the code red bug report. Your boss is now having serious doubts about your leadership qualities in the daily morning crisis scrum. However the broken scripts are part of a test package that was installed on a writeable partition, so you are at least able to modify the scripts.

You decide to patch the scripts manually by editing them in situ over ssh, you think you can see what's wrong. Thank heavens you learned vi years ago; it takes you about an hour to patch the scripts using vi and then do some basic testing, which leaves enough time to have the tester re-run the test. You tell the tester to try it again, whereupon... it all starts working properly and passes the test suite.

Your boss suddenly decides your soft-skills are actually top-notch world-class and in fact the scrum just wouldn't be the same without you, tells the HR person that your EQ is outstanding and that you're overdue to receive a crackerjack pencil! You breathe a huge sigh of relief and briefly reflect on what a good idea it was to put the effort into learning vi all those years ago.

And this story is a lot closer to real life than you might think! 😄

1705271601749.png
 
Last edited:
You can actually exit from vi you know... at least, so I've been told. I've been trying to do that for years now anyway, I think I got it to work a few times by accident. You can click the little cross in the corner of that bar thing at the top of the window, that usually works.. Or failing that the secret incantation that few know and many blindly grope their way towards in the darkness is to type ESC:wq or ESC:q!. Or for the real hackers, just ESCZZ. The command 'kill -15 $(pgrep vim)' works too, although it will make ALL of your vim's exit, unless you add some way to choose which one. But as always, YMMV. As Flann O'Brien would say, "for if a stone is cast, there is no foretelling of where it may land".
 
This story about one's inability to quit vi is quite old. One should be embarrassed to put their shortcomings on display and not want to write about them.
I really don't understand why learning vi is supposed to be so hard. It's much easier to learn than most of the modern IDE junk, and such a powerful, elegant design. Even more so when combined with gnu screen or tmux. About 80% of it is learnt by rote, you practice it for a while and then it becomes automatic. It's seriously one of favourite pieces of software ever. Bram Moolenaar has done such a good job of taking vi forward with vim. I was pretty sad when we lost him recently. I use his code just about every day, for everything. I even run vim in termux on my phone.

'They' forced me to use eclipse for a while. I had to learn a whole new meaning of the word "artefacts". I even resorted to eclim after a while http://eclim.org .
 
Note there is also,
Interesting, I wasn't aware of either of those. Thanks!
 
This story about one's inability to quit vi is quite old. One should be embarrassed to put their shortcomings on display and not want to write about them.

In the context of recent discussion of total newbies being dumped into vi during installation, pointing out their shortcomings and wishing them embarrassment for not having read handbooks and manual pages is gatekeeping, effective in deterring uptake by other than cognoscenti.

I'm not embarrassed to advocate for opening the gate. Once people are inside they can explore and determine their own preferences, free from notions like the sanctity of POSIX or other religions.

cheers
 
In the context of recent discussion of total newbies being dumped into vi during installation, pointing out their shortcomings and wishing them embarrassment for not having read handbooks and manual pages is gatekeeping, effective in deterring uptake by other than cognoscenti.

I'm not embarrassed to advocate for opening the gate. Once people are inside they can explore and determine their own preferences, free from notions like the sanctity of POSIX or other religions.

cheers

smithi And I say again. If one considers figuring out that :q quits out of vi and it's too difficult to learn then they should stick to their Game boxes and leave us alone.

In the context of recent discussion of total newbies being dumped into vi during installation, pointing out their shortcomings and wishing them embarrassment for not having read handbooks and manual pages is gatekeeping, effective in deterring uptake by other than cognoscenti.

I'm not embarrassed to advocate for opening the gate. Once people are inside they can explore and determine their own preferences, free from notions like the sanctity of POSIX or other religions
Well of course, complete beginners should never be treated that way. Why don't they teach vi properly for a day or two at the start of the course? Instead on day one of "shell programming 1" its "OK class, type 'vi' to start and then copy in these commands from your worksheet". Yes teach, but how do I use this editor that's different from notepad that we learned at school???

Then they hate vi forever because teach didn't tell them about 'i' and 'ESC' and ':wq' and vow never to use it again. Why don't they teach it? There's nothing intrinsically difficult about it, after all. It's not like trying to learn quaternions.

They never teach you how to type, either, and everyone is sitting there plonking away at the keyboard with two fingers. I have known senior developers who know their way round the kernel source code but who still can't touch type properly after 20 years in the job. You sit next to them and can see that they've somehow figured out how to more or less type with 3 or 4 fingers by then.

When you're a kid and learning to tie your shoe laces they do actually show you how to do it first and then help you practice, they don't just stand there and say "right, tie them up then!". At least, if you're lucky, that is.
 
smithi And I say again. If one considers figuring out that :q quits out of vi and it's too difficult to learn then they should stick to their Game boxes and leave us alone.
Yes, it's quite easy to learn, if any coach/mentor stands by the person who first invoking vi without any knowledge about vi. Without preliminary knowkedge or coach, it is surely almost IMPOSSIBLE.
Once more. vi is an excellent editor FOR STEPPING UP TO EXPERTS/WIZARDS. But not for the first step for newbies coming from Windows or something.
 
If you don't like vi(1), how about ex(1)?
If you type 'quit' it will exit, and if you type 'help', you will get a message including how to exit.

ex(1) would not have had to rush to bookstore.
One thing to mention would be that anyone coming from Windows would hit F1 key instead of typing "help".:(
Old NEC PC-9801 users would look for "HELP" key on their keyboard, which would never exists nowadays.;) Yes, there was a dedicated key.
 
Yes, it's quite easy to learn, if any coach/mentor stands by the person who first invoking vi without any knowledge about vi. Without preliminary knowkedge or coach, it is surely almost IMPOSSIBLE.
Once more. vi is an excellent editor FOR STEPPING UP TO EXPERTS/WIZARDS. But not for the first step for newbies coming from Windows or something.
You don't need a coach, just reading some documentation and articles works just as well. There's no absolute need to "learn vi" at all, and if you want to learn it, it doesn't have to be a "first step" either, sure. But why would a "newbie" pick a system like e.g. FreeBSD in the first place? If it isn't about learning new stuff in a way that will put you in control of your system (in a way only possible by understanding quite a lot of inner workings), it might be the wrong choice. And then, learning lots of stuff that's very different from what you knew before is inevitable. In that light, "learning vi" could even make for good training, because its concept is REALLY unique for a text editor.

IMHO, it's always "worth learning". At least as long as a vi implementation is a typical part of some "base installation" of any "unixy" OS, meaning chances are good it can be used even on some seriously hosed system ... MUCH easier than having to deal with e.g. ed, sed, awk, whatever .... So then, knowing vi buys you something measurable at least when it comes to disaster recovery.

And once you learned it, it might happen you prefer something based on it as your daily editor (like e.g. editors/vim) over other powerful editors, because, as unique as the concept might be, it's pretty efficient once grokked ... of course, this will remain a matter of taste :cool:
 
Back
Top