{"id":21875,"date":"2023-10-01T04:06:39","date_gmt":"2023-10-01T04:06:39","guid":{"rendered":"https:\/\/linuxways.net\/?p=21875"},"modified":"2023-10-01T04:06:39","modified_gmt":"2023-10-01T04:06:39","slug":"how-to-exit-quit-linux-vi-editor-with-or-without-saving-changes-in-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/ubuntu\/how-to-exit-quit-linux-vi-editor-with-or-without-saving-changes-in-ubuntu-22-04\/","title":{"rendered":"\u200b\u200bHow to Exit\/Quit Linux Vi Editor With or Without Saving Changes in Ubuntu 22.04?"},"content":{"rendered":"<p><strong>Vim (Vi Improved) <\/strong>is a free, open-source, text editor available in Linux, Unix, Windows, and macOS. Vim can be used both in GUI (Graphical User Interface) and the command line. Due to Vim\u2019s flexibility and reliability, it is a very popular text editor. This article will demonstrate how to exit the Vim text editor without saving changes and with saving changes on Linux\/Ubuntu 22.04 LTS.<\/p>\n<h2><a id=\"post-21875-_drhf0egpmy5r\"><\/a>What are the Modes in Vim Editor?<\/h2>\n<p>Vim editor furnishes three modes to manage files:<\/p>\n<ul>\n<li><strong>Command Mode: <\/strong>Command mode is enabled by default. It supports commands like redo, undo, replace, etc. We can exit command mode by clicking the \u201cEsc\u201d key.<\/li>\n<li><strong>Insert Mode: <\/strong>is enabled by \u201ci\u201d. It enables text insertion. We can exit command mode by pressing the \u201cEsc\u201d key.<\/li>\n<li><strong>Visual Mode:<\/strong> is enabled by \u201cCtrl+V\u201d. It is used for selecting text for copy, cut, delete, paste, and other operations.<\/li>\n<\/ul>\n<p>The installation of Vim is discussed in the next section.<\/p>\n<h2><a id=\"post-21875-_927kxaf5v1cz\"><\/a>How to Install Vim on Ubuntu 22.04?<\/h2>\n<p>Updating the system repository before installing any software\/tools such as Vim Editor ensures a smooth installation process:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> apt update<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"613\" class=\"wp-image-21877\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-1.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-1-300x90.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-1-1024x307.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-1-768x230.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-1-1536x460.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>After the system repository is updated, Vim can be installed by running the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> apt <span class=\"kw2\">install<\/span> <span class=\"kw2\">vim<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1178\" class=\"wp-image-21878\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-2.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-2-300x173.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-2-1024x589.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-2-768x442.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-2-1536x884.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>From the below image, it can be seen that Vim is installed successfully:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1103\" class=\"wp-image-21880\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-3.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-3-300x162.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-3-1024x552.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-3-768x414.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-3-1536x827.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<h2><a id=\"post-21875-_cckx23iintxs\"><\/a>How to Exit\/Quit Linux Vim Editor Without Saving Changes in Ubuntu 22.04?<\/h2>\n<p>While editing files, sometimes, it is realized that the changes in the file are not required due to which it is decided to exit the file without saving the changes that were made. For instance, a file \u201c5g.txt\u201d can be accessed using the Vim text editor as:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">vi<\/span> 5g.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"156\" class=\"wp-image-21882\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-4.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-4-300x23.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-4-1024x78.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-4-768x59.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-4-1536x117.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The file \u201c5g.txt\u201d is launched with the Vim text editor:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1224\" class=\"wp-image-21883\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-5.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-5-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-5-1024x612.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-5-768x459.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-5-1536x918.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-5-501x300.png 501w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>Next, some text is inserted in the file by entering \u201cinsert mode\u201d by pressing \u201c<strong>i<\/strong>\u201d and typing text. Later, If it is required to exit the Vim editor without saving the file, we will switch back to command mode by pressing \u201c<strong>Esc<\/strong>\u201d and typing \u201c<strong>:qi<\/strong>\u201d as shown below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1041\" class=\"wp-image-21884\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-6.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-6-300x152.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-6-1024x521.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-6-768x390.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-6-1536x781.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The changes will be discarded and the file will be saved in the previous state. This can be verified by launching the file in the Vim editor:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">vi<\/span> 5g.txt<\/div><\/div>\n<p>The below image shows that the changes are discarded and the file is in a previous state.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1092\" class=\"wp-image-21885\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-7.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-7-300x160.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-7-1024x546.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-7-768x410.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-7-1536x819.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<h2><a id=\"post-21875-_vwi4ezl9toa3\"><\/a>How to Exit\/Quit Linux Vim Editor With Saving Changes in Ubuntu 22.04?<\/h2>\n<p>Most of the time when files are edited, they need to be saved so that data is not lost. A file \u201c5g.txt\u201d can be accessed using the Vim text editor as:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">vi<\/span> 5g.txt<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"156\" class=\"wp-image-21886\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-8.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-8-300x23.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-8-1024x78.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-8-768x59.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-8-1536x117.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1224\" class=\"wp-image-21887\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-9.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-9-300x179.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-9-1024x612.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-9-768x459.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-9-1536x918.png 1536w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-9-501x300.png 501w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The file \u201c5g.txt\u201d is launched with the Vim text editor. Next, some text is inserted in the file by entering the \u201cinsert mode\u201d by pressing \u201c<strong>i<\/strong>\u201d and typing text. The file can be saved and exited by switching to command mode by pressing \u201c<strong>Esc<\/strong>\u201d and type \u201c<strong>:wq<\/strong>\u201d as shown below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1234\" class=\"wp-image-21888\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-10.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-10.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-10-300x181.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-10-1024x617.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-10-768x463.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-10-1536x926.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The changes in the file will be saved in the current state and the edit will be closed. This can be verified by launching the file in the Vim editor:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">vi<\/span> 5g.txt<\/div><\/div>\n<p>From the below image, it can be seen that the edited line is saved in the file.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"1238\" class=\"wp-image-21889\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-11.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-11.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-11-300x181.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-11-1024x619.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-11-768x464.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/10\/word-image-21875-11-1536x929.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<h2><a id=\"post-21875-_k4r3ojha6hv3\"><\/a>Conclusion<\/h2>\n<p><strong>Vim <\/strong>Editor can be exited with or without saving changes by entering \u201c<strong>:wq<\/strong>\u201d and \u201c<strong>:q!<\/strong>\u201d respectively in command mode in Ubuntu 22.04. This article has demonstrated how to exit the Vim text editor without saving changes and with saving changes on Linux\/Ubuntu 22.04 LTS.<\/p>","protected":false},"excerpt":{"rendered":"<p>Vim Editor can be exited with or without saving changes by entering \u201c:wq\u201d and \u201c:q!\u201d respectively in command mode in Ubuntu 22.04.<\/p>","protected":false},"author":110,"featured_media":21881,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-21875","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21875","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\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=21875"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/21875\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/21881"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=21875"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=21875"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=21875"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}