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

by on November 1, 2008 · 6 comments· LAST UPDATED April 15, 2013

in , ,

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?

Tutorial details
DifficultyEasy (rss)
Root privilegesNo
Estimated completion timeN/A
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:
$ export EDITOR=vim
$ echo 'export EDITOR=vim' >> ~/.bash_profile
export EDITOR=vim

Open any text file using more or less pager, type:
$ less myfile.txt
$ more ~/some.conf
To edit a file, hit v key from keyboard. This will start up an editor at current line and file.

Further readings:
  • man page less and more
Tweet itFacebook itG+ itDownload PDF versionFound an error/typo on this page?

{ 6 comments… read them below or add one }

1 pradeep December 20, 2008 at 6:12 am

when you use less for more to view at that time you want edit first press ‘v’ then ‘i’


2 Iain Cheyne February 3, 2009 at 4:52 pm

Great tip thank you. I heard about this on the Lottalinuxlinks podcast.


3 Shawn @ apprenticeships in australia June 23, 2011 at 3:05 pm

Hullo, just love your writing :) Sorry if this is a stupid comment, I didn’t find a “like” button :(


4 jeff June 30, 2012 at 3:34 pm

I use TextWrangler which comes with the ‘edit’ command line tool. I have always detested vim and preferred nano’s simplicity. I just tried this hint with nano and then with the TW edit command and both worked great. This is a simple, yet very helpful hint.



5 Nir March 4, 2013 at 8:56 am

i was looking for the EDITOR env-var tip!


6 Philippe Petrinko April 15, 2013 at 1:25 pm

Useful, thanks,
— Philippe


Leave a Comment

Tagged as: , , , , , , , ,

Previous Faq:

Next Faq: