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

by Vivek Gite · 2 comments

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:
$ export EDITOR=vim
OR
$ echo 'export EDITOR=vim' >> ~/.bash_profile
Now open any file using more or less pager:
$ less myfile.txt
OR
$ more ~/some.conf
Now, 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

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 2 comments… read them below or add one }

1 pradeep 12.20.08 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 02.03.09 at 4:52 pm

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

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous FAQ:

Next FAQ:

nixCraft FAQ PDF Collection Now Available To All