14

I'm a Windows user coming to Ubuntu's Bash thanks to WSL. Now I need to edit some files and I really hate Vi. Do I just have to deal with it, or is there a simpler alternative?

The features I am looking for are:

  • CLI based
  • easy to use (typing and editing should be similar to Notepad)
  • simple editing capabilities are enough

I will try to master Vim, but I need to make a quick edit right now!

  • It is a matter of opinion. Beginners use nano howtogeek.com/howto/42980/… . vim (vi improved) has a bit of a learning curve but it is very powerful - See linux.com/learn/vim-101-beginners-guide-vim or any vim guides or the vim tutorial , vimtutor (included in vim) – Panther May 29 '17 at 20:12
  • Please note that this question might be closed as quite opinion-based. You might want to reword it to fit the rules of the site (e.g. what can I use as alternative to vim?) – Andrea Lazzarotto May 29 '17 at 20:13
  • 3
    Voting to close this as opinion-based question. Word of advice: start with nano, and later transition to vim with baby-steps. It will pay off in long run because vim is on any Linux system basically – Sergiy Kolodyazhnyy May 29 '17 at 20:19
  • 1
    As a follow up to my comment, the current title is still debatable and could lead to closing. People might consider vim itself to be "good", and this is subjective. May I suggest using the word "easier" instead? Also specifying some desired features could help in narrowing down the question. – Andrea Lazzarotto May 29 '17 at 20:34
  • 2
    @Jos we are talking about WSL where running GUI programs can be done but is not trivial. Also the question wouldn't exists for GUI editors because they are all easier than vim. – Andrea Lazzarotto May 29 '17 at 21:53
22

If you are looking for an alternative editor, you are not alone. Basically life is too short to learn vi and I say this being a software developer for a living. However you should learn how to exit it because it's a problem for one out of 20k programmers. Also performing some basic append/insert operation might be worth learning, because on some stubborn servers you won't find any other editor.

Now, the answer to your question is probably nano.

If you are running some automated build script, using git or running other commands, they might open vim without you wanting it. You can prevent this by running the following before proceeding:

export EDITOR=nano
  • 1
    thanks! extra point for the EDITOR tip – sebagomez May 29 '17 at 20:31
  • 3
    "Basically life is too short to learn vi". No need to spend entire life, although one can if they love vim. I spent 2 hours watching a good tutorial on YouTube, and just kept practicing basics that I learned from the video. Now 70% of all my answers on Ask Ubuntu are written in vim. – Sergiy Kolodyazhnyy May 29 '17 at 21:14
  • 7
    On "life is too short", I thought this essay had a good point. One of the biggest (artificial) roadblocks in learning Vim is the false premise that you need to immediately dive into becoming a "hard core" user. You don't. Use the arrow keys. Use the GUI shortcuts to copy/paste. Hang out in insert mode. Ignore tabs and registers and bells and whistles (for now). It's relatively quick to get to nano-level functionality in Vim, and you can slowly add advanced features later, as you need them. – R.M. May 29 '17 at 21:21
  • @R.M. GUI shortcuts? – Andrea Lazzarotto May 29 '17 at 21:51
  • 1
    @Sergiy vim makes sense if you want to use advanced features. If I were to use vim like I use nano I would just keep using nano (as a matter of fact, I do... I use vim when I am on a server on which I cannot add software, like a client's machine). – Andrea Lazzarotto May 29 '17 at 21:52
11

It is a matter of opinion.

Beginners use nano.

vim ("vi improved") has a bit of a learning curve but it is very powerful. See this beginner's guide for vim or any other vim guides or the vim tutorial vimtutor (included in vim).

For now I highly suggest nano

nano -B /path/to/file/to/edit

-B makes a backup

Commands are issued with the control key and are listed at the bottom of the editor window.

There' a a guide on syntax highlighting see: How do I enable syntax highlighting in nano?

nano

emacs is an alternate to both vim and nano and has many benefits as well. emacs is more complex than nano. You can see emac's tour.

Just for completeness, vim + themes such as Zenburn can be quite helpful

Zenburn

  • 2
    Not only beginners, basically all humans that do not want to enter the vim vs emacs wars. :P – Andrea Lazzarotto May 29 '17 at 20:32
  • 1
    +1 I'd go with nano too, even for long time users vi looks like some old crap – xavier_fakerat May 29 '17 at 20:33
  • Well, to be fair, you can theme vim and a .vimrc goes a long ways. vim and emacs have advanced features that are not available in nano, but it is a waste if you do not use the advanced features. For quick basic edits I use nano although overall I am a vim fanboi. kippura.org/zenburnpage – Panther May 29 '17 at 20:40
  • 1
    Learn vi/vim. :) It is on every nix device. :) Basics aren't that hard. – fugitive May 29 '17 at 21:24
  • 3
    "emacs is more complex than nano." :p this could be the understatement of the year. – Daniel Jour May 29 '17 at 21:53
3

as a windows poweruser , after trying vim and nano I found out that I need something in between, complexity wise. so I tried slap and It was the thing that I was looking for.

slap image

slap is a Sublime-like terminal-based text editor that strives to make editing from the terminal easier.


installation:

curl -sL https://raw.githubusercontent.com/slap-editor/slap/master/install.sh | sh
  • 1
    You forgot to mention the main selling point, first-class mouse support (even over an SSH connection) – blueray May 5 at 7:30
2

Have you ever been frustrated that your text editor wasn’t doing what you wanted? Angered that you can’t remember...

  • ...how to find help?
  • ...what :wq means?
  • ...any of the little lisper that you read as an undergrad?

A small, brave world awaits!

While we're advocating for our favourite lightweight text editors, let me recommend the eXcellent, tiny, and fast xo (exofrills).

It's a single Python 3 file, and it has good support for syntax highlighting through Pygments (although not perfect with non-Python):

enter image description here

It also has extremely simple and useful key combinations which can be readily and easily changed to your heart's content:

enter image description here

Other features:

  • Less than 850 lines of code in a single file!
  • Syntax highlighting!
  • Regular expression matching and replacing!
  • Search history caching!
  • WTFPL licensed!
  • Fully customizable!
  • Start at non-origin locations!
  • Hop between words on a line!
  • Jump to anywhere in the file!
  • Whole file insertion!
  • Beginner friendly - maybe you are new to words!
  • Copy and paste text!
  • Line and column status!
  • Only one row of non-text editing space!
  • Both saving & loading!

The Python3 source is on github, and you can install it more easily using:

sudo apt install python3-pip
sudo pip3 install exofrills 

exofrills: your text has been edited...but you are still hungry.

Disclaimer: I am in no way affiliated with the exofrills project.

  • 1
    This looks very neat, +1 from me. Although that amount of exclamation marks is disturbing. :P – Andrea Lazzarotto May 29 '17 at 23:41
0

While I cannot deny that I too struggled with vi in the beginning, I think an argument can be made that vi is actually very simple to learn. (When I began using Unix the choice was either vi or emacs, so at the time I chose ed, ed being a very simple line editor, which I had learned already from reading early Unix textbooks.) I use vi daily, but I probably use only a very small subset of its features.

Here's first an argument for using vi: vi exists on all systems, uses very few resources, and may be usable over unstable and slow connections, where other editors may fail or be slow and unusable. Or in situations where the system is broken, so arrow keys are not interpreted correctly (bad terminfo settings for example.) So vi can be used to fix the configuration files leading to the problem, without being affected by the problem.

And here is how to learn a useful subset of vi: First: stop thinking of vi as an interactive, terminal-GUI "editor", and see it as a programming language for manipulating text files. In the beginning "vi" stood for VIsual mode, and vi has a nonvisual counterpart ex, which is a good place to start. Type ex at the shell prompt (I will use ¬ to represent return):

$ ex¬
Entering Ex mode.  Type "visual" to go to Normal mode.
:

Now press enter.

:¬
E749: empty buffer
:

So, lets put something in it. Type "a¬", and type a line of text, then a period on a line by itself:

:a¬
Hello World¬
.¬
:

That was the append command. Easy, short and mnemonic. But it would be nice to see what is in the buffer:

:%p¬
Hello World
:

That was the print command, p, obviously. The % is a line range shorthand. Each command may be preceded by a line number or range which the command should apply to. % means "all lines". $ means the last line, and a period means the current line. A number means that particular line. A range is written n,m and a number can be added or subtracted, so .+1,$-1 mean from the next line to the second-last line. A command consisting of just a line number goes to that line. Here is the remaining small subset of commands I use:

:1i¬
this text is inserted before line 1.¬
.¬
:

:w /tmp/filename¬
"/tmp/filename" [New] 2L, 49C written
:

w writes all (or the chosen range of) lines to a file.

:1d¬

deletes line 1.

:.s/Hello/Hello,/¬
Hello, World
:.s/$/!/¬
Hello, World!

s substitutes a regular expression. It's good to know regular expressions!

:q¬
E37: No write since last change (add ! to override)

q quits. wq writes and quits. q! quits without writing, and in a similar vein, w! forces a write to a file if possible.

Now a cool one:

:p
Hello, World!
:.!tr a-z A-Z
:p
HELLO, WORLD!

! as a command filters the lines into a shell command.

And finally:

:vi¬

enters VISUAL mode. Don't be fooled. It looks like an editor, but it's still just an interactive programming shell. You just get to look at the buffer all the time, and a few more commands. In visual mode a : shows the : prompt from ex mode. The arrow keys (if they work) move around, and if they don't, then hjkl do! h left, j down, k up and l right. 0 moves to the first character and ^(think regex here!) to the first non-space character on the line. $ (regex again!) moves to the end of line. Typing :999¬ goes to line 999, naturally, just like in ex mode.

"i" enters insert mode, which now inserts on characters instead of lines, and ends with pressing escape instead of ".¬". "I" inserts at the beginning, "a" after the character under the cursor, and "A" after the end of the current line. Always press escape when done typing text. "x" deletes the character under the cursor, and "D" deletes from the cursor to end of line. "Y" yanks (copies) the current line, and "P" pastes it back. ":pu" does the same, but can be preceded by a line number. ":ya" is the ex equivalent of "Y", and again, useful to apply to a line range. I think there is a mark command as well, but I will admit I don't remember it. I don't miss it.

The above is what I use, and I know I am probably not a very "efficient" vi user. On the other hand, I do use ex's versatility, for example to script editing configuration files. Need to change your hostname foo.bar.com to www.foobar.com in a number of conf files?

for file in conf/*
do (echo "%s/foo.bar.com/www.foobar.com/" ; echo "wq") |ex $file ; done

What I am trying to say is, that I think the problem with vi is that people think of it as a difficult editor. All it takes is to change your mindset a little, and view it as a very simple yet also very powerful interactive programming language instead. So powerful that even with a subset of the available commands, you can use it to great effect - not just as an editor but as a general, scriptable tool well integrated with the rest of Unix. I doubt nano would do all of this - emacs...maybe.

  • 3
    Sorry but... this does not answer the question. OP asked for an alternative to vim and answers should provide that. – Andrea Lazzarotto May 29 '17 at 23:40
  • 1
    I commend the work you put into this answer, but it doesn't really answer the question -- a tutorial on and plug for vim does not belong here at all, but it does belong on your blog. – cat May 29 '17 at 23:47
  • This answer is exactly why so many people are asking for an alternative to the viemacs - the more we say they're unpleasant to use, the more the converted insist that we try harder to use them. – Shukri Adams Mar 21 at 14:21
0

If you want terminal-based Sublime like text editor with mouse support, go for Micro, Slap or Suplemon.

However, if you are looking for a modal text editor, look no further than Kakoune.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.