{"id":6942,"date":"2021-06-09T13:17:28","date_gmt":"2021-06-09T13:17:28","guid":{"rendered":"https:\/\/linuxways.net\/?p=6942"},"modified":"2021-06-09T13:17:28","modified_gmt":"2021-06-09T13:17:28","slug":"how-to-install-and-use-vim-editor-in-linux","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-install-and-use-vim-editor-in-linux\/","title":{"rendered":"How to Install and Use Vim Editor in Linux"},"content":{"rendered":"<p>A powerful tool for the command line, vim (Vi Improved) is a text editor that is used for editing programs and config files written in Python, shell, C, Perl, C++, etc. It is great for the development environment. This article will go through installing vim, using it for editing and managing documents, and uninstalling it.<\/p>\n<h2>Installing vim<\/h2>\n<p>The first step will be to update the package database using:<\/p>\n<pre>sudo apt update<\/pre>\n<p>You will be asked for your password before the packages update, enter your password to proceed.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"490\" height=\"57\" class=\"wp-image-6943\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-200.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-200.png 490w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-200-300x35.png 300w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/p>\n<p>Next, search for vim packages using:<\/p>\n<pre>sudo apt search vim<\/pre>\n<p>You will see a long list of available packages you don\u2019t need to install all of them. We will be installing vim, vim-tiny can be installed instead as well.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"613\" height=\"372\" class=\"wp-image-6944\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-201.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-201.png 613w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-201-300x182.png 300w\" sizes=\"auto, (max-width: 613px) 100vw, 613px\" \/><\/p>\n<p>To install vim, run:<\/p>\n<pre>sudo apt-get update<\/pre>\n<pre>sudo apt install vim<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"693\" height=\"123\" class=\"wp-image-6945\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-202.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-202.png 693w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-202-300x53.png 300w\" sizes=\"auto, (max-width: 693px) 100vw, 693px\" \/><\/p>\n<p>You will be asked to confirm the installation, enter <strong>y<\/strong>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"289\" class=\"wp-image-6946\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-203.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-203.png 705w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-203-300x123.png 300w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/p>\n<p>You can check if vim installed by running:<\/p>\n<pre>vim --version<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"744\" height=\"305\" class=\"wp-image-6947\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-204.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-204.png 744w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-204-300x123.png 300w\" sizes=\"auto, (max-width: 744px) 100vw, 744px\" \/><\/p>\n<h2>Opening vim<\/h2>\n<p>To open the vim editor, run:<\/p>\n<pre>vim<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"385\" height=\"29\" class=\"wp-image-6948\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-205.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-205.png 385w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-205-300x23.png 300w\" sizes=\"auto, (max-width: 385px) 100vw, 385px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"728\" height=\"537\" class=\"wp-image-6949\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-206.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-206.png 728w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-206-300x221.png 300w\" sizes=\"auto, (max-width: 728px) 100vw, 728px\" \/><\/p>\n<p>You can see the vim version along with some helpful commands.<\/p>\n<h2>Creating a file<\/h2>\n<p>To create a new file, use:<\/p>\n<pre>vim {filename}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"447\" height=\"29\" class=\"wp-image-6950\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-207.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-207.png 447w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-207-300x19.png 300w\" sizes=\"auto, (max-width: 447px) 100vw, 447px\" \/><\/p>\n<p>When you run the above command, the file opens in the vim editor.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"766\" height=\"610\" class=\"wp-image-6951\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-208.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-208.png 766w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-208-300x239.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-208-150x120.png 150w\" sizes=\"auto, (max-width: 766px) 100vw, 766px\" \/><\/p>\n<p>When you try typing in anything in the editor, you won\u2019t be able to. That\u2019s because vim opens in normal mode. Vim has four modes, we will look at each.<\/p>\n<h3>Normal mode<\/h3>\n<p>When you open vim it is in normal mode. You cannot enter text in this mode, you can only view the document. To enter normal mode, press Esc.<\/p>\n<h3>Visual mode<\/h3>\n<p>This mode allows you to select and manipulate text. You can enter visual mode by pressing either one of the following keys:<\/p>\n<p>v : You can select text by moving your cursor up or down, left or right.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"222\" height=\"494\" class=\"wp-image-6952\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-209.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-209.png 222w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-209-135x300.png 135w\" sizes=\"auto, (max-width: 222px) 100vw, 222px\" \/><\/p>\n<p>V : You can select the entire line by moving up or down.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"245\" height=\"503\" class=\"wp-image-6953\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-210.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-210.png 245w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-210-146x300.png 146w\" sizes=\"auto, (max-width: 245px) 100vw, 245px\" \/><\/p>\n<p>CTRL v : This enters visual block mode, allowing you to expand and contract the selection.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"240\" height=\"489\" class=\"wp-image-6954\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-211.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-211.png 240w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-211-147x300.png 147w\" sizes=\"auto, (max-width: 240px) 100vw, 240px\" \/><\/p>\n<h3>Insert mode<\/h3>\n<p>This lets you edit text. You can enter insert mode through the following keys:<\/p>\n<p>i : enter insert mode at the current cursor position<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"525\" height=\"541\" class=\"wp-image-6955\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-212.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-212.png 525w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-212-291x300.png 291w\" sizes=\"auto, (max-width: 525px) 100vw, 525px\" \/><\/p>\n<p>a : enter insert mode after the current cursor position<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"434\" height=\"531\" class=\"wp-image-6956\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-213.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-213.png 434w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-213-245x300.png 245w\" sizes=\"auto, (max-width: 434px) 100vw, 434px\" \/><\/p>\n<p>I: enter at the beginning of the current line<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"478\" height=\"572\" class=\"wp-image-6957\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-214.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-214.png 478w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-214-251x300.png 251w\" sizes=\"auto, (max-width: 478px) 100vw, 478px\" \/><\/p>\n<p>A: enter at the end of the current line<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"460\" height=\"541\" class=\"wp-image-6958\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-215.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-215.png 460w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-215-255x300.png 255w\" sizes=\"auto, (max-width: 460px) 100vw, 460px\" \/><\/p>\n<h3>Command mode<\/h3>\n<p>This mode is used for saving documents, searching, quitting the program, etc. You can enter this mode using :.<\/p>\n<p>Here a couple of common commands:<\/p>\n<p>:wq -&gt; to save and exit the document<\/p>\n<p>:help -&gt; shows you helpful tips<\/p>\n<h2>Editing a document<\/h2>\n<p>Now that you are familiar with the modes, let\u2019s edit our file.<\/p>\n<p>Open the file using:<\/p>\n<pre>vim {filename}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"451\" height=\"28\" class=\"wp-image-6959\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-216.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-216.png 451w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-216-300x19.png 300w\" sizes=\"auto, (max-width: 451px) 100vw, 451px\" \/><\/p>\n<p>Enter insert mode by pressing i. Enter your text.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"551\" height=\"305\" class=\"wp-image-6960\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-217.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-217.png 551w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-217-300x166.png 300w\" sizes=\"auto, (max-width: 551px) 100vw, 551px\" \/><\/p>\n<p>To save and exit the editor, press the escape key, followed by :wq, and then hit enter.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"403\" height=\"569\" class=\"wp-image-6961\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-218.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-218.png 403w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-218-212x300.png 212w\" sizes=\"auto, (max-width: 403px) 100vw, 403px\" \/><\/p>\n<p>The following commands will help you with editing:<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Command<\/strong><\/td>\n<td><strong>Use<\/strong><\/td>\n<\/tr>\n<tr>\n<td>:w<\/td>\n<td>Save<\/td>\n<\/tr>\n<tr>\n<td>:q<\/td>\n<td>Quit<\/td>\n<\/tr>\n<tr>\n<td>y<\/td>\n<td>Copy<\/td>\n<\/tr>\n<tr>\n<td>yy<\/td>\n<td>Copy line<\/td>\n<\/tr>\n<tr>\n<td>p<\/td>\n<td>Paste<\/td>\n<\/tr>\n<tr>\n<td>d<\/td>\n<td>cut<\/td>\n<\/tr>\n<tr>\n<td>dd<\/td>\n<td>Cut line<\/td>\n<\/tr>\n<tr>\n<td>:\/word<\/td>\n<td>Search forward for a word<\/td>\n<\/tr>\n<tr>\n<td>:?word<\/td>\n<td>Search backward for a word<\/td>\n<\/tr>\n<tr>\n<td>n<\/td>\n<td>Traverse through the whole document to look for the searched word<\/td>\n<\/tr>\n<tr>\n<td>x<\/td>\n<td>Delete character<\/td>\n<\/tr>\n<tr>\n<td>dw<\/td>\n<td>Delete word from the cursor on<\/td>\n<\/tr>\n<tr>\n<td>dd<\/td>\n<td>Delete line<\/td>\n<\/tr>\n<tr>\n<td>D$<\/td>\n<td>Delete end of line<\/td>\n<\/tr>\n<tr>\n<td>L<\/td>\n<td>Moves the cursor one character to the right<\/td>\n<\/tr>\n<tr>\n<td>j<\/td>\n<td>Moves the cursor down by one line<\/td>\n<\/tr>\n<tr>\n<td>k<\/td>\n<td>Moves the cursor up by one line<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>You can also add text to your file when creating it. Use:<\/p>\n<pre>echo {your text} &gt;&gt; {filename}<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"725\" height=\"48\" class=\"wp-image-6962\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-219.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-219.png 725w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-219-300x20.png 300w\" sizes=\"auto, (max-width: 725px) 100vw, 725px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"437\" height=\"40\" class=\"wp-image-6963\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-220.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-220.png 437w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-220-300x27.png 300w\" sizes=\"auto, (max-width: 437px) 100vw, 437px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"547\" class=\"wp-image-6964\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-221.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-221.png 724w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-221-300x227.png 300w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><\/p>\n<h2>Uninstalling vim<\/h2>\n<p>To uninstall vim from your system, use:<\/p>\n<pre>sudo apt remove vim<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"486\" height=\"31\" class=\"wp-image-6965\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-222.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-222.png 486w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-222-300x19.png 300w\" sizes=\"auto, (max-width: 486px) 100vw, 486px\" \/><\/p>\n<p>You will be asked for your password before proceeding.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"501\" class=\"wp-image-6966\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-223.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-223.png 723w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-223-300x208.png 300w\" sizes=\"auto, (max-width: 723px) 100vw, 723px\" \/><\/p>\n<p>Next, you will need to enter <strong>y<\/strong> to confirm the uninstallation.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"723\" height=\"501\" class=\"wp-image-6967\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-224.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-224.png 723w, https:\/\/linuxways.net\/wp-content\/uploads\/2021\/06\/word-image-224-300x208.png 300w\" sizes=\"auto, (max-width: 723px) 100vw, 723px\" \/><\/p>\n<p>This article went through how to install vim, followed by some basics on using vim and then uninstalling it.<\/p>","protected":false},"excerpt":{"rendered":"<p>A powerful tool for the command line, vim (Vi Improved) is a text editor that is used for editing programs and config files written in Python, shell, C,&hellip;<\/p>","protected":false},"author":1,"featured_media":7094,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[100,181],"class_list":["post-6942","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu","tag-ubuntu-20-04","tag-vim-editor"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6942","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=6942"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/6942\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/7094"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=6942"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=6942"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=6942"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}