Samizdis
Samizdis

Reputation: 1661

Quick text editor from within shell environment

I sometimes want to make small edits to small file from within the shell I'm working in, while looking at my command history.

As an example, if I want to write a short shell script after experimenting on the command line, I can do:

cat > example.sh

and work from what I can see.

But cat's not the best editor. If I use vi or emacs though (as far as I can tell) the whole environment changes, and I can only see what I've been doing is if I run the shell history command from inside the editor, which isn't really what I want either.

I realise this is really nit-picky, but does anyone have any suggestions for a sensible editor (or way of using a sensible editor) that I can quickly invoke from the command-line and doesn't spawn its own environment?

Upvotes: 2

Views: 267

Answers (2)

Jens
Jens

Reputation: 72667

If you need to edit the command line, have a look at the (built-in) fc editor (Bourne Shells).

If you need to edit files though, nothing beats a real editor. You can use The Standard (ed, man!) or what everybody else should be using, vi :-)

Unlike vi, ed does not clear the screen; in fact, it is a line oriented editor. Note that some versions of vi in some terminals (vim in an xterm) can be configured to save the screen and restore it upon exit as it was before editing.

Upvotes: 2

dogbane
dogbane

Reputation: 274670

Try a terminal multiplexer like tmux (or screen). It will allow you to quickly split your terminal (horizontally or vertically) into another "pane" and you can then start vi in the new pane. You will still be able to see the rest of your shell in the other pane. I do this all the time.

Upvotes: 2

Related Questions