is "vi" worth learning in 2022?

blimey, I only see this now...

"is "vi" worth learning in 2022?" asked on 30 december.

In my experience just two days is a bit short to learn vi or vim well enough. You might consider practicing during 2023 as well.
I've been using vi since the early 1980s and am still learning new things about it, even today. It includes a veritable cornucopia of editing features.
 
Yeah, sure. I would be ashamed if a product of mine would need a thread on Stack Overflow on how to exit it.

UI should be intuitive. It's a matter of quality.
What a great answer to that thread!

I never though of explaining vi's modes as a state machine, it works really well. See vi is "helping" you learn state machines. They're important in several areas of computer science.
 
4. Using shell scripts and environment variables to define long filenames which you use most frequently (here we assume use of sh or bash as your default shell interpreter language):

i. Prepare a short shell script to define any number of long filenames and/or pathnames which you edit most frequently:
Code:
$ export b=$HOME/bin; mkdir $b; export PATH=$PATH:$b
$ fd=$b/filename-definitions; touch $fd; chmod +x $fd; vi $fd
ii. Press i (for insert) in vi in order to insert the following lines in /home/user1/bin/filename-definitions:
Code:
b=$HOME/bin
h=/usr/local/etc/apache24/httpd.conf
wd=/usr/local/my-web-application-directory-name
f1=my-textfile1.txt; f2=my-textfile2.txt; f3=my-textfile3.txt
s1=my-script-1; s2=my-script-2; s3=my-script3
export h wd f1 f2 f3 s1 s2 s3
iii. Press ESC followed by :x to return to normal mode, write the file, and return to the shell prompt:
Code:
ESC
:x
iv. Edit your shell profile to make this all work automatically in the future:
a. Enter cd; pwd to verify that your present working directory is your home directory:
Code:
cd; pwd
b. Enter vi .shrc (or vi .bashrc) to edit your profile file:
Code:
vi .shrc
c. Press G to position the cursor on the last line of the profile:
Code:
G
d. Press o to enter insert mode after the last line:
Code:
o
e. Enter the following line to invoke the /home/user1/bin/filename-definitions script every time you login in the future (don't forget the period and space before the command:
Code:
. bin/filename-definitions
f. Press ESC followed by :x to write your changes into .shrc (or .bashrc):
Code:
ESC
:x
g. Log out and log in again.
h. Start the new login session by, for example, editing the /home/user1/my-textfile1.txt file using the environment variable $f1:
Code:
vi $f1
i. To edit /home/user1/my-textfilel2.txt:
Code:
vi $f2
j. You don't need to return to the shell prompt every time you start editing a new file. Because you have exported your environment variables, you can now enter them from vi's : prompt:
Code:
:e $f3

As you add additional files to your developing project, create new environment variables for each file, and add it to /home/user1/bin/filename-definitions.
 
I've always used nano to edit text files. Is it even worth spending the time to master vi/vim ? I'd rather put my time towards learning new FreeBSD commands, shell scripting, or programming in C.. and for code editors there's stuff like geany. I just don't see the advantages of going through the trouble of learning the ins and outs of this editor, when I can use something much simpler and get the same thing done. Maybe someone can explain ? Anyone actually still use vi in 2022 and what for?
Traditional editors(vi/emacs) have their own benefits. But learning pure vi is waste of time unless you want vim.
 
But learning pure vi is waste of time unless you want vim.
Unless you work with Unix-like systems where you may have to work with a machine without a full-blown modem editor.

It hasn’t happened to me *that* often but it’s been worth having vi-knowledge in my mental toolbox. And probably getting less likely by the day.

If you’re just looking after a machine or two of your own then probably not much point (but you’d possibly get stuck in a pager wondering how to search or quit).

Probably getting to the point you should try it and see. If your eyeballs start to bleed then stop. That’s what happens when I try and understand “ed”.
 
# insert mode
  • vi will display --INSERT-- in the bottom left corner when you are in insert mode

Good info, thanks for posting.

I have used the arrow keys and i for editing and :wq and :q! for saving. So many time ended up getting a capital letter when I pressed del and sometime for unknow reasons multiple copies of the letter I wanted to delete.

When I enter the insert mode, there is no --INSERT-- at the bottom left (over SSH console)? is this related to FreeBSD vi too? not even sure if there are different versions (GNU etc.)
 
4. Using shell scripts and environment variables to define long filenames which you use most frequently (here we assume use of sh or bash as your default shell interpreter language):

i. Prepare a short shell script to define any number of long filenames and/or pathnames which you edit most frequently:
Code:
$ export b=$HOME/bin; mkdir $b; export PATH=$PATH:$b
$ fd=$b/filename-definitions; touch $fd; chmod +x $fd; vi $fd
ii. Press i (for insert) in vi in order to insert the following lines in /home/user1/bin/filename-definitions:
Code:
b=$HOME/bin
h=/usr/local/etc/apache24/httpd.conf
wd=/usr/local/my-web-application-directory-name
f1=my-textfile1.txt; f2=my-textfile2.txt; f3=my-textfile3.txt
s1=my-script-1; s2=my-script-2; s3=my-script3
export h wd f1 f2 f3 s1 s2 s3
iii. Press ESC followed by :x to return to normal mode, write the file, and return to the shell prompt:
Code:
ESC
:x
iv. Edit your shell profile to make this all work automatically in the future:
a. Enter cd; pwd to verify that your present working directory is your home directory:
Code:
cd; pwd
b. Enter vi .shrc (or vi .bashrc) to edit your profile file:
Code:
vi .shrc
c. Press G to position the cursor on the last line of the profile:
Code:
G
d. Press o to enter insert mode after the last line:
Code:
o
e. Enter the following line to invoke the /home/user1/bin/filename-definitions script every time you login in the future (don't forget the period and space before the command:
Code:
. bin/filename-definitions
f. Press ESC followed by :x to write your changes into .shrc (or .bashrc):
Code:
ESC
:x
g. Log out and log in again.
h. Start the new login session by, for example, editing the /home/user1/my-textfile1.txt file using the environment variable $f1:
Code:
vi $f1
i. To edit /home/user1/my-textfilel2.txt:
Code:
vi $f2
j. You don't need to return to the shell prompt every time you start editing a new file. Because you have exported your environment variables, you can now enter them from vi's : prompt:
Code:
:e $f3

As you add additional files to your developing project, create new environment variables for each file, and add it to /home/user1/bin/filename-definitions.
I am using aliases instead:

v='/home/amw/.config/vifm/scripts/vifmrun .'
v3='vim /home/amw/.config/i3/config'
vX='vim /home/amw/.Xresources'
va='vim /home/amw/.config/i3/app-icons.json'
vab='vim /home/amw/bin/autostart-bspwm.sh'
val='vim /home/amw/.config/alacritty/alacritty.yml'
vb='vim /home/amw/.config/bspwm/bspwmrc'
vba='vim ~/.bash_aliases'
vc='vim /home/amw/.config/conky/conky.conf'
vcolors='cd ~/.vim/plugged/vim-colorschemes/colors'
vf='vim /home/amw/.config/vifm/vifmrc'
vk='vim /home/amw/.config/kitty/kitty.conf'
vl='vim /home/amw/.config/lilyterm/default.conf'
vp='vim /home/amw/.config/polybar/config'
vs='vim /home/amw/.config/sakura/sakura.conf'
vswm='vim /home/amw/.config/spectrwm/spectrwm.conf'
vsx='vim /home/amw/.config/sxhkd/sxhkdrc'
vthemes='cd ~/.vim/plugged/vim-airline-themes/autoload/airline/themes'
vv='vim /home/amw/.vimrc'
vx='vim /home/amw/.xinitrc'
vxs='vim /home/amw/.xsettingsd'
vz='vim /home/amw/.zshrc'
 
vi isn't a good editor. Unfortunately, people still use it because "it has always been there".
Sorry, but in this point I disagree with you.

You name all the points of someone who fumbled around a bit with vi,
presumbly when being forced to used it (while under stress within a emergency situation [Linux]),
cursed loudly and a lot (I felt the same way many times)
...decided to hate it,
and that's it.
But never really got past the hurdle,
grasped its true concept.
I bet if you did you'd talk otherwise.

Okay, vi needs two things to get through to it:
  1. DON'T compare vi with any editor you've learned before. Start fresh all over as you never used any texteditor before.
  2. Practise. You'll need at least a couple of hours, biting bullets (cursing is permitted [see 1.] as using backspace and cursorkeys (Vim and neovim) for the beginning. Don't stick too strictly to the tutorials! Use ZZ to leave the editor, not :wq
A Formula-one is no mobility scooter.
Even as an experienced driver you have to practise.

And of course, it's absolutely up to you, to rate if it's worth the effort.
Only you knew the amount of textediting you have to do.
Learning vi only pays off in the long term for someone really doing large amounts of textediting.
For anybody doing just smaller or medium amounts of textediting I wouldn't recommend to learn vi.

Under some commercial Unix or Linux have a cheat-sheet ready, because vi may be the only editor available in some situations your system doesn't fully boot.
Within FreeBSD you don't need on.
Under FreeBSD vi is always available, but by system's default settings FreeBSD's basic editor such as for emergencies is ee ("Easy Editor")
It's small (and slow), but self explaining by having the help always online.
It's good for small editing tasks like commenting a line within /boot/loader.conf that prevents your system from fully boot, and you don't know vi 😁

Btw:
having the handbook/help/command's explanations always visible is very helpful, but neither intuitive nor efficient.

I would be ashamed if a product of mine would need a thread on Stack Overflow on how to exit it.
An old vi joke:
"How to produce a random file?"
"Set someone who never used it before infront of vi and ask him to leave the editor."

ZZ - don't need a thread for that.

When unsure hit Esc - that always brings you back in editing/command mode.

UI should be intuitive.
It is.

Don't confuse things.
Intuitive means how to create new things by successfully guessing and combining things you've already learned,
and not "avoid learning."
Once you grasped the concept of vi - and yes, you need some training to do so - vi is very intuitive and very logical structured.
That's why I told the example with the romans alphabet.
If you do not know the signs and how to combine them to words, it's just chaotic rubbish to you, seems to be the total opposite of intuitve.
But once you know all 26 letters and learned to combine them you can write anything with them - very intuitive.

The core problem most people have with vi is the two modes of editing and entering text are seperated,
while within other editors they are always avaible at the same time.
The reason is:
Most of the time you're doing more editing than entering text.
That's why vi starts in editing mode.
Starting in textenter mode would make sense, if the most tasks someone does were producing new files.
(You see: vi is finetuned to spare even the lessest superflous single keystroke.)

While in texteditors with both modes combined (most) the editor has to distinguish between text and command.
That's why commands usually done by combining special keys with other keys.
You also have to learn those. Otherwise you stick with GUI's menus, making mouse-kilometers, which is editing at snail's speed. 🐌
And even if your learned those, in all other texteditors I know you cannot guess commands or combine those - you just depend on pure rote learning.
That's not intuitive.

When you have a seperate editing mode, you don't have to distinguish every single time.
Then single keys become commands.
That's much less typing, thus speeding up the process significantly.
They can easily be combined to create whole command-chains.
This way you don't have to check your long list of rote learned editing commands, their according keystrokes, and how to do them in which order to reach the editing task.
You "program" your own editing command for the very editing job you're currently want to do every time tailored exactly to the point.

Of course, I admit,
this requires thinking while editing,
and doing a bit math in your head is also very helpful.
(I recommend to have line numbering activated by default.)
But if you have no problem with mental arithmetics,
and willing to bite bullet,
once grasp and loved Vim's and neovim's concept of registers and macros you will agree:

Vi is not outdated.
Its concept is timeless, and almost ingeniuos (at least for people who prefer thinking above rote learning 😜)
Vi is very powerful.
Vi is very intuitive.
Vi is very efficient.
Vi is editing at max-speed.

You may say:"I don't like vi", "it's complicated to learn", "its usage is strange/very special - nothing for everybody" or "to me vi is no useful", even "it may not worth learning" (depends)
but you cannot say "vi is outdated" or "bad."
Because that's simply not true.
 
I have spent a lot of time in the vicinity of people who work with and on Unix.

To use vi(1) effectively, you have to be able to use ex(1), or ed(1). You also have to have a reasonable grasp of regular expressions. None of these skills are trivial. Happily, they are not requisite for the most casual of use.

But, vi is not truly rewarding to use without some practice and commitment. Neither is Unix... and most of us would not be here unless we already understood that...
 
I don't think I've seen in this thread, another useful shortcut for commonly typed things. For example, I've been going through a shellscripting book that uses bash. As, in FreeBSD, I'd have to type #!/usr/local/bin/bash or #!/usr/bin/env bash for each script. I have in $HOME/.nexrc (for FreeBSD's included nvi--if you prefer vim you can make a $HOME/.vimrc),
Code:
abbr rbash /usr/bin/env bash
I chose rbash at random, I don't remember how I chose rbash instead of something else. I have a few other standard things like a shortcut to turn on numbering and another to turn on spell check. I think this thread has evolved into little vi/vim tips which, to me, is a good thing because there's always something to be learned.
By the way, as we've mentioned Ed, and I'm a big Michael Lucas book fan, he has a book on Ed, available for only $4.99. (And no, I don't get a referral fee. This is an unsolicited fan blurb.) :)
 
I always think of vi not as a program, but as a protocol, for the interface between my fingers and some text. That in mind, it's timeless and essential learning - e.g. you may find neovim more palatable, but you'll find vi on any unix, and it's close enough
 
I've been using vi since the early 1980s and am still learning new things about it, even today. It includes a veritable cornucopia of editing features.
I find this a good example. Can anyone name another text editor from ~1980 still in common use? How about early 2000s?

From this I can project that in another 40 years (~2060), vi will still be known and all current "modern" "trendy" text editors will have disappeared into obscurity. VSCode will become the new E. Notepad++ will become the new RHIDE. Etc.

The Lindy effect is real! ;)
 
My problem with VI(M) is that has always appeared on my way in any panic situation I have had so far! 😖

Is unavoidable building a bad relationship with it, personally my default editor is Micro...
 
Hi! Let me put my 5cents in this thread:

1.
HUMAN PSYCHOLOGY
Human's psychology and neurobiology determine that well known things looks like BETTER for us. And of course, we will find A LOT of arguments why.
This mean “If You start from vi, using vi several years, 99,999% that any other editor would be refused”

2.
Suggesting “good old tool” from 80' for newcomers of 2020’ - is a stupid things.
Because (and this is logical) FreeBSD newcomers seek for productive and usable tool with well known features like:
- hotkeys are intuitive (the same 'traditional' Ctrl-C, Ctrl-V, Ctrl-X, Ctrl-Z...)
- Syntax highlighting
- screen split between 2-4 files or the parts of same code file
- spellcheck for most common programming languages & config file formats
- useful find/replace and copy/paste
- useful comment/uncomment for blocks of code
- several clipboards
- cursor position, file coding format (ascii, utf-8, etc...)
This is just “must have” for ANY code editor or IDEs nowadays.


Most of this concepts / features not exist (and not asked for) many years ago. But this not mean You need to be sticky to “old great tool” that born 100 years ago!

In 2022 shells/zsh (+ shells/zsh-autosuggestions, shells/zsh-syntax-highlighting, shells/ohmyzsh) in conjunction with misc/mc and editors/nano (or editors/micro) pretending to be great toolset.

looks like more flexible, powerful, easy to switch on, and with a ton of features if You wish...
 
I suspect that most Linux distributions have nano, not pico. Pico is part of the pine (now alpine) email program. Debian Linux, for example, has nano as its default editor. For example, if working on a Debian system, if you type in visudo, the /etc/sudoers comes up in nano, not vi or vim. (This can be easily changes with alternatives, a Linux program to reset things like editors).
 
Why I have to remember non-standard shortcuts "invented" 40+ years ago?
There is no difference in learning shortcuts for vi, emacs, nano or other editors or applications. They make the handling of the tools fast and efficient. The vi, emacs and wordstar shortcuts are different but all are almost standards. They will survive all of us.
 
If vi is the only text editor, I will remember its keys. But there is choice and I have to run it once per 2-3 years. Sorry but I forget the "menu" key every time.
 
Back
Top