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

Posted on in Categories , , , last updated June 11, 2016

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?

You can always start up an editor immediately to edit the current file being viewed. This will save some time while typing commands. 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
export EDITOR=vim

Feel free to replace vim with emacs, joe or any other editor of your choice. Open a text file using more or less pager, type:
$ less myfile.txt
OR
$ 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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

6 comment

  1. 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.

    Thanks!

Leave a Comment