{"id":220107,"date":"2021-04-06T15:00:50","date_gmt":"2021-04-06T12:00:50","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/define-a-great-vim-profile-using-vimrc-cloudsavvy-it\/"},"modified":"2021-04-06T15:00:50","modified_gmt":"2021-04-06T12:00:50","slug":"define-a-great-vim-profile-using-vimrc-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/define-a-great-vim-profile-using-vimrc-cloudsavvy-it\/","title":{"rendered":"#Define a Great Vim Profile Using .vimrc \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a41aed61d8fd\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a41aed61d8fd\" checked aria-label=\"Toggle\" \/><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:\/\/buradabiliyorum.com\/en\/define-a-great-vim-profile-using-vimrc-cloudsavvy-it\/#What_Is_Vim\" >What Is Vim?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/define-a-great-vim-profile-using-vimrc-cloudsavvy-it\/#Defining_a_Great_vimrc_Profile\" >Defining a Great .vimrc Profile<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/define-a-great-vim-profile-using-vimrc-cloudsavvy-it\/#Wrapping_up\" >Wrapping up<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#Define a Great Vim Profile Using .vimrc \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-10514\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/02\/7ae6c4da.png?width=1200&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"650\" height=\"331\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Vim is an advanced text editor for Linux and Unix operating systems. Recently rated the #1 worldwide Linux editor, Vim is open-source and free. This article will show you how to create a great .vimrc profile.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"What_Is_Vim\"><\/span>What Is <i>Vim<\/i>?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>First, if you are new to Vim: welcome! You have just started the great journey of learning one of the worlds best and most convenient editors.<\/p>\n<p><em>Bram Moolenaar<\/em> created Vim, the much loved Linux terminal based editor, in 1991. Vim stands for <i>vi improved<\/i>, and <code>vi<\/code> was the classic old-school text editor for Unix, developed in 1976. Vim\u2019s popularity has increased a lot, and the editor was recently named the #1 worldwide Linux editor by a major Linux forum. Vim is <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>ly also preinstalled as the default editor in many Linux distributions.<\/p>\n<p>Vim allows users to edit files in two sets of modes, the <i>edit<\/i> mode and the <i>command<\/i> mode, if you will, which likely makes navigation in Vim challenging for new users. Users are likely used to being in edit mode in most other popular text editors (OpenOffice writer etc.), but not in command mode. And command mode is the default mode that Vim will start in.<\/p>\n<p>To give an example, if you open a file with Vim (using a command on your terminal prompt like <code>vi my_story.txt<\/code>), you will enter Vim in command mode. You can now type the letter <code>i<\/code> (a vi command) to enter edit (or specifically in this case <i>insert<\/i>) mode (<code>-- INSERT --<\/code> will usually <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>ear on the last line of the terminal to highlight the mode you are in) and start typing your test. When you\u2019re done, you press <code>ESC<\/code> (the escape key) to return to command mode.<\/p>\n<p>You can then again re-enter edit mode by for example tying <code>a<\/code> (another vi command) to enter edit mode again (<code>a<\/code> in this case stands for <i>append<\/i> and the cursor will jump one character to the right when entering edit mode using <code>a<\/code> instead of <code>i<\/code>). When done with editing (which allows full editing capabilities like pressing <code>cursor up\/down<\/code>, <code>cursor left\/right<\/code> etc.) you can again press the <code>ESC<\/code> key to return to command mode.<\/p>\n<p>When you\u2019re done with editing the file in total, make sure you are in command mode (press the <code>ESC<\/code> key again to be sure if you like) and type the key sequence <code>:wq!<\/code>. This will write (<code>w<\/code>) the file and quit (<code>q<\/code>). If you have never used Vim before, then well done! This was your first Vim session \ud83d\ude09<\/p>\n<p>The Vim editor is one of the few editors with such a sharp initial learning curve. However, after the initial learning curve, the knowledge of editor commands and usage continues to grow with a person over time in a more or less linear format. I write all of my scripts, articles and data wrangling in Vim, using it in only in combination with AutoKey to readily insert my template and HTML tags where needed.<\/p>\n<p>If you would like to learn more about AutoKey, you may like to read our AutoKey: How to Replace Characters with Predefined Text Automatically in Linux article.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Defining_a_Great_vimrc_Profile\"><\/span>Defining a Great .vimrc Profile<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you have previously used Vim in various Linux distributions, you may have noticed how some distributions seem to fail setting up a correct Vim profile, leading to somewhat odd behavior when using Vim.<\/p>\n<p>One of the things you may see (specifically on Mint 19 and some older Ubuntu versions) is that when you press <i>cursor right<\/i> you have to press another key for the cursor to actually jump, and this especially around highlighted\/colored syntax (in shell scripts for example). Another oddity is strange behavior from mouse clicks, or when using tabs.<\/p>\n<p>If you see any of these, or similar oddities, it\u2019s really time to setup a great default .vimrc profile. The .vimrc file\/profile contains all settings that Vim will read and use each time it starts. Over the years of using Vim, and especially around the time I logged a bug for one of these odd behavior items, I made a short .vimrc profile which negates these issues.<\/p>\n<p>The <code>.vimrc<\/code> file will and should be stored in your home directory. Let\u2019s create the file using <code>vim<\/code> itself. Note that you can generally use <code>vi<\/code> to start <code>vim<\/code>. First, we open the <code>.vimrc<\/code> file in our home directory (which in Linux is represented by the <i>tilde<\/i>, i.e. <code>~<\/code>, symbol) by executing:<\/p>\n<pre>vi ~\/.vimrc&#13;\n<\/pre>\n<p>At the command line. This should bring up the <i>Vim<\/i> editor. Now press the <code>i<\/code> key to enter edit\/insert mode. One you see <code>-- INSERT --<\/code> on the last line of your terminal (shown in most cases) you know you are insert mode. Then copy and paste the block of text below, and right-click with your mouse in the terminal window where <i>Vim<\/i> is running. Then click <i>Paste<\/i>.<\/p>\n<pre>set nocompatible&#13;\ncolo torte&#13;\nsyntax on&#13;\nset tabstop     =2&#13;\nset softtabstop =2&#13;\nset shiftwidth  =2&#13;\nset expandtab&#13;\n<\/pre>\n<p>You should now see a screen similar to the following:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-9885\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/02\/441536d1.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"A solid basic .vimrc profile template\" width=\"484\" height=\"275\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>If you generally use four spaces instead of two (for your coding work), then simply replace all <code>=2<\/code> by <code>=4<\/code>.<\/p>\n<p>Now press <code>ESC<\/code> to leave edit mode, and next type the key sequence seen earlier: <code>:wq!<\/code>. This will write out the file <code>~\/.vimrc<\/code> and exit the <i>Vim<\/i> editor. If you would like to verify the contents of the file, you can execute <code>cat ~\/.vimrc<\/code> at the command line.<\/p>\n<p>The next time you enter <i>Vim<\/i>, all these settings will automatically be loaded by Vim from your <code>~\/.vimrc<\/code> file.<\/p>\n<p>Besides setting a nice color scheme using the command <code>colo torte<\/code>, we also turn on syntax highlighting with <code>syntax on<\/code>. We set some better tab width handling options (generally indicating we want two, or four as described above, spaces as tabs).<\/p>\n<p>Please note that the<code>torte<\/code> color scheme does not seem to be available on Linux Mint 20.1, though it is available on some earlier Mint releases. If this is applicable to your system, you will receive a message to the same effect. Simply press enter and edit<code>~\/.vimrc<\/code> to remove this line.<\/p>\n<p>The <code>set expandtab<\/code> option specifically ensures that whenever we press <i>tab<\/i> it will be automatically translated to spaces instead. You can remove this line if you do not like this (tip: use <i>Vim<\/i> to do so and you can press <code>dd<\/code> on a line, whilst in edit mode, to delete the entire line, even without entering edit mode).<\/p>\n<p>However, the most important option is the one on the first line. The <code>set nocompatible<\/code> ensures that a number of things \u2013 like the ones described above \u2013 work much better and without unclear behavior.<\/p>\n<p>There is some discussion online about the perceived need to not set this option because this setting is deemed to be auto-enabled as soon as a .vimrc file is being used, however setting it will ensure this setting is active, and there is no negative side effect to setting it [again]. In other words, there is a potential upside to define it hard coded\/statically whereas there is no downside to doing so.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Wrapping_up\"><\/span>Wrapping up<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>This article placed Vim and Vi in historical context and described it\u2019s popularity. After this we provided a small introduction to the edit and command modes in Vim and looked at creating a <code>~\/.vimrc<\/code> settings file for Vim which will ensure a much improved Vim user experience by reconfiguring tab widths, space settings, syntax highlighting, setting a color scheme and finally and most importantly avoiding buggy\/unclear Vim behavior on various Linux distributions.<\/p>\n<p><strong>Enjoy!<\/strong>\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/9884\/define-a-great-vim-profile-using-vimrc\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#Define a Great Vim Profile Using .vimrc \u2013 CloudSavvy IT&#8221; Vim is an advanced text editor for Linux and Unix operating systems. Recently rated the #1 worldwide Linux editor, Vim is open-source and free. This article will show you how to create a great .vimrc profile. What Is Vim? First, if you are new to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":220108,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/02\/7ae6c4da.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-220107","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/220107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=220107"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/220107\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/220108"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=220107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=220107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=220107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}