Tag: less

Edit a File When You Are Viewing It Using more / less Command

Aritcle here.

Edit a File When You Are Viewing It Using more / less Command

Posted by Vivek Gite [Last updated: November 1, 2008]
\"\"

Question: I can use less or more pagers to view a file. How do I start an editor (such as vi or other text editor) to edit the current file without leaving the less or more pager command?

Answer: You can always start up an editor immediately to edit the current file being viewed. This will save some time and command typing. The editor is taken from the environment variable VISUAL if defined, or EDITOR if VISUAL is not defined, or defaults to \”vi\” if neither VISUAL nor EDITOR is defined. I suggest you define your EDITOR first, enter:

1
$ export EDITOR=vim

OR

1
$ echo \'export EDITOR=vim\' >> ~/.bash_profile

Now open any file using more or less pager:

1
$ less myfile.txt

OR

1
$ more ~/some.conf

Now, to edit a file, hit v key from keyboard. This will start up an editor at current line and file.