10

I am looking for a lightweight text editor that runs in the terminal. I currently use nano 2.2.6, but I am slightly dissatisfied with it (particularly the fact that it doesn't have working undo/redo).

Must haves:

  1. Ability to run in the Terminal.
  2. Quick startup time. If it's much slower than nano it won't be usable.
  3. Easy customization of tabs/indentation.
  4. Syntax highlighting for major languages.
  5. Undo/redo functionality.
  6. Cannot be modal (vim is out unless there's a way to use it with key combinations rather than modes.)
  7. Customizable key combinations for common tasks.
  8. Free.
  9. Works on OSX.
  10. Supports soft line wrapping (long lines wrap visually but not with newlines).

Nice to haves:

  1. Ability to use it in place of a pager (i.e. less).
  2. Ability to do smart indentation.
  3. Cross-platform.
  4. Ability to install via MacPorts.
  5. Ability to do fancier IDE-like editing for code: enter image description here

I will be using the editor mostly to edit shell scripts, but I might also use it for java coding, writing markdown, writing html/javascript etc.

Note: I've tried emacs, and it fails these two requirements for me:

  1. Quick startup time. If it's much slower than nano it won't be usable.
  2. Easy customization of tabs/indentation.
  • Have you tried starting emacs with emacs -q? Is it still slow? – Tymric Mar 19 '15 at 16:02
  • @Timmy, yeah I've tried that. It's still way to slow for me. Maybe I'm doing something wrong, but I've tried a lot of things to speed up emacs, and none have gotten it to the startup time of nano. – stiemannkj1 Mar 19 '15 at 16:31
4

VIM

(vim is out unless there's a way to use it with key combinations rather than modes.)

Funnily enough, once I really thought about this, I realized that vim is the answer.

vim has all the "must haves" and "nice to haves":

  1. Ability to run in the Terminal.
  2. Quick startup time. If it's much slower than nano it won't be usable.
  3. Relatively easy customization of tabs/indentation.
  4. Syntax highlighting for major languages.
  5. Undo/redo functionality.
  6. Cannot be modal (vim is out unless there's a way to use it with key combinations rather than modes.)
  7. Customizable key combinations for common tasks.

I was worried about #6 and #7, but it turns out that you can start vim in insert mode and customize insert mode keyboard shortcuts. On top of that, vim has an amazingly useful Ctrl+o shortcut which allows you to execute a single command in insert mode. Combining these two allows you to map modal vim commands to nano like keyboard shortcuts (e.g. inoremap <C-u> <C-o>P " map vim paste to nano's [Ctrl]+[u] paste keyboard shortcut).

  1. Free.
  2. Works on OSX.
  3. Supports soft line wrapping (long lines wrap visually but not with newlines).

Nice to haves:

  1. Ability to use it in place of a pager (i.e. less).
  2. Ability to do smart indentation.
  3. Cross-platform.
  4. Ability to install via MacPorts.
  • macvim
  1. Ability to do fancier IDE-like editing for code.*

On top of all this, vim has amazing documentation from loads of programmers (heck, it even has its own SE site), tons of features, and is very customizable. I highly recommend hacking vim to work like this if you have similar requirements. It may seem like sacrilege to vim experts, but it perfectly fits my requirements.

* I don't know if it has the feature shown in the question, but it certainly has a lot of IDE-like editing features.

2

Emacs

Ability to run in the Terminal.

emacsclient -nw

Also, if you want that because you're editing files on a remote machine where you're logged in over SSH, there's another way: open the remote files in your local Emacs session. To edit files accessed over SSH, type hostname.example.com:/path/to/file when opening the file. See the manual for more advanced usage.

Quick startup time. If it's much slower than nano it won't be usable.

That's what you're doing wrong: you're starting a new instance of Emacs each time you edit a file. Emacs was designed so that you start Emacs once and for all, and when you want to open a file, you open it in the running instance. Call emacsclient -nw to start an interface to the already-running Emacs in the current terminal. Either run emacs --daemon as part of your session startup, or run emacsclient -a '' -nw … to tell emacsclient to start Emacs if it isn't already started.

Easy customization of tabs/indentation.

Emacs has a lot of features to set up indentation. Advanced customization tends to depend on the language. I've never had trouble to make Emacs follow the indentation. “Easy” is subjective, but if you're doing something that's at all possible with any editor out there, I doubt that it's going to be hard in Emacs — at most, if it's a very unusual style that isn't supported out of the box by setting a few variables, you should be able to get help getting it right with a few line of Elisp.

Syntax highlighting for major languages.

Emacs gives it the weird name font lock.

Undo/redo functionality.

Sure. By default, there's no “redo”, but you can undo an undo operation. There are packages to provide a more familiar undo/redo interface, undo trees, etc.

Cannot be modal (vim is out unless there's a way to use it with key combinations rather than modes.)

Emacs can emulate Vi but you don't have to do it.

Customizable key combinations for common tasks.

Of course. And macros and so on.

Free.

A poster child of the GNU movement. Enough said.

Works on OSX.

Emacs For Mac OS X, Aquamacs, etc.

Supports soft line wrapping (long lines wrap visually but not with newlines).

Visual Line Mode

Ability to use it in place of a pager (i.e. less).

It's been done more than once. I've never tried. What you can do instead is run shell commands inside Emacs, which gives you paging for free. Emacs also has a native way to read man pages, browse the web, etc.

Ability to do smart indentation.

See indentation above. Emacs can be configured to indent automatically in various situations or on request; this tends to depend on the file type so I won't go into detail.

Cross-platform.

Unix, OSX native (see also OSX above), Windows, MS-DOS, Android iOS via Cydia, and a few more.

Ability to install via MacPorts.

Check

Ability to do fancier IDE-like editing for code:

Out of the box, you get indentation, syntax highlighting, identifier lookup, folding. There are lots of additional packages providing additional features; CEDET is a good start.

1

mcedit

mcedit is a cross-platform and full-featured text editor that comes packaged with Midnight Commander.

  1. It can be run in the terminal, using the command mcedit, or by pressing F4 within Midnight Commander
  2. Has a quick startup time
  3. Customizable tab size. By changing the variable editor_tab_spacingin the configuration file (~/.config/mc/ini)
  4. Syntax highlighting for many languages, found in the Options menu
  5. Undo/redo functionality
  6. Not modal, uses key combinations
  7. Can record and save macros, and repeat simple commands. I don't think you can customize the original key bindings, but you could create new ones and use them instead.
  8. Free (GNU)
  9. Works on OSX
  10. Supports line wrapping. Customizable using the editor_word_wrap_line_length, editor_option_typewriter_wrap, and wrap_mode variables

Edit:

As discussed in the comments, the line wrap adds breaks so it does not satisfy the requirement of soft line wrapping. The viewer that comes with it, mcview supports this kind of wrapping, but without editing functionalities.

1

ne does a lot of this.

Stuff I’m sure about:

  1. Runs in terminal
  2. Starts up near instantly
  3. Completely customizable key combinations
  4. Optional undo/redo
  5. Free
  6. Will compile on OS X, and I wouldn't be surprised if it’s available on MacPorts

Not sure:

  • Easy customization of tabs/indentation
  • How it handles line wraps
  • Has customizable syntax highlighting, but not sure if they are by default
0

JOE

joe has all of the "must haves" except softwrapping (as far as I know):

Must haves:

  1. Ability to run in the Terminal (and via MacPorts).
  2. Quick startup time. If it's much slower than nano it won't be usable.
  3. Easy Customization of tabs/indentation.
  4. Syntax highlighting for major languages.
  5. Undo/redo functionality.
  1. It's not modal.
  1. Customizable key combinations for common tasks.
  • It actually has a nano-like mode with familiar key combos by starting joe with the alternative jpico command.
  1. Free.
  2. Works on OSX.
  • joe is cross platform.
  1. Supports soft line wrapping (long lines wrap visually but not with newlines).

joe is actually very nice and I recommend it for anyone who wants a more full-featured version of nano (as long as you don't care about softwrapping).

0

In 2018, the answer to this question is: nano! It ticks all the boxes. It's now (September 2018) on version 3.0, they have kept improving the functionality and codebase, and keep doing it! Besides undo, it now also has key macro recording. For my usage (and it sounds like OP's usage as well) many keybindings need redefining and default settings changed, but do that in ~/.nanorc or globally in /etc/nanorc and Bob's your uncle for years to come..!

-1

I just discovered that nano does have soft wrapping. I'm currently using jed (formerly ne, but it doesn't handle UTF-8 well), and jed is very powerful, but if you add "set softwrap" in your ~/.nanorc it will allow you to softwrap (and redefine most keys, and set loads of other options!). I'm never going back to nano, but on a new install it is often included. I still install ne because it hardly needs configuration. Unfortunately, jed requires tons of configuration for me (as does joe).

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.