{"id":17313,"date":"2022-05-30T07:29:56","date_gmt":"2022-05-30T07:29:56","guid":{"rendered":"https:\/\/linuxways.net\/?p=17313"},"modified":"2022-05-30T07:29:56","modified_gmt":"2022-05-30T07:29:56","slug":"how-to-show-or-hide-line-numbers-in-vim","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-show-or-hide-line-numbers-in-vim\/","title":{"rendered":"How to Show or Hide Line Numbers in Vim"},"content":{"rendered":"<p>Vim is a powerful and highly configurable command line editor that comes installed with most of the operating systems. It offers many useful features for editing and configuration of files. However, some of its useful features are disabled by default. One of them is line numbering. With Vim line numbering features, you can display line numbering at the beginning of each line which comes helpful when modifying the text. Line numbers are also useful in debugging scripts, code review and configuration files.<\/p>\n<p>Vim has following three line numbering modes:<\/p>\n<ul>\n<li>Absolute line number<\/li>\n<li>Relative line number<\/li>\n<li>Hybrid line number<\/li>\n<\/ul>\n<p>This post covers how to show or hide line numbers in Vim\/Vi text editor. We will discuss all three modes.<\/p>\n<p><strong>Note:<\/strong><\/p>\n<ul>\n<li>Use the Ctrl+Alt+T keyboard shortcut to open the command line Terminal.<\/li>\n<li>We have tested the commands and procedure on Ubuntu 20.04 LTS OS. The same commands and procedure are valid for any Linux distribution.<\/li>\n<\/ul>\n<h2>Show Absolute Line Numbers<\/h2>\n<p>It is the standard line numbering mode which shows the line numbers in the beginning of each line in the file.<\/p>\n<p>To show absolute line numbering, follow the below steps:<\/p>\n<p>1. Switch to Vim\u2019s Normal operation mode by hitting the Esc key.<\/p>\n<p>2. Then hit <strong>: <\/strong>and type the below command and hit Enter.<\/p>\n<pre>set number<\/pre>\n<p>or you can use the below abbreviation after hitting the \u201c:\u201d key:<\/p>\n<pre>set nu<\/pre>\n<p>Now you will see the absolute line numbers at the beginning of each line.<\/p>\n<h2><img loading=\"lazy\" decoding=\"async\" width=\"699\" height=\"408\" class=\"wp-image-17314\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-86.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-86.png 699w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-86-300x175.png 300w\" sizes=\"auto, (max-width: 699px) 100vw, 699px\" \/><\/h2>\n<h2>Hide Absolute Line Numbers<\/h2>\n<p>To hide absolute line numbering, follow the below steps:<\/p>\n<p>1. Switch to Vim\u2019s Normal operation mode by hitting the Esc key.<\/p>\n<p>2. Then hit <strong>:<\/strong> and type the below command and hit Enter.<\/p>\n<pre>set nonumber<\/pre>\n<p>or you can use the below command after hitting the \u201c:\u201d key and hit Enter:<\/p>\n<pre>set number!<\/pre>\n<p>You can also use the abbreviated form of the above commands <strong>set nonu<\/strong> or <strong>set nu!<\/strong> after pressing the : to hide absolute line numbers.<\/p>\n<h2>Show Relative Line Numbers<\/h2>\n<p>In relative line numbering mode, the current line is marked as 0 while all the above and below lines are incrementally numbered (1,2,3,\u2026) relative to the current line.<\/p>\n<p>To show relative line numbering, follow the below steps:<\/p>\n<p>1. Switch to Vim\u2019s Normal operation mode by hitting the Esc key.<\/p>\n<p>2. Then hit <strong>: <\/strong>and type the below command and hit Enter.<\/p>\n<pre>set relativenumber<\/pre>\n<p>or you can use the below abbreviation after hitting the \u201c:\u201d key:<\/p>\n<pre>set rnu<\/pre>\n<p>Now you will see the current line number marked as 0 and if you move the cursor up or down, you will see the numbers marked as 1,2 3,\u2026.<\/p>\n<h2><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"463\" class=\"wp-image-17315\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-87.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-87.png 781w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-87-300x178.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-87-768x455.png 768w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/><\/h2>\n<h2>Hide Relative Line Numbers<\/h2>\n<p>To hide relative line numbering, follow the below steps:<\/p>\n<p>1. Switch to Vim\u2019s Normal operation mode. Hit the Esc key to do so:<\/p>\n<p>2. Then hit <strong>:<\/strong> and type the below command and hit Enter:<\/p>\n<pre>set norelativenumber<\/pre>\n<p>or you can use the below command after hitting the \u201c:\u201d key and hit Enter:<\/p>\n<pre>set relativenumber!<\/pre>\n<p>You can also use the shortened form of the above commands <strong>set nornu<\/strong> or <strong>set rnu!<\/strong>.<\/p>\n<h2>Show Hybrid Line Numbers<\/h2>\n<p>Hybrid line numbering enables both absolute and relative line numbering. It is similar to the relative line numbering except the current line shows its absolute number instead of showing 0.<\/p>\n<p>To show relative line numbering, follow the below steps:<\/p>\n<p>1. Switch to Vim\u2019s Normal operation mode by hitting the Esc key.<\/p>\n<p>2. Then hit <strong>: <\/strong>and type the below command and hit Enter.<\/p>\n<pre>set number relativenumber<\/pre>\n<p>or type the below commands one by one after hitting the \u201c:\u201d key for once:<\/p>\n<pre>set number<\/pre>\n<pre>set relativenumber<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"781\" height=\"463\" class=\"wp-image-17316\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-88.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-88.png 781w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-88-300x178.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-88-768x455.png 768w\" sizes=\"auto, (max-width: 781px) 100vw, 781px\" \/><\/p>\n<h2>Hide Hybrid Line Numbers<\/h2>\n<p>To hide hybrid line numbering, follow the below steps:<\/p>\n<p>1. Switch to Vim\u2019s Normal operation mode by hitting the Esc key.<\/p>\n<p>2. Then hit <strong>:<\/strong> and type the below command and hit Enter:<\/p>\n<pre>set nonumber norelativenumber<\/pre>\n<p>or type the below commands one by one after hitting the \u201c:\u201d key for once:<\/p>\n<p>set number!<\/p>\n<pre>set relativenumber!<\/pre>\n<p>You can also use the abbreviated form of the above commands <strong>set nonu nornu<\/strong> or <strong>set nu! set rnu!<\/strong>(one by one) to hide absolute line numbers.<\/p>\n<h2>Enable File Numbering Permanently<\/h2>\n<p>The method we have discussed above only enables the line numbering for the currently opened file. To enable line numbering for all the files that opens in Vim, follow the below procedure:<\/p>\n<p>1. Edit .vimrc configuration file using the below command in Terminal:<\/p>\n<pre>$ vim ~\/.vimrc<\/pre>\n<p>2. Then in the insert mode, use the following commands:<\/p>\n<p>To enable absolute line numbering mode, the entry would be:<\/p>\n<pre>set number<\/pre>\n<p>To enable relative line numbering mode, the entry would be:<\/p>\n<pre>set relativenumber<\/pre>\n<p>To enable hybrid line numbering mode, the entry would be:<\/p>\n<pre>set number relativenumber<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"616\" height=\"325\" class=\"wp-image-17317\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-89.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-89.png 616w, https:\/\/linuxways.net\/wp-content\/uploads\/2022\/05\/word-image-89-300x158.png 300w\" sizes=\"auto, (max-width: 616px) 100vw, 616px\" \/><\/p>\n<p>Then press Esc and type :wq to save and exit the file.<\/p>\n<p>That is all there is to it! By following the procedures discussed in this article, you can show or hide line numbers in Vim\/Vi text editor. You have learned about different line numbering modes and how to enable them for a current file or permanently for all files.<\/p>","protected":false},"excerpt":{"rendered":"<p>Vim is a powerful and highly configurable command line editor that comes installed with most of the operating systems. It offers many useful features for editing and configuration&hellip;<\/p>","protected":false},"author":1,"featured_media":17365,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[1015,279],"class_list":["post-17313","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-line-numbers","tag-vim"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/17313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=17313"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/17313\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/17365"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=17313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=17313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=17313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}