VI / Vim Print Line Numbers on Hardcopies / Printer

How do I print line numbers on the printer for my c / java / c++ code written using vi or vim text editor under Linux / UNIX like operating system?

Tutorial details
Difficulty Easy (rss)
Root privileges No
Requirements vi/vim
Time N/A
To print line number on screen and hardcopies such as printer type the following two commands while vim / vi text editor is open:

set number
set printoptions=number:y

Make sure you add above two commands to your ~/.vimrc file; so that settings get loaded everytime you start the vim text editor.

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

🐧 7 comments so far... add one

CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig 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
7 comments… add one
  • Giorgis May 31, 2008 @ 11:38

    Great tip, thanks guys (and google)

  • R Mar 4, 2009 @ 0:03


  • venkatakumar Nov 12, 2009 @ 13:45

    What is great tip , it working good.

  • venkatakumar Nov 12, 2009 @ 13:45

    what a great tip, it’s working…

  • waleking May 27, 2012 @ 6:19

    Thanks for your tip, it works very well!

  • Philippe Petrinko Apr 15, 2013 @ 13:28

    Good to remember, thanks Vivek.
    — Philippe

  • Shripad Lale Dec 20, 2016 @ 3:39

    Excellent tip! Thanks a lot!

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Problem posting comment? Email me @