What editor can I use as a simple vi/vim alternative?

104,437

Solution 1

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

Solution 2

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

Solution 3

as a windows power user, after trying vim and nano I found out that I need something in between, complexity-wise. so I tried slap and It was the exact 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. slap has first-class mouse support, even over SSH connection.


installation:

curl -sL https://raw.githubusercontent.com/slap-editor/slap/master/install.sh | sh

Solution 4

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.

Solution 5

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.

Share:
104,437

Related videos on Youtube

sebagomez
Author by

sebagomez

Updated on September 18, 2022

Comments

  • sebagomez
    sebagomez over 1 year

    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!

    • Panther
      Panther almost 7 years
      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)
    • Andrea Lazzarotto
      Andrea Lazzarotto almost 7 years
      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?)
    • Sergiy Kolodyazhnyy
      Sergiy Kolodyazhnyy almost 7 years
      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
    • Andrea Lazzarotto
      Andrea Lazzarotto almost 7 years
      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.
    • Jos
      Jos almost 7 years
      Please note that these answers (vi, nano) address terminal editors only. While knowledge of these is extremely useful, in practice you would more often use a GUI-based editor like Geany, Gedit, Atom, Sublime Text and many more.
    • Admin
      Admin almost 7 years
      mcedit (part of mc). If I need anything else, it usually means I don't need a text editor but either a text processor or an IDE. There's a lot of console-based editors out in the wild (pico, nano, vi, vim, ed, emacs, joe ... the list goes on), but there was only one editor I didn't need to memorize at all - and that's mcedit (based on cooledit btw).
    • Andrea Lazzarotto
      Andrea Lazzarotto almost 7 years
      @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.
    • Jos
      Jos almost 7 years
      @AndreaLazzarotto I interpreted "coming to Ubuntu thanks to WSL" as "I have switched from Windows to Ubuntu". I may be wrong, of course.
    • Andrea Lazzarotto
      Andrea Lazzarotto almost 7 years
      @Jos OP wrote “coming to Ubuntu's bash”. :) Your comments contains very good suggestion, I just don't think they are essential to be mentioned because basically all GUI editors have a sane interface, which instead is not always found in CLI tools (e.g. vim).
    • sebagomez
      sebagomez almost 7 years
      @AndreaLazzarotto is right, but thanks for the suggestions Jos
    • Andrea Lazzarotto
      Andrea Lazzarotto almost 7 years
      I reworded the question to fit the format of this site. I tried to keep it as close as possible to your original goal while clarifying some features that are needed for the tool you are looking for. Please edit the question further if I inadvertently changed some of your requirements. See the guidelines here: meta.askubuntu.com/a/14399/271
    • SO_fix_the_vote_sorting_bug
      SO_fix_the_vote_sorting_bug over 3 years
      @SergiyKolodyazhnyy What you offer could be good advice, but I would also suggest trying to go "full vim" for one week. It really only takes learning ciw diw yiw and a few movement commands to really understand what vim is trying to do. Baby steps might work for some, but in my case (and many other anecdotal cases) going into the deep end for a week worked out better than the one-step-at-a-time approach because as a noob I would be tempted to resort to 'jjjjjjjjjjjhhhhhh' every time I switched back from a "dumb" editor. It's akin to learning Morse Code at 18 wpm (good) vs 5 (bad habits).
  • Andrea Lazzarotto
    Andrea Lazzarotto almost 7 years
    Not only beginners, basically all humans that do not want to enter the vim vs emacs wars. :P
  • xavier_fakerat
    xavier_fakerat almost 7 years
    +1 I'd go with nano too, even for long time users vi looks like some old crap
  • Panther
    Panther almost 7 years
    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
  • Ravexina
    Ravexina almost 7 years
    Up vote for -B :D
  • Sergiy Kolodyazhnyy
    Sergiy Kolodyazhnyy almost 7 years
    "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.
  • R.M.
    R.M. almost 7 years
    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.
  • fugitive
    fugitive almost 7 years
    Learn vi/vim. :) It is on every nix device. :) Basics aren't that hard.
  • Andrea Lazzarotto
    Andrea Lazzarotto almost 7 years
    @R.M. GUI shortcuts?
  • Andrea Lazzarotto
    Andrea Lazzarotto almost 7 years
    @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).
  • Daniel Jour
    Daniel Jour almost 7 years
    "emacs is more complex than nano." :p this could be the understatement of the year.
  • Sergiy Kolodyazhnyy
    Sergiy Kolodyazhnyy almost 7 years
    @AndreaLazzarotto Exactly ! If you can use what you like - sure. That's not always the case of course, and vim makes sense if you're working with variety of *nix systems, legacy systems, client's servers, etc. My main point was that vim isn't being taught properly, and people focus on the "so many features" part, which leads people to mistakenly believe it's hard to learn. It's not, because 80% of the time what a person needs to do in vim is only 20% or less of what it can do. And I absolutely agree with what R.M. said
  • cat
    cat almost 7 years
    @DanielJour by a few lines of source code yea :P
  • Andrea Lazzarotto
    Andrea Lazzarotto almost 7 years
    @SergiyKolodyazhnyy what I wanted to say is that you should not be required to learn how to do basic operations like typing a word, a newline or exiting the program. Something like the message in this picture, I guess: twitter.com/p_redaelli/status/868385233556480000 I use CLI tools all day long, but I'm not a guy who tries to use a textual editor like it were an IDE. If I need an IDE, I open an IDE. For the rest, nano is enough for me and for 99% of users. :)
  • Andrea Lazzarotto
    Andrea Lazzarotto almost 7 years
    Sorry but... this does not answer the question. OP asked for an alternative to vim and answers should provide that.
  • Andrea Lazzarotto
    Andrea Lazzarotto almost 7 years
    This looks very neat, +1 from me. Although that amount of exclamation marks is disturbing. :P
  • cat
    cat almost 7 years
    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.
  • Ray
    Ray almost 7 years
    @AndreaLazzarotto I agree that it shouldn't be hard to learn how to do such basic things. That said: typing a word: press i, then type the word(s), then press ESC. Newline: press ENTER. Exit: type :q. Now that you know the basics, you can gradually pick up the more powerful features. A few minutes of learning will let you use vim to do everything you can do in nano, plus a few extra things. After that, it just becomes even more useful every time you pick up a new trick. After awhile, it'll also become (far) more useful than an IDE. But you can still use it normally before you get there
  • R.M.
    R.M. almost 7 years
    @AndreaLazzarotto By GUI shortcuts I mean things like ctrl-C/ctrl-V, or ctrl-shift-C/ctrl-shift-V or cmd-C/cmd-V or highlight/middle-click. (They're different depending on OS and interface to Vim/terminal you use, so I didn't want to specify.) -- The point is they're not the "official" Vim way to do it, but they still work.
  • Andrea Lazzarotto
    Andrea Lazzarotto almost 7 years
    @Ray thanks, I already know how to do those things using its absurd interface, and I'm WAY less productive than when I use nano. I guess you didn't check the picture I linked though. :)
  • Andrea Lazzarotto
    Andrea Lazzarotto almost 7 years
    @R.M. if I have access to a GUI then I can open Atom to get a useful text editor with syntax highlighting, multiple cursors, auto-completion, multiple tabs/panels and other stuff. The only reason one is forced to use vim is when needing some advanced features and there is no GUI (assuming you remember 30 different keyboard shortcuts).
  • Shukri Adams
    Shukri Adams about 5 years
    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.
  • Ahmad Ismail
    Ahmad Ismail almost 5 years
    You forgot to mention the main selling point, first-class mouse support (even over an SSH connection)
  • user3932000
    user3932000 over 4 years
    I honestly don't understand why people say "vim is very powerful," other than that's what vim says about itself in the first line of vimtutor. Anything I can do in vim I can with VS Code or what have you, and with far fewer keystrokes.
  • aderchox
    aderchox almost 4 years
    a quick summary of the shortcuts one may need most when using nano: comment multiple lines: esc+3, delete multiple lines: ctrl+k(it basically cuts those lines but there's no difference if you don't paste them afterwards) ;-) , paste lines: ctrl+u("u" stands for "uncut"), to search for something: ctrl+w then type the name and enter, to go to a specific line number: ctrl+shift+w, to cancel anything: ctrl+c, to save: ctrl+o, to save & exit: ctrl+x, to undo: alt+U, to redo: alt+E.
  • psprint
    psprint almost 3 years
    Yes, mcedit is a great, easy editor. If you want a programming-enhanced version of it (e.g.: TAB-completing symbols from CTags index), you might want to checkout neomcedit.software
  • Admin
    Admin almost 2 years
    Cat. It's on every unix machine. Works for me.
  • Admin
    Admin almost 2 years
    cat works too! shift-ctrl-c to copy, shift-ctrl-v to paste, ctrl-d to save and quit.
  • Admin
    Admin almost 2 years
    @user10489 cat doesn't have a clipboard, those are provided by your terminal emulator and aren't available in a tty.
  • Admin
    Admin almost 2 years
    Yup, too true. Doesn't change the results, however.