33

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!

typecasto
  • 170
  • 1
  • 8
sebagomez
  • 441
  • It is a matter of opinion. Beginners use nano https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/ . vim (vi improved) has a bit of a learning curve but it is very powerful - See https://www.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
  • 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. – Jos May 29 '17 at 21:18
  • 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). –  May 29 '17 at 21:43
  • 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
  • @AndreaLazzarotto I interpreted "coming to Ubuntu thanks to WSL" as "I have switched from Windows to Ubuntu". I may be wrong, of course. – Jos May 29 '17 at 21:56
  • @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). – Andrea Lazzarotto May 29 '17 at 23:44
  • @AndreaLazzarotto is right, but thanks for the suggestions Jos – sebagomez May 30 '17 at 12:21
  • 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: https://meta.askubuntu.com/a/14399/271 – Andrea Lazzarotto May 30 '17 at 12:51
  • @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). – SO_fix_the_vote_sorting_bug Jan 07 '21 at 19:15
  • The reason Vim pays off is not so much as you find it everywhere as because there is no other editor on the planet to beat it. You find that in the end you'll want to install Vim anywhere where it isn't there already. – NeilG Aug 05 '23 at 07:38

9 Answers9

45

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
Melebius
  • 11,431
  • 9
  • 52
  • 78
  • 4
    "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
  • 11
    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
  • 2
    @R.M. GUI shortcuts? – Andrea Lazzarotto May 29 '17 at 21:51
  • 2
    @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
  • @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 – Sergiy Kolodyazhnyy May 29 '17 at 21:58
  • 2
    @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: https://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 May 29 '17 at 23:38
  • 1
    @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 – Ray May 30 '17 at 00:43
  • @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. – R.M. May 30 '17 at 01:48
  • @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 May 30 '17 at 09:54
  • @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). – Andrea Lazzarotto May 30 '17 at 09:55
  • My first several months of vi use were just i, normie text editing, then Esc, :q or :wq, and Enter. If you're happy with a normie text editor, insert mode in vi is a normie editor so long as your terminal lets you select text and copy+paste. Then if/when you start to want to do something faster, you can just incrementally learn commands to do that. – mtraceur Feb 08 '23 at 21:07
16

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

k0pernikus
  • 6,115
Panther
  • 102,067
  • 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
  • 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. http://kippura.org/zenburnpage/ – Panther May 29 '17 at 20:40
  • Up vote for -B :D – Ravexina May 29 '17 at 20:53
  • 1
    Learn vi/vim. :) It is on every nix device. :) Basics aren't that hard. – fugitive May 29 '17 at 21:24
  • 4
    "emacs is more complex than nano." :p this could be the understatement of the year. – Daniel Jour May 29 '17 at 21:53
  • @DanielJour by a few lines of source code yea :P – cat May 29 '17 at 22:36
  • 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. – user3932000 Nov 09 '19 at 07:31
  • 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. – aderchox Jun 19 '20 at 19:58
  • Cat. It's on every unix machine. Works for me. – user10489 Jul 11 '22 at 05:18
8

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
Soorena
  • 201
6

Tilde is exactly what you're looking for.

To quote from Tilde's homepage

Tilde is a text editor for the console/terminal, which provides an intuitive interface for people accustomed to GUI environments such as Gnome, KDE and Windows. For example, the short-cut to copy the current selection is Control-C, and to paste the previously copied text the short-cut Control-V can be used. As another example, the File menu can be accessed by pressing Meta-F.

If you're used to keyboard shortcuts like

  • Ctrl + C for copy,
  • Ctrl + V for paste,
  • Ctrl + A for select all,
  • Ctrl + Z for undo,
  • Ctrl + Y for redo,
  • Ctrl + F for find,
  • Ctrl + S for save,
  • etc...

You'll find Tilde's default shortcuts and interface overall very intuitive.

See https://github.com/gphalkes/tilde#installing-tilde for installation instructions.

Here's how Tilde looks like. A Tilde screenshot

Myk
  • 103
  • 3
Huge
  • 604
  • 1
    https://camo.githubusercontent.com/cc46af81e544b440142f7c3ce6e49e472e6d8c733a374f483ab725ae0dbbd7b3/68747470733a2f2f6f732e6768616c6b65732e6e6c2f74696c64652f74696c64652d73637265656e73686f742e706e67 – Valerio May 09 '23 at 11:47
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.

cat
  • 1,672
3

Mcedit

This is the (seriously underrated) built-in editor of Midnight Commander. Install:

sudo apt install mc

To edit a file with it, issue

mcedit file-name
Adjustments for better usability
  • Mouse support is enabled, but better disable the annoying "Persistent Selection" by pressing F9 and going into the General menu.

  • Some of the default bindings are exotic, especially copy-cut-paste, but all are configurable via ~/.config/mc/mc.keymap under the [editor] section. That file will not exist initially, so you can grab a copy from /etc/mc/mc.keymap. For your convenience, I'm appending the one I used before I switched to Vim.

    [editor]
    Store                 =  ctrl-c
    Paste                 =  ctrl-v
    Cut                   =  ctrl-x
    Undo                  =  ctrl-z
    Redo                  =  ctrl-y
    Save                  =  ctrl-s
    EditNew               =  ctrl-n
    MarkAll               =  ctrl-a
    Search                =  ctrl-f
    SearchContinue        =  ctrl-alt-f
    Help                  =  f1
    UserMenu              =  f2
    Mark                  =  f3
    Replace               =  f4
    Copy                  =  f5
    Move                  =  f6
    Options               =  f7
    Remove                =  f8
    Menu                  =  f9
    Quit                  =  f10; esc
    SyntaxOnOff           =  f11
    SaveAs                =  f12
    SyntaxChoose          =  ctrl-alt-x
    ShowNumbers           =  alt-n
    Goto                  =  alt-l
    Up                    =  up
    Down                  =  down
    Left                  =  left
    Right                 =  right
    WordLeft              =  ctrl-left
    WordRight             =  ctrl-right
    Enter                 =  enter
    Return                =  shift-enter; ctrl-enter; ctrl-shift-enter
    BackSpace             =  backspace
    Delete                =  delete
    PageUp                =  pgup
    PageDown              =  pgdn
    Home                  =  home
    End                   =  end
    Tab                   =  tab
    Top                   =  ctrl-up
    Bottom                =  ctrl-down
    TopOnScreen           =  ctrl-pgup
    BottomOnScreen        =  ctrl-pgdn
    DeleteToWordBegin     =  alt-backspace
    DeleteToWordEnd       =  alt-d
    DeleteToEnd           =  ctrl-k
    MarkPageUp            =  shift-pgup
    MarkPageDown          =  shift-pgdn
    MarkLeft              =  shift-left
    MarkRight             =  shift-right
    MarkToWordBegin       =  ctrl-shift-left
    MarkToWordEnd         =  ctrl-shift-right
    MarkUp                =  shift-up
    MarkDown              =  shift-down
    MarkToHome            =  shift-home
    MarkToEnd             =  shift-end
    MarkToFileBegin       =  ctrl-shift-home
    MarkToFileEnd         =  ctrl-shift-end
    MarkToPageBegin       =  ctrl-shift-pgup
    MarkToPageEnd         =  ctrl-shift-pgdn
    MarkScrollUp          =  ctrl-shift-up
    MarkScrollDown        =  ctrl-shift-down
    MarkColumnPageUp      =  alt-pgup
    MarkColumnPageDown    =  alt-pgdn
    MarkColumnLeft        =  alt-left
    MarkColumnRight       =  alt-right
    MarkColumnUp          =  alt-up
    MarkColumnDown        =  alt-down
    MarkColumn            =  f13
    ReplaceContinue       =  f14
    Complete              =  alt-tab
    InsertOverwrite       =  insert
    Refresh               =  ctrl-l
    Sort                  =  alt-t
    Mail                  =  alt-m
    ParagraphFormat       =  alt-p
    MatchBracket          =  alt-b
    ExternalCommand       =  alt-u
    Bookmark              =  ctrl-u
    BookmarkFlush         =  ctrl-delete
    BookmarkNext          =  ctrl-alt-down
    BookmarkPrev          =  ctrl-alt-up
    Shell                 =  ctrl-o
    InsertLiteral         =  ctrl-q
    MacroStartStopRecord  =  ctrl-r
    ShowTabTws            =  alt-underline
    ShowMargin            =  ctrl-b
    FilePrev              =  alt-minus
    FileNext              =  alt-plus
    SelectCodepage        =  alt-e
    WindowFullscreen      =  ctrl-t
    # ExtendedKeyMap           =
    # WindowPrev               =
    # WindowNext               =
    # WindowList               =
    # WindowResize             =
    # WindowMove               =
    # LearnKeys                =
    # SpellCheckSelectLang     =
    # SpellCheckCurrentWord    =
    # SpellCheck               =
    # OptionsSaveMode          =
    # RepeatStartStopRecord    =
    # Find                     =
    # InsertFile               =
    # MacroDelete              =
    # MacroStopRecord          =
    # MacroStartRecord         =
    # History                  =
    # Date                     =
    # BlockSave                =
    # MarkColumnParagraphDown  =
    # MarkColumnParagraphUp    =
    # MarkColumnScrollDown     =
    # MarkColumnScrollUp       =
    # MarkParagraphDown        =
    # MarkParagraphUp          =
    # BlockShiftRight          =
    # BlockShiftLeft           =
    # Unmark                   =
    # MarkWord                 =
    # MarkLine                 =
    # Close                    =
    # EditFile                 =
    # ParagraphDown            =
    # ParagraphUp              =
    # DeleteToHome             =
    # DeleteLine               =
    # ScrollDown               =
    # ScrollUp                 =
    

If you like it, update your default editor by running select-editor.

Quasímodo
  • 2,017
  • 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 http://neomcedit.software – psprint Jun 15 '21 at 16:20
3

micro seems to be right up your alley. It's a terminal editor similar to vi or nano but with much more sensible keybinds. e.g. Ctrl+C is copy, Ctrl+V is paste, Ctrl+S is save, Ctrl+Q to quit, etc. It's got built in syntax-highlighting for many languages, as well as mouse support.

If you just want to open a file, edit it, and close it, it's one of the most painless ways to do so.

typecasto
  • 170
  • 1
  • 8
2

You can try micro

It's natural for people who are familiar with windows, and it supports lsp

There are also some rust alternatives. Though not so powerful(But faster.).

1

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.

LHP
  • 39
  • 6
    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
  • 4
    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
  • 1
    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 '19 at 14:21