{"id":794,"date":"2021-06-14T20:39:28","date_gmt":"2021-06-14T15:09:28","guid":{"rendered":"https:\/\/openapex.org\/spaces\/software\/?p=794"},"modified":"2025-07-07T17:24:24","modified_gmt":"2025-07-07T11:54:24","slug":"work-with-vi-editor-like-a-pro","status":"publish","type":"post","link":"https:\/\/mutesoft.com\/spaces\/software\/work-with-vi-editor-like-a-pro.html","title":{"rendered":"Work With vi Editor Like a Pro"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_79_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/mutesoft.com\/spaces\/software\/work-with-vi-editor-like-a-pro.html\/#1_vi_Editor\" >1. vi Editor<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/mutesoft.com\/spaces\/software\/work-with-vi-editor-like-a-pro.html\/#2_Modes\" >2. Modes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/mutesoft.com\/spaces\/software\/work-with-vi-editor-like-a-pro.html\/#3_Commands\" >3. Commands<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"1-vi-editor\"><span class=\"ez-toc-section\" id=\"1_vi_Editor\"><\/span>1. vi Editor<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In the 90s, when visual editors were introduced, the popularity of command-line editing tools like the <strong>vi<\/strong> editor started declining. Then in the first decade of this century came the IDEs (Integrated Development Environment). Eclipse made IDE attractive and popular among developers. Developers of the current generation prefer an IDE to plain visual text editors and most of them do not even know about the existence of the <strong>vi<\/strong> editor. However, people working in system engineering in Linux and Mac still prefer <strong>vi<\/strong>. In this article, I&#8217;ll highlight 20 commands when practiced, will enable you to use the <strong>vi<\/strong> editor like a pro.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1008\" height=\"630\" src=\"https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/01\/vi-editor.png\" alt=\"vi editor on Mac\" class=\"wp-image-881\" style=\"width:1200px\" srcset=\"https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/01\/vi-editor.png 1008w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/01\/vi-editor-300x188.png 300w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/01\/vi-editor-768x480.png 768w\" sizes=\"auto, (max-width: 1008px) 100vw, 1008px\" \/><figcaption class=\"wp-element-caption\">vi editor on Mac<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"2-modes\"><span class=\"ez-toc-section\" id=\"2_Modes\"><\/span>2. Modes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The improved version of the <strong>vi<\/strong> editor is <strong>vim<\/strong> (vi improved). All the <strong>vi<\/strong> commands are supported by <strong>vim<\/strong> as well. There are two modes in the <code>vi<\/code> editor:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Command mode &#8211; This mode allows to perform tasks like cut, copy, paste, delete, undo, redo, etc.<\/li>\n\n\n\n<li>Insert mode &#8211; In this mode, it directly adds texts to the file.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"3-commands\"><span class=\"ez-toc-section\" id=\"3_Commands\"><\/span>3. Commands<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>To open a file in <strong>vi<\/strong>, use the command <code>vi file_name<\/code>.<\/p>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-stripes\"><table><thead><tr><th>SL#<\/th><th>Purpose<\/th><th>Command<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Switch Mode<\/td><td><code>Esc<\/code> to switch to command mode<br><code>i<\/code> to switch to insert mode and add characters before the current position<br><code>I<\/code> to switch to insert mode but move the cursor to the beginning of the line<br><code>a<\/code> to switch to insert mode and add characters after the current position<br><code>A<\/code> to switch to insert mode but move the cursor to the end of the line<\/td><\/tr><tr><td>2<\/td><td>Go to Line<\/td><td><code>G<\/code> to go to the last line<br><code>gg<\/code> to go to the first line<br><code>nG<\/code> to go to the nth line. Example: <code>120G<\/code><br><code>:line_number<\/code> to go to a specific line. Example: <code>:120<\/code><\/td><\/tr><tr><td>3<\/td><td>Undo and Redo<\/td><td><code>u<\/code> or <code>:u<\/code> or <code>:undo<\/code> for undoing the last change<br><code>.<\/code> to repeat the last undo operation<br><code>:Nu<\/code> for undoing last <code>N<\/code> changes. Example:  <code>:2u<\/code><br>Ctrl + r for redoing the last change<\/td><\/tr><tr><td>4<\/td><td>Move<\/td><td><code>hjkl<\/code> to move left, down, up, and right<br><code>w<\/code> to move one word forward <br><code>b<\/code> to move one word backward<br><code>0<\/code> to move to the beginning of the line <br><code>$<\/code> to move to the end of the line<br><code>H<\/code> to move to the top of the screen<br><code>M<\/code> to move to the middle of the screen<br>L to move to the bottom of the screen<br><code>Ctrl + f<\/code> for page down<br><code>Ctrl + b<\/code> for page up<\/td><\/tr><tr><td>5<\/td><td>Copy and Paste<\/td><td><code>yy<\/code> or <code>Y<\/code> to copy the current line to the clipboard<br><code>Nyy<\/code> to copy N lines to the clipboard. Example: <code>10yy<\/code><br><code>yw<\/code> to copy the current word. Example: <code>2yw<\/code> or <code>y2w<\/code><br><code>yl<\/code> to copy the current letter<br><code>p<\/code> to paste clipboard contents after the current line<br><code>P<\/code> to paste clipboard contents before the current line<\/td><\/tr><tr><td>6<\/td><td>Delete<\/td><td><code>x<\/code> to delete the character at the current cursor position<br><code>X<\/code> to delete the character before the current cursor position<br><code>dw<\/code> to delete one word<br><code>dd<\/code> to delete the current line<br><code>d$<\/code> or <code>D<\/code> to delete from the current position to the end of the line<br><code>d^<\/code> to delete from the current position to the beginning of the line<\/td><\/tr><tr><td>7<\/td><td>Add a line<\/td><td><code>o<\/code> to add a line after the current line <br><code>O<\/code> to add a line before the current line<\/td><\/tr><tr><td>8<\/td><td>Find and Replace<\/td><td><code>\/search_text<\/code> for search forward <br><code>?search_text<\/code> for search backward<br><code>n<\/code> repeats the last search in the forward direction <br><code>N<\/code> repeats the last search in the backward direction<br><code>:s\/search_text\/replace_text<\/code> to replace the first occurrence of <code>search_text<\/code> by <code>replace_text<\/code><br><code>:s\/search_text\/replace_text\/g<\/code> to replace all occurrences of <code>search_text<\/code> by <code>replace_text<\/code> in the current line<br><meta http-equiv=\"content-type\" content=\"text\/html; charset=utf-8\"><code>:%s\/search_text\/replace_text\/g<\/code> to replace all occurrence of <code>search_text<\/code> by <code>replace_text<\/code> in the entire file<\/td><\/tr><tr><td>9<\/td><td>Save and Quit<\/td><td><code>:w<\/code> to save<br><code>:q<\/code> to quit<br><code>!<\/code> to force either saving or exiting<br><code>:wq<\/code> to save and quit<br><code>:q!<\/code> to force quit without saving<\/td><\/tr><tr><td>10<\/td><td>Match Brackets<\/td><td><code>%<\/code> to match brackets <code>(<\/code> with <code>)<\/code> and <code>{<\/code> with <code>}<\/code><\/td><\/tr><tr><td>11<\/td><td>Shift<\/td><td><code>&lt;&lt;<\/code> Shifts line left<br><code>&gt;&gt;<\/code> Shifts line right<\/td><\/tr><tr><td>12<\/td><td>Options<\/td><td><code>:set option<\/code> to set an option<br><code>:set number<\/code> or <code>:set nu<\/code> to show line numbers<br><code>:set autoindent<\/code> for automatic line indentation<br><code>:set showmatch<\/code> to show bracket matches <code>(<\/code> with <code>)<\/code> and <code>{<\/code> with <code>}<\/code><br><code>:set autowrite<\/code> to write before quit<br><code>:set cursorline<\/code> to highlight the current line<br><code>:set hlsearch<\/code> to highlight the searched text<\/td><\/tr><tr><td>13<\/td><td>Configuration<\/td><td>To permanently configure options open <code>vi ~\/.vimrc<\/code> and add one or more lines to it:<br><code>syntax on<\/code> for syntax highlighting<br><code>:set number<\/code> to show line numbers<br>Set other options mentioned in #12 as needed.<\/td><\/tr><tr><td>14<\/td><td>Reload<\/td><td><code>:e<\/code> to reload the file<\/td><\/tr><\/tbody><\/table><figcaption class=\"wp-element-caption\">vi top commands<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>People working in system engineering in Linux and Mac still prefer vi. In this article, I&#8217;ll highlight 20 commands when practiced, will enable you to use the vi editor like a pro.<\/p>\n","protected":false},"author":2,"featured_media":881,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"6","_seopress_titles_title":"","_seopress_titles_desc":"People working in system engineering in Linux and Mac still prefer vi. In this article, I&#039;ll highlight 20 commands when practiced, will enable you to use the vi editor like a pro.","_seopress_robots_index":"","_vp_format_video_url":"","_vp_image_focal_point":[],"footnotes":""},"categories":[6,32],"tags":[46,47,44,42,45,43],"class_list":["post-794","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming","category-tools","tag-top-vi-commands","tag-top-vim-commands","tag-vi-commands","tag-vi-editor","tag-vim-commands","tag-vim-editor"],"_links":{"self":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/comments?post=794"}],"version-history":[{"count":26,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/794\/revisions"}],"predecessor-version":[{"id":1625,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/794\/revisions\/1625"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media\/881"}],"wp:attachment":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media?parent=794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/categories?post=794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/tags?post=794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}