23

Are there scenarios where vi is the only option to create, edit or modify a file in an Ubuntu environment?

My question is basically to really know if there is such a case where I would be forced to use vi because it would be the only option available in a particular case in the Ubuntu ecosystem.

Could a particular case exist where I somehow would not have access to other options like nano, pico or simply sending the information with tools like cat, sed, tee and more?

I would assume this is more of a server or cloud side since on the Desktop there are many more options, but from anybody that uses the terminal a lot I ask:

Is there such a case?

Greg
  • 103
Luis Alvarado
  • 211,503
  • @CAB yep, but I just realised that that actually uses nano... :) – Tim Aug 27 '14 at 17:50
  • 8
    @Tim Actually visudo can use any editor. Since its default configuration on Ubuntu respects the EDITOR and VISUAL environment variables, you can run sudo env VISUAL=emacs visudo for emacs or even gksudo env VISUAL=gedit visudo for a graphical editor like Gedit. (sudo -H or sudo -i may be used in place of gksudo.) I suggest this env way as VISUAL=emacs sudo visudo won't work (sudo resets most of the environment) and sudo -EH might be considered inadvisable. – Eliah Kagan Aug 28 '14 at 01:13
  • 3
    vi is the only option ... when vi is the only editor installed that you know and you don't want to spend time installing another. vi is the best option when vi is the editor you know/like best among those available and you don't want to spend time installing one you like more. There is NEVER a case where only one tool can solve a problem; there may be times when the choices are constrained. And some people actually like vi. (Not me. I'm an Emacs bigot. Though I can tolerate many editors.) – keshlam Aug 28 '14 at 02:25
  • 3
    cat? sed? Really? vi really is not that complicated, and if you really cannot be bothered to learn it, you only have to remember two modes (Normal and Insert mode). You move the cursor with arrows (or HJKL if not available), press "i" to start editing (insert mode). Once you are done, press "Esc" to go back to normal mode. Type ":wq" to save and quit (Write + Quit). – sleblanc Aug 28 '14 at 02:34
  • Situations where your sys-admin is lazy and only uses vi, so other editors aren't installed and he/she refuses. I've been told to suck it up and learn vi by system admins from amateurs through HPC experts. (And for that matter, to use csh instead of bash because they didn't want to write their custom environment scripts again). – tpg2114 Aug 28 '14 at 03:33
  • @Eliah yep realised that now :) Turns out nano is my default! – Tim Aug 28 '14 at 07:50
  • 2
    just suck it up and learn vi :) Its not as hard as it first appears and once you know it you'll never waste time hunting for other editors on any new system you use. – JamesRyan Aug 28 '14 at 16:01
  • This isn't as much an answer as a historical observation. N years ago when AIX was new a company I worked for did a project for IBM. Our AIX system had emacs; I'd never even learned vi. Theirs didn't. I couldn't afford to look unix ignorant when I visited in Austin to demo our project - so I learned enough vi for the occasion. – Ethan Bolker Aug 28 '14 at 16:00
  • @EliahKagan sudo accepts environment variables directly before the command that sudo is to run, like sudo VISUAL=emacs visudo. There is no need (in this case) to use env. – Jonathan Callen Aug 29 '14 at 23:49
  • @JonathanCallen Yes, you're quite right. (gksu/gksudo does not accept this syntax, however.) – Eliah Kagan Aug 29 '14 at 23:52

10 Answers10

33

Inside the Ubuntu ecosystem, I do not think this case can even exist, as vi would at least be a vim-tiny, which is already a “real vim” far from “real vi.”

In the context of resource limited embedded systems, which are not normally Ubuntu, you may just have a vi that turns out to be a link to busybox. And not space left. Then, vi is the only option.

Apart from that, I think situations where vi the only option are not very common at all today, even outside the Linux world.

But there can easily be situations where vi is the only option you can plan for, the only option that certaily will exist in some future situation — which will happen inside a customer’s over-chilled server room, most probably.

Imagine you are called by a customer:

Customer: I need to get this configuration fixed! Now!! I don’t know how, but I can tell you where the configuration file is. Can you help me!?!

You: Ok, what kind of system is that running on?

Customer: Oh, it's on server foo, ahh... it's running... can't remember, something with "ix" in the end, or mayeb with "ux"...

No problem, by now, you know there will be vi!

Volker Siegel
  • 13,065
  • 5
  • 49
  • 65
  • 1
    I have personally worked on a number of embedded systems which contained only vi as a text editor, I believe buildroot and yocto both have it as the only editor when using minimal config options. Admittedly this is not an issue on ubuntu, but if you are an embedded dev this can be a real issue. However you can always as the OP said use pipe based tools such as sed, sort, grep and such, however this can be very painful. – Vality Aug 27 '14 at 22:32
  • The busybox case is indeed a good one. What's annoying about it is, I don't think it's even a full vi (at least it wasn't a decade ago, and I hope they haven't bloated it up, even if it is annoying). – hyde Aug 28 '14 at 07:23
  • 1
    busybox vi is 4k lines: curl -s https://gitorious.org/busybox/busybox/raw/1c7a58dfb82ea04c525e0c19f94f2d800dee99e3:editors/vi.c | wc ;) – Volker Siegel Aug 28 '14 at 07:50
17

Vi is never the only option; you can always use ed instead.

evilsoup
  • 4,485
13

Well, there is one case where you need the vi editor, lets assume:

  • there is not graphical interface
  • you're on some strange unknown *nix system
  • your terminal look like this:

enter image description here

  • you have enough of guys like this:

enter image description here

As you can see there is no numerical keypad. With the old vi (and I mean the original traditional vi, not vim, vim.tiny, or vim.basic) you can edit a file with this keyboard. Without arrow keys? Yes, when you're in command mode you moved through the file with h, j, k and l, like a pro. h was left, j was down, k was up and l was right.

chaos
  • 27,506
  • 12
  • 74
  • 77
  • 5
    I think this answer is actually not that bad (typewriter-like keyboards not a completely unlikely thing to encounter), but in fact that doesn't mean you need vi in particular. All older text editors have "backup" key combinations that allow you to work without arrow keys etc., though I daresay that vi is the only editor where you wouldn't miss the arrow keys. – leftaroundabout Aug 27 '14 at 20:07
  • Somewhat off-topic: I don't see why you would need a numerical keypad for any text editor, and arrow keys are useless in Vim anyway. :P – Doorknob Aug 27 '14 at 23:54
  • 1
    Hey, don't discount good old ed! No need for these "visual" gimmicks on a system like that! Just try using vim on paper terminal and see how you manage... More seriously, knowing ed is useful anyway, it's a decent option when editing needs to be scripted. – hyde Aug 28 '14 at 07:27
  • how do you switch to command mode with that keyboard (I don't see escape; was there another key combo for that?) – Foon Aug 29 '14 at 16:29
  • @Foon There is an escape key =) It's where tab should normally be. To the left of the Q-key. – chaos Aug 29 '14 at 16:55
  • @Doorknobs: Numpads used to be more common than dedicated arrow keys. – Dennis Aug 29 '14 at 17:51
6

Fact of the matter is that, in many distributions editors like nano and pico just aren't standard while other packages, namely vim-tiny are. See here for the package list of ubuntu-minimal, vim-tiny is the only editor. According to this answer, it seems to be the case for Ubuntu server, as well. I know this is the case for base Debian, Fedora as well.

That being said, given that if you have nano on your system I've yet to see a case where you'd HAVE to use vi instead, but, playing off @Volker's answer, if you're working for a customer and don't have root access? apt-get install nano isn't going to do you much good (if it even has access to the outside internet!).

Mitch
  • 4,697
4

There are a number of cases where vi (and by that I naturally mean vim.tiny because that's what we ship) could be the only interactive editor. If we ignore butterflies and cosmic-rays, these seem like the most likely occasions where this could happen:

  • You're only using the ubuntu-minimal base meta-package. This depends on vim-tiny but no other editors. I can't currently find a way to install Ubuntu without the standard^ task but you can remove it after installation with:

    sudo apt-get remove $(apt-cache show standard^ | awk '/Package: / {print $2}')
    

    I have personal experience where I've been handed a system image without the standard^ task installed. If I hadn't had network access vi would have been my only option.

  • Chrooting into an environment that only mapped vi through

  • Manually nuking all the other editors (and disabling the means to reinstall them)

  • Manually breaking the shell to stop known editors except vi being launched.

A true-minimal install will be the most likely reason but those are fairly rare these days. Some VPS and cloud hosting companies use them (to save disk space as much as anything else) but I would suggest that they are definitely not the norm.

Oli
  • 293,335
2

In cases where you are not able to install emacs, or in cases where you need to modify a configuration file in order to enable you to install emacs. :-p

Craig Tullis
  • 130
  • 3
2

Many (most?) Busy-Box installations only have vi.

It's not ubuntu specific, but it is true of many embedded devices.

Fake Name
  • 425
2

There's always cat, head, tail ... so I am not sure there is system where you do not have any alternative, but it's possible to find systems where there is not a better alternative even if you prefer emacs.

My example was a system I once administered, that was either so slow (or the line was slow and lossy), that when navigating with cursor keys, it often suddenly switched to insert and injected garbage into the edited file, and using HJKL for movement was the only reliable option.

Edheldil
  • 161
2

Here's the case where vim is the only option within Ubuntu ecosystem: Ubuntu Snappy doesn't come with any text editor other than vim-tiny. Perhaps in future there will be one, but not as of 2015-16. If you are going to be using Ubuntu Snappy over serial console or ssh, you better be prepared to use vim.

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
0

I got myself into a situation once where only vi's linemode was working. Something having to do with having really screwed up terminal definitions. Basically only vi in linemode (this behaves like normal vi if you pretend you have a 1 line terminal), ex, and ed were going to work because the only terminal definition was "dumb".

Joshua
  • 709
  • 3
  • 8