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
Difficulty level Easy
Root privileges No
Requirements vi/vim
Est. reading time N/A
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
$ 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
$ 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

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • pradeep Dec 20, 2008 @ 6:12

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

  • Iain Cheyne Feb 3, 2009 @ 16:52

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

  • Shawn @ apprenticeships in australia Jun 23, 2011 @ 15:05

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

  • jeff Jun 30, 2012 @ 15:34

    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.


  • Nir Mar 4, 2013 @ 8:56

    i was looking for the EDITOR env-var tip!

  • Philippe Petrinko Apr 15, 2013 @ 13:25

    Useful, thanks,
    — Philippe

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum