<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Enrique Domínguez on Medium]]></title>
        <description><![CDATA[Stories by Enrique Domínguez on Medium]]></description>
        <link>https://medium.com/@edominguez.se?source=rss-270e861d6b04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*rMeNhNKutQgxUsco2zd5kg.jpeg</url>
            <title>Stories by Enrique Domínguez on Medium</title>
            <link>https://medium.com/@edominguez.se?source=rss-270e861d6b04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 06:30:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@edominguez.se/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[NeoVim from scratch in 2025]]></title>
            <link>https://medium.com/@edominguez.se/so-i-switched-to-neovim-in-2025-163b85aa0935?source=rss-270e861d6b04------2</link>
            <guid isPermaLink="false">https://medium.com/p/163b85aa0935</guid>
            <category><![CDATA[text-editor]]></category>
            <category><![CDATA[vim]]></category>
            <category><![CDATA[neovim]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Enrique Domínguez]]></dc:creator>
            <pubDate>Thu, 27 Mar 2025 04:24:43 GMT</pubDate>
            <atom:updated>2026-02-06T07:24:06.770Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s me, <strong>rebuilding my config from scratch</strong>. I’ll only be assuming you’re familiar with basics.</p><h4>— EDIT — <br>I had to move to WSL and spent some time tinkering further with my config. (FEB 2026)</h4><p>I use Mason for installing the LSP servers, and manage each config individaully in a root `lsp/` directory. Furthermore I updated TreeSitter only to realize the newest version has breaking changes.</p><p>Here’s <a href="https://github.com/kikedose/dotfiles">my dotfiles repo</a>, the README.md documents the TreeSitter dependencies and you can check the LSP-related file structure.</p><figure><img alt="NeoVim final look" src="https://cdn-images-1.medium.com/max/1024/1*FEEO4DweeCHL5QvDYdGRHg.png" /></figure><h3>Installation</h3><p>If you’re on Mac, I recommend using <a href="https://brew.sh/">Homebrew</a> to manage your packages via terminal; once installed, just run brew install neovim and it’ll take care of its dependencies as well.</p><p>If you’re on Linux, you probably know your way around. Just in case, your distro comes with a package manager already (usually), and you simply need to sudo apt-get install neovim or similar.</p><p>If you’re on Windows, I actually recommend to run all your code-related stuff on WSL (pronounced <em>“weasel”</em>). Even if you don’t end up liking NeoVim, just code . and VSCode will open your current directory and automatically install the necessary plugins to work on a Linux environment. Forget about GitBash, you’ll have proper Bash. Hell, you can have ZSH if you want. But that’s a story for another day.</p><h3>First Steps</h3><p>From now on I’ll asume we’re all on a UNIX-based environment. Your config files will go into ~/.config/nvim.</p><p>Your basic folder structure:</p><pre>(~/.config/nvim)<br><br>.<br>├─ after/<br>├─ init.lua<br>└─ lua/<br>   └─ [your-custom-name]/<br>       ├─ init.lua<br>       | ...<br></pre><p>I guess you could throw all into your root ./init.lua file. I prefer having everything split into files and folders, and all that goes into ./lua/[your-custom-name]/... . I’ll let you research what the ./after/ directory does.</p><p>I used nconf for your-custom-name because sometimes I’m of a peculiar lack of imagination. My root ./init.lua is a one-liner that requires that folder. Note how the /lua/ part of the path is inferred:</p><pre>-- ~/.config/nvim/init.lua<br><br>require(&quot;nconf&quot;)</pre><p>And now, everything under ./lua/nconf/... will be loaded when initializing NeoVim. Remember, you don’t have yo use “nconf”, you can use whatever name pleases you. You can have multiple directories at this level if you deem it necessary, just remember to require them all. I actually do it further down the path.</p><p>Now, this is my ./lua/nconf/init.lua :</p><pre>-- ~/.config/nvim/lua/nconf/init.lua<br><br>vim.g.mapleader = &quot; &quot;<br><br>require(&quot;nconf.lazy_init&quot;)<br>require(&quot;nconf.set&quot;)<br>require(&quot;nconf.remap&quot;)</pre><p>I was told to set my leader key before loading any plugins and I did literally so. I told you, sometimes I’m not very imaginative, and if you know of a better place to set it let me know in the comments. The first line calls the vim API, the g globals, and then mapleader maps the leader key to the spacebar &quot; &quot;. This means I can later on set custom commands using spacebar + keystrokes that won’t overlap with the defaults.</p><p>In the following lines I call for three different files: lazy_init.lua , set.lua and remap.lua. lazy_init is all the plugin manager config (Lazy is my plugin manager of choice), and it comes with its own /lazy folder where I have a file for each plugin. We’ll do that one last. set has all my classic Vim settings translated to Lua. And remap is self-explanatory. Let’s get on with those. And for the last time, remember you can name things however it pleases you.</p><p>Here’s the directory tree so far:</p><pre>(~/.config/nvim)<br>.<br>├── after/<br>│   └── ...<br>├── init.lua<br>└── lua/<br>    └── nconf<br>        ├── init.lua<br>        ├── lazy/<br>        │   ├── ...<br>        ├── lazy_init.lua<br>        ├── remap.lua<br>        └── set.lua</pre><h4>set.lua</h4><p>NeoVim <em>can</em> read good ol’ VimScript config. Mostly for consistency, I’m doing it all in Lua. I called it “set” because of, once more, my lack of imagination: in VimScript one would set relativenumber. In Lua you vim.opt.relativenumber = true , you call the vim API, the opt options table, and lastly the setting which usually takes the same name as in Vim config.</p><pre>-- (./lua/nconf/set.lua)<br><br>vim.opt.tabstop = 2<br>vim.opt.softtabstop = 2<br>vim.opt.shiftwidth = 2<br>vim.opt.expandtab = true<br>vim.opt.autoindent = true<br>vim.opt.smartindent = true<br>vim.opt.smarttab = true<br>vim.opt.list = true<br>vim.opt.listchars = &quot;eol:.,tab:&gt;-,trail:~,extends:&gt;,precedes:&lt;&quot;<br><br>vim.opt.number = true<br>vim.opt.relativenumber = true<br>vim.opt.cursorline = true<br>vim.opt.signcolumn = &quot;yes:1&quot;<br>vim.opt.scrolloff = 8<br>vim.opt.showcmd = true<br><br>vim.opt.swapfile = false<br>vim.opt.backup = false<br>vim.opt.undodir = os.getenv(&quot;HOME&quot;) .. &quot;/.config/nvim/undodir&quot;<br>vim.opt.undofile = true<br>vim.opt.clipboard = &quot;unnamed&quot;<br><br>vim.opt.hlsearch = true<br>vim.opt.incsearch = true<br>vim.opt.ignorecase = true<br>vim.opt.smartcase =true<br><br>vim.opt.termguicolors = true<br><br>vim.opt.showmode = false<br><br>-- No automatic comment insertion<br>vim.cmd([[autocmd FileType * set formatoptions-=ro]])</pre><p>Piece of advice, turn off the relatives numbers :set nornu when you’re sharing your screen with a colleague. Most people don’t use them and it muddies communication. Turn them back on with :set rnu.</p><p>If you want a line by line breakdown you can always refer to my 2021 <a href="https://medium.com/@edominguez.se/vim-101-a-comprehensive-guide-to-using-vim-like-an-ide-1-3-vimrc-d484cc41fc2">Vim article</a>, my basic settings haven’t changed much. Keep in mind you can always look up :h expandtab or whatever setting you need help with.</p><p>Remember to actually manually create the “undodir” and specify the path if you create it elsewhere.</p><h4>remap.lua</h4><pre>-- (~/.config/nvim/lua/nconf/remap.lua)<br><br>vim.keymap.set(&quot;v&quot;, &quot;J&quot;, &quot;:m &#39;&gt;+1&lt;CR&gt;gv=gv&quot;)<br>vim.keymap.set(&quot;v&quot;, &quot;K&quot;, &quot;:m &#39;&lt;-2&lt;CR&gt;gv=gv&quot;)<br>vim.keymap.set(&quot;n&quot;, &quot;&lt;leader&gt;s&quot;, [[:%s/\&lt;&lt;C-r&gt;&lt;C-w&gt;\&gt;/&lt;C-r&gt;&lt;C-w&gt;/gI&lt;Left&gt;&lt;Left&gt;&lt;Left&gt;]])<br><br>vim.api.nvim_create_autocmd(&quot;TextYankPost&quot;, {<br>  desc = &quot;Highlights text when yanking&quot;,<br>  group = vim.api.nvim_create_augroup(&quot;kickstart-highlight-yank&quot;, { clear = true }),<br>  callback = function()<br>    vim.highlight.on_yank()<br>  end,<br>})</pre><p>The syntax goes “mode”, where “v” means visual, “n” normal, and so on; then the key you want to remap, for example capital “J”; and then the command or motion you want to map to your key.</p><p>The first two remaps, when you visually select a line, will move it whole one line up or one line down, when pressing capital K or J respectively. The third remap, when in normal mode, allows you to select the word under your cursor and replace it everywhere in your document by pressing leader + s (in my case, spacebar + s) and typing the replacement. Give them a try. Shoutout to <a href="https://x.com/ThePrimeagen">ThePrimeagen</a>, I stole these from him. Make sure to follow him everywhere, he actually knows programing, and you can learn a lot about NeoVim from him.</p><p>The last block isn’t really a remap, but I decided to put it in this file nonetheless. It’s a function that, as stated in its description, highlights whichever text you’re copying. Just a little visual feedback. This one I stole from <a href="https://x.com/teej_dv">TJ DeVries</a>. Also follow him around, I think he’s actually part of the NeoVim development team.</p><h4>lazy_init.lua</h4><p>As I mentioned before, I use <a href="https://github.com/folke/lazy.nvim">Lazy</a> as my plugin manager. As for all the plugins to come, I recommend you to always checkout the docs. There’s more info in there than whatever I might get to explain here.</p><pre>-- (~/.config/nvim/lua/nconf/lazy_init.lua)<br><br>local lazypath = vim.fn.stdpath(&quot;data&quot;) .. &quot;/lazy/lazy.nvim&quot;<br>if not vim.loop.fs_stat(lazypath) then<br>  vim.fn.system({<br>    &quot;git&quot;,<br>    &quot;clone&quot;,<br>    &quot;--filter=blob:none&quot;,<br>    &quot;https://github.com/folke/lazy.nvim.git&quot;,<br>    &quot;--branch=stable&quot;, -- latest stable release<br>    lazypath,<br>  })<br>end<br>vim.opt.rtp:prepend(lazypath)<br><br>require(&quot;lazy&quot;).setup({<br>    spec = &quot;nconf.lazy&quot;,<br>    change_detection = { notify = false }<br>})</pre><p>The first block ensures Lazy is installed. The second block requires the ‘lazy’ plugin and initializes it, then you specify the ~/.config/nvim/lua/nconf/lazy/ directory as an object under ‘spec’ for Lazy to load all files within. I actually made it confusing by also naming it ‘lazy’, but the point is to put all the different plugins in there, to each plugin its own file. Name it however you want and structure this however it pleases you; for instance, the Lazy docs suggest a slightly different setup. Just remember to specify the proper path under the ‘spec’ key.</p><h3>Plugins</h3><pre>(~/.config/nvim)<br>.<br>├── after/<br>│   └── queries/<br>│       └── jsdoc/<br>│           └── highlights.scm<br>├── init.lua<br>├── lazy-lock.json<br>├── lua/<br>│   └── nconf/<br>│       ├── init.lua<br>│       ├── lazy/<br>│       │   ├── autopair.lua<br>│       │   ├── autotag.lua<br>│       │   ├── colorizer.lua<br>│       │   ├── comment.lua<br>│       │   ├── conform.lua<br>│       │   ├── fugitive.lua<br>│       │   ├── indentline.lua<br>│       │   ├── lsp.lua<br>│       │   ├── luasnip.lua<br>│       │   ├── statusline.lua<br>│       │   ├── surround.lua<br>│       │   ├── telescope.lua<br>│       │   ├── theme.lua<br>│       │   └── treesitter.lua<br>│       ├── lazy_init.lua<br>│       ├── remap.lua<br>│       ├── set.lua<br>│       └── snippets/<br>│           └── all.lua<br>└── undodir/<br>    └── ...</pre><p>This is my complete tree. Each file must return a table, i.e. an “associative array” (in Lua they’re simply called tables). Some setups call for all the plugins on a single file, that’s your call. I prefer the multiple file approach. Let’s get on with it.</p><h4>treesitter.lua (OUTDATED)</h4><p>— <br>Breaking changes. Check my dotfiles repo for an updated config (link at the top). The README.md documents the dependencies.<br> —</p><p><a href="https://github.com/nvim-treesitter/nvim-treesitter">nvim-treesitter</a> provides an interface for the TreeSitter parser to run on NeoVim. It gets you <em>much better</em> highlighting, and some other plugins use its functionalities.</p><pre>return {<br>  &quot;nvim-treesitter/nvim-treesitter&quot;,<br>  build = &quot;:TSUpdate&quot;,<br><br>  config = function()<br>    require(&quot;nvim-treesitter.configs&quot;).setup({<br>        ensure_installed = {<br>          &quot;javascript&quot;,<br>          -- The five parsers below should always be installed<br>          &quot;lua&quot;,<br>          &quot;vim&quot;,<br>          &quot;vimdoc&quot;,<br>          &quot;c&quot;,<br>          &quot;query&quot;<br>        },<br>        sync_install = false,<br>        auto_install = true,<br>        highlight = {<br>          enable = true,<br>          additional_vim_regex_highlighting = false,<br>        },<br>        indent = {<br>          enable = true,<br>          disable = { &quot;python&quot;, &quot;c&quot; } -- these and some other langs don&#39;t work well<br>        },<br>      })<br>  end<br>}</pre><p>You caught me, I write JavaScript for a living.</p><p>Upon opening a new file format, TreeSitter downloads the necessary parsers, so you don’t need to overload the “ensure_installed” section. I’m actually not sure of what I just said, so check out the docs and take a look at the commands, for instance :TSInstall jsdoc, and install away any parsers you might need, such as JSDoc. Speaking of which, deep within the after/ directory you might have noticed a little file called highlights.scm with a little query within:</p><pre>;; extends<br>(identifier) @property</pre><p>This one tells TreeSitter to highlight the identifier following the @tag on a JSDoc block. Feel free to extend any functionalities using TreeSitter syntax.</p><h4>telescope.lua</h4><p><a href="https://github.com/nvim-telescope/telescope.nvim">telescope</a> is a heavily extensible fuzzy finder and much more. I actually don’t know if it uses your system <strong>fzf</strong> and <strong>grep</strong> as dependencies, but I recommend having them installed and learning to use them regardless.</p><pre>return {<br>  &quot;nvim-telescope/telescope.nvim&quot;,<br>  tag = &quot;0.1.5&quot;,<br>  dependencies = { &quot;nvim-lua/plenary.nvim&quot; },<br>  module = &quot;telescope&quot;,<br><br>  config = function()<br>    require(&#39;telescope&#39;).setup({})<br><br>    local builtin = require(&#39;telescope.builtin&#39;)<br><br>    vim.keymap.set(&quot;n&quot;, &quot;&lt;leader&gt;fg&quot;, builtin.git_files, {})<br>    vim.keymap.set(&quot;n&quot;, &quot;&lt;leader&gt;fr&quot;, builtin.live_grep, {})<br>    vim.keymap.set(&quot;n&quot;, &quot;&lt;leader&gt;ff&quot;, builtin.find_files, {})<br>    vim.keymap.set(&quot;n&quot;, &quot;&lt;leader&gt;fb&quot;, builtin.buffers, {})<br>    vim.keymap.set(&quot;n&quot;, &quot;&lt;leader&gt;fh&quot;, &quot;:Telescope find_files hidden=true &lt;CR&gt;&quot;)<br><br>    vim.keymap.set(&#39;n&#39;, &#39;&lt;leader&gt;pws&#39;, function()<br>      local word = vim.fn.expand(&quot;&lt;cword&gt;&quot;)<br>      builtin.grep_string({ search = word })<br>    end)<br>    vim.keymap.set(&#39;n&#39;, &#39;&lt;leader&gt;pWs&#39;, function()<br>      local word = vim.fn.expand(&quot;&lt;cWORD&gt;&quot;)<br>      builtin.grep_string({ search = word })<br>    end)<br>  end<br>}</pre><p>Set those remaps to whatever keystrokes you like. What they do, in descending order, is allowing you to browse your git files, an expression within all files, browsing all non-hidden files, switching between buffers… Check out the docs, telescope has some very powerful functions and I’ve seen some surprisingly creative uses of the plugin.</p><h4>lsp.lua (OUTDATED)</h4><p>— <br>I now use Mason to install the LSP servers. I have a dedicated file at the lsp/ directory for each server config. The servers are then initialized down below at lua/config/lsp.lua as to keep things tidy. <a href="https://lsp-zero.netlify.app/blog/lsp-config-without-plugins.html">Check this post for further reference</a>.<br> —</p><p>To be honest, I totally forgot about <a href="https://github.com/williamboman/mason.nvim">Mason</a>. It’s a package manager for all your LSP servers and stuff. Since I did it without Mason, I had to install the servers manually and globally via NPM. If I had to do it again, I’d probably use Mason to be honest.</p><p>I followed the <a href="https://lsp-zero.netlify.app/docs/getting-started.html">LSP Zero</a> guide to set things up. Do check it out! Everything ‘cmp’ related are dependencies for autocompletion. Your LSP suggestions won’t appear on the suggestion list unless you set up a snippets manager, we’ll set up that immediately after.</p><pre>return {<br>  &quot;neovim/nvim-lspconfig&quot;,<br>  version = &quot;*&quot;, -- remove after they fix ESLint<br>  dependencies = {<br>    &quot;hrsh7th/cmp-nvim-lsp&quot;,<br>    &quot;hrsh7th/nvim-cmp&quot;,<br>  },<br><br>  config = function()<br>    local lspconfig_defaults = require(&#39;lspconfig&#39;).util.default_config<br>    lspconfig_defaults.capabilities = vim.tbl_deep_extend(<br>      &#39;force&#39;,<br>      lspconfig_defaults.capabilities,<br>      require(&#39;cmp_nvim_lsp&#39;).default_capabilities()<br>      )<br><br>    vim.api.nvim_create_autocmd(&#39;LspAttach&#39;, {<br>        desc = &#39;LSP actions&#39;,<br>        callback = function(event)<br>          local opts = {buffer = event.buf}<br><br>          vim.keymap.set(&#39;n&#39;, &#39;K&#39;, &#39;&lt;cmd&gt;lua vim.lsp.buf.hover()&lt;cr&gt;&#39;, opts)<br>          vim.keymap.set(&#39;n&#39;, &#39;gd&#39;, &#39;&lt;cmd&gt;lua vim.lsp.buf.definition()&lt;cr&gt;&#39;, opts)<br>          vim.keymap.set(&#39;n&#39;, &#39;gD&#39;, &#39;&lt;cmd&gt;lua vim.lsp.buf.declaration()&lt;cr&gt;&#39;, opts)<br>          vim.keymap.set(&#39;n&#39;, &#39;gi&#39;, &#39;&lt;cmd&gt;lua vim.lsp.buf.implementation()&lt;cr&gt;&#39;, opts)<br>          vim.keymap.set(&#39;n&#39;, &#39;go&#39;, &#39;&lt;cmd&gt;lua vim.lsp.buf.type_definition()&lt;cr&gt;&#39;, opts)<br>          vim.keymap.set(&#39;n&#39;, &#39;gr&#39;, &#39;&lt;cmd&gt;lua vim.lsp.buf.references()&lt;cr&gt;&#39;, opts)<br>          vim.keymap.set(&#39;n&#39;, &#39;gs&#39;, &#39;&lt;cmd&gt;lua vim.lsp.buf.signature_help()&lt;cr&gt;&#39;, opts)<br>          vim.keymap.set(&#39;n&#39;, &#39;&lt;F2&gt;&#39;, &#39;&lt;cmd&gt;lua vim.lsp.buf.rename()&lt;cr&gt;&#39;, opts)<br>          vim.keymap.set({&#39;n&#39;, &#39;x&#39;}, &#39;&lt;F3&gt;&#39;, &#39;&lt;cmd&gt;lua vim.lsp.buf.format({async = true})&lt;cr&gt;&#39;, opts)<br>          vim.keymap.set(&#39;n&#39;, &#39;&lt;F4&gt;&#39;, &#39;&lt;cmd&gt;lua vim.lsp.buf.code_action()&lt;cr&gt;&#39;, opts)<br>        end,<br>      })<br><br>    -----------<br>    -- SERVERS<br>    require&#39;lspconfig&#39;.html.setup{}<br>    require&#39;lspconfig&#39;.cssls.setup{}<br>    require&#39;lspconfig&#39;.jsonls.setup{}<br>    require&#39;lspconfig&#39;.tailwindcss.setup{}<br>    require&#39;lspconfig&#39;.ts_ls.setup{}<br>    require&#39;lspconfig&#39;.eslint.setup{<br>      on_attach = function(client, bufnr)<br>        vim.api.nvim_create_autocmd(&quot;BufWritePre&quot;, {<br>            buffer = bufnr,<br>            command = &quot;EslintFixAll&quot;,<br>          })<br>      end<br>    }<br>    -----------<br><br>    local cmp = require(&#39;cmp&#39;)<br><br>    cmp.setup({<br>      sources = {<br>        {name = &quot;nvim_lsp&quot;},<br>        {name = &quot;luasnip&quot;},<br>      },<br>      snippet = {<br>        expand = function(args)<br>          require(&#39;luasnip&#39;).lsp_expand(args.body)<br>          -- vim.snippet.expand(args.body)<br>        end,<br>      },<br>      preselect = &#39;item&#39;,<br>      completion = {<br>        completeopt = &#39;menu,menuone,noinsert&#39;<br>      },<br>      mapping = cmp.mapping.preset.insert({<br>        [&#39;&lt;CR&gt;&#39;] = cmp.mapping.confirm({select = false}),<br>        -- Jump to the next snippet placeholder<br>        [&#39;&lt;C-f&gt;&#39;] = cmp.mapping(function(fallback)<br>          local luasnip = require(&#39;luasnip&#39;)<br>          if luasnip.locally_jumpable(1) then<br>            luasnip.jump(1)<br>          else<br>            fallback()<br>          end<br>        end, {&#39;i&#39;, &#39;s&#39;}),<br>        -- Jump to the previous snippet placeholder<br>        [&#39;&lt;C-b&gt;&#39;] = cmp.mapping(function(fallback)<br>          local luasnip = require(&#39;luasnip&#39;)<br>          if luasnip.locally_jumpable(-1) then<br>            luasnip.jump(-1)<br>          else<br>            fallback()<br>          end<br>        end, {&#39;i&#39;, &#39;s&#39;}),<br>      }),<br>    })<br>  end<br>}</pre><p>You have some default keymaps up there, tweak them as needed. You also have to explicitly initialize the servers, as I did above, but you’ve got to have them installed beforehand <a href="https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md">from this list</a>. If you have <a href="http://mason.nvim/">mason</a> and <a href="https://github.com/williamboman/mason-lspconfig.nvim">mason-lspconfig</a> installed you would rather do that via the command :LspInstall.</p><p>Then comes the ‘cmp’ autocompletion and suggestions settings. I’m telling it to listen to both the LSP and LusSnip for my custom snippets (more on that later) in the ‘sources’ section. I’m also telling it to use LuaSnip instead of the brand new native snippet manager in the ‘snippet’ section. The ‘preselect’ section <em>preselects</em> the first item on the suggestions list; if you set it to false you’ll have to arrow-down. And lastly, some mappings to expand the suggestion with Return and to jump around the custom snippets.</p><h4>luasnip.lua</h4><pre>return {<br>  {<br>    &quot;L3MON4D3/LuaSnip&quot;,<br>    version = &quot;v2.*&quot;,<br>    build = &quot;make install_jsregexp&quot;,<br><br>    config = function()<br>      require(&quot;luasnip.loaders.from_vscode&quot;).lazy_load()<br>      require(&quot;nconf.snippets.all&quot;)<br>    end,<br>  },<br><br>  {<br>    &#39;saadparwaiz1/cmp_luasnip&#39;,<br>  }<br>}</pre><p>Here we have the initialization of the <a href="https://github.com/L3MON4D3/LuaSnip/">snippets manager</a>. Notice I’m requiring a file within the snippets directory, there I threw ‘all’ my snippets since I only have one: ~/.config/nvim/lua/nconf/snippets/all.lua. You might want to divide them them by language on their own files to keep things tidy. Also notice the ‘cmp_luasnip’ plugin, to <em>plug</em> LuaSnip <em>in</em> cmp’s autocompletion.</p><p>This is my snippet:</p><pre>local ls = require(&quot;luasnip&quot;)<br>local s = ls.snippet<br>local i = ls.insert_node<br>local t = ls.text_node<br>local f = ls.function_node<br><br>ls.add_snippets(&quot;javascriptreact&quot;, {<br>  s(&quot;rfc&quot;, {<br>    t({&quot;export default function &quot;}),<br>    f(function(_, snip) <br>      return snip.env.TM_FILENAME_BASE or &quot;Component&quot;<br>    end, {}),<br>    t({&quot; () {&quot;, &quot;\treturn (&quot;, &quot;\t\t&lt;div&gt;&quot;, &quot;\t\t\t&quot;}),<br>    i(1),<br>    t({&quot;&quot;, &quot;\t\t&lt;/div&gt;&quot;, &quot;\t)&quot;, &quot;}&quot;, &quot;&quot;}),<br>  })<br>})</pre><p>I need to tweak it a little bit, I know I can do better; basically it scaffolds a react functional component on prompt. It’s written in Lua. LuaSnip also reads JSON snippets, but you’ll probably have to tweak the configs.</p><p><a href="https://github.com/rafamadriz/friendly-snippets">This is a collection of snippets</a> you can simply install, but you can always check out <a href="https://github.com/rafamadriz/friendly-snippets/blob/main/snippets/javascript/react-ts.json">any particular snippet in there</a> and translate it to Lua. Try using ChatGPT with the right prompts if you don’t feel like reading the docs, it might actually work.</p><h4>comment.lua</h4><p>Here the only thing out of the ordinary is the ‘ts_context_commentstring’ extra plugin, which I use to get proper comments within JSX’s html-like blocks. If you don’t work with embedded languages, you can delete the pre_hook, the aforementioned plugin, and flatten the table.</p><pre>return {<br>  {<br>    &#39;numToStr/Comment.nvim&#39;,<br><br>    config = function()<br>      require(&#39;Comment&#39;).setup {<br>        pre_hook = require(&#39;ts_context_commentstring.integrations.comment_nvim&#39;).create_pre_hook(),<br>        padding = true,<br>        sticky = true,<br>        ignore = nil,<br>        toggler = {<br>          ---Line-comment toggle keymap<br>          line = &#39;gcc&#39;,<br>          ---Block-comment toggle keymap<br>          block = &#39;gbc&#39;,<br>        },<br>      }<br>    end<br>  },<br><br>  {<br>    &#39;JoosepAlviste/nvim-ts-context-commentstring&#39;,<br><br>    config = function()<br>      require(&#39;ts_context_commentstring&#39;).setup {<br>        enable_autocmd = false,<br>      }<br>    end<br>  }<br>}</pre><h4>conform.lua</h4><p>I’m using <a href="https://github.com/stevearc/conform.nvim">conform</a> to format with Prettier on save. Albeit there are other solutions to the Prettier predicament, I went with this one. I wouldn’t say I recommend it though. I should also create a command to format on demand.</p><pre>return {<br>  &#39;stevearc/conform.nvim&#39;,<br><br>  config = function()<br>    require(&quot;conform&quot;).setup({<br>      formatters_by_ft = {<br>        javascript = { &quot;prettier&quot;, stop_after_first = true },<br>        javascriptreact = { &quot;prettier&quot;, stop_after_first = true },<br>        typescriptreact = { &quot;prettier&quot;, stop_after_first = true },<br>      },<br>    })<br><br>    vim.api.nvim_create_autocmd(&quot;BufWritePre&quot;, {<br>      pattern = &quot;*&quot;,<br>      callback = function(args)<br>        require(&quot;conform&quot;).format({ bufnr = args.buf })<br>      end,<br>    })<br>  end<br>}</pre><p>On the first block I’m setting which formatters I want to use on each filetype. You can actually set up a list of formatters for an individual filetype, and ‘stop_after_first’ makes sense now: it tells conform to only load the first formatter it finds on said list. Since I only have Prettier it’s redundant but I left it there so I don’t forget about it, I’ve been wanting to try other solutions.</p><p>The second block is simply the ‘format on save’ function.</p><h4>autopair.lua</h4><p>When you type “(” you expect an automatic “)” to be inserted. That’s what <a href="https://github.com/altermo/ultimate-autopair.nvim">ultimate-autopair</a> does. As per the docs: “It has features which other auto-pairing plugins lack: multiline support, treesitter-node filtering and treesitter-filetype detection.”</p><pre>return {<br>  &quot;altermo/ultimate-autopair.nvim&quot;,<br>  event = { &quot;InsertEnter&quot; },<br>  config = true,<br>}</pre><h4>autotag.lua</h4><p>Like autopair for html tags.</p><pre>return {<br>  &quot;windwp/nvim-ts-autotag&quot;,<br><br>  config = function()<br>    require(&#39;nvim-ts-autotag&#39;).setup({<br>        opts = {<br>          enable_close = true,<br>          enable_rename = true,<br>          enable_close_on_slash = false,<br>        }<br>      })<br>  end<br>}</pre><h4>indentline.lua</h4><p>Just a visual aid to guide your eyes on indent levels.</p><pre>return {<br>  &quot;lukas-reineke/indent-blankline.nvim&quot;,<br>  main = &quot;ibl&quot;,<br>  opts = {<br>    indent = {<br>      char = {&quot;│&quot;},<br>    },<br>  },<br>}</pre><h4>statusline.lua</h4><p>I use <a href="https://github.com/nvim-lualine/lualine.nvim">LuaLine</a> as my statusline. That’s why I disabled the native “show mode” setting back in the set.lua file. Check out the docs for other customization options, mine is pretty minimal.</p><pre>return {<br>  &#39;nvim-lualine/lualine.nvim&#39;,<br>  dependencies = { &#39;nvim-tree/nvim-web-devicons&#39; },<br><br>  config = function()<br>    require(&#39;lualine&#39;).setup({<br>        theme = &#39;gruvbox&#39;,<br>        options = {<br>          icons_enabled = false,<br>          component_separators = &#39;&#39;,<br>          section_separators = &#39;&#39;,<br>        },<br>        sections = {<br>          lualine_a = { &#39;mode&#39; },<br>          lualine_b = { &#39;branch&#39;, &#39;diff&#39; },<br>          lualine_c = { { &#39;filename&#39;, path = 1 } },<br>          lualine_x = { &#39;diagnostics&#39; },<br>          lualine_y = { &#39;filetype&#39;, &#39;lsp_status&#39; },<br>          lualine_z = { &#39;location&#39; }<br>        },<br>        tabline = {<br>          lualine_a = { &#39;buffers&#39; },<br>          lualine_b = {},<br>          lualine_c = {},<br>          lualine_x = {},<br>          lualine_y = {},<br>          lualine_z = { &#39;tabs&#39; }<br>        },<br>      })<br><br>  end<br>}</pre><h4>theme.lua</h4><p>I use Gruvbox.</p><pre>return {<br>  &quot;ellisonleao/gruvbox.nvim&quot;,<br>  name = &quot;gruvbox&quot;,<br>  priority = 1000,<br>  config = function()<br>    require(&quot;gruvbox&quot;).setup({<br>        terminal_colors = true,<br>        undercurl = true,<br>        underline = false,<br>        bold = true,<br>        italic = {<br>          strings = false,<br>          emphasis = false,<br>          comments = true,<br>          operators = false,<br>          folds = false,<br>        },<br>        strikethrough = true,<br>        invert_selection = false,<br>        invert_signs = false,<br>        invert_tabline = false,<br>        invert_intend_guides = false,<br>        inverse = true, -- invert background for search, diffs, statuslines and errors<br>        contrast = &quot;hard&quot;,<br>        palette_overrides = {},<br>        overrides = {},<br>        dim_inactive = false,<br>        transparent_mode = true,<br>      })<br><br>    vim.cmd.colorscheme(&quot;gruvbox&quot;)<br>  end<br>}</pre><h4>Other Plugins…</h4><p>These two I use: you might want to check out <a href="https://github.com/tpope/vim-fugitive">fugitive</a> for Git actions, and if you work with css/colors you might find <a href="https://github.com/norcalli/nvim-colorizer.lua">colorizer</a> useful.</p><p>I don’t use this one anymore, but you might want some breadcrumbs. Check out <a href="https://github.com/SmiteshP/nvim-navic">navic</a> and <a href="https://github.com/LunarVim/breadcrumbs.nvim">this one</a> on top.</p><p>Also check out <a href="https://github.com/lewis6991/gitsigns.nvim">gitsigns</a> if you actually enjoy having the git blame shown on your current line. It actually does much more, but I never ended up using it.</p><h3>Now what?</h3><p>Check out these two videos if you’re interested in a more in-depth and yet beginner-friendly understanding of NeoVim config. They’re the guys I told you about before.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fw7i4amO_zaE%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dw7i4amO_zaE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fw7i4amO_zaE%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ee427b3457b52bdba8fe8c6c1e7d756/href">https://medium.com/media/8ee427b3457b52bdba8fe8c6c1e7d756/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fm8C0Cq9Uv9o%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dm8C0Cq9Uv9o&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fm8C0Cq9Uv9o%2Fhqdefault.jpg&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/d6e0f393d51192065a482ef5b74e4cfd/href">https://medium.com/media/d6e0f393d51192065a482ef5b74e4cfd/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=163b85aa0935" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set up Vim in 2021? (2/3)]]></title>
            <link>https://medium.com/geekculture/fuzzy-searchhow-to-set-up-vim-in-2021-2-3-b8eae1b77497?source=rss-270e861d6b04------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8eae1b77497</guid>
            <category><![CDATA[ide]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[vim]]></category>
            <dc:creator><![CDATA[Enrique Domínguez]]></dc:creator>
            <pubDate>Mon, 08 Nov 2021 23:01:52 GMT</pubDate>
            <atom:updated>2021-11-11T16:08:22.796Z</atom:updated>
            <content:encoded><![CDATA[<h3>A comprehensive guide to setting up Vim like an IDE Part 2: plugins</h3><p><em>This is part of a series aimed at teaching you the vim fundamentals. </em><a href="https://medium.com/@edominguez.se/vim-101-a-comprehensive-guide-to-using-vim-like-an-ide-1-3-vimrc-d484cc41fc2"><em>Part one is about my .vimrc configurations</em></a><em>. Part two is all about the plugins. Part three will be about navigating Vim like a pro.</em></p><p><em>I’m writing these articles for the Vim newbie I once was. But even as of yesterday I’m still learning new things about Vim, so who knows, stay awhile and listen!</em></p><h4>It’s plugin time</h4><figure><img alt="Plugins everywhere meme" src="https://cdn-images-1.medium.com/max/550/1*1YGkXni1kUcyj6iG1Nvusw.jpeg" /><figcaption>Everywhere indeed</figcaption></figure><p>I might as well refer you to the most upvoted comment of <a href="https://www.reddit.com/r/vim/comments/bfxr2z/vim_theory_and_reflections/">this post</a>, but my point is you definitely <strong>should</strong> try all the plugins and configurations that get your attention. As time goes by, you’ll find yourself deleting more and more plugins as you come to the realization you no longer need them, or even worse, you never really used them in the first place.</p><p>This is my selection of plugins, one year into the vimworld. Same as before, if you just wanna look a it and move on, here it is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/267ee5fa90f7e272da0f2e43927dcb06/href">https://medium.com/media/267ee5fa90f7e272da0f2e43927dcb06/href</a></iframe><p>I’ll link the configs at the end. Now, let’s break it down.</p><h4><a href="https://github.com/junegunn/vim-plug">Plug</a></h4><p>First things first: let’s get you a plugin manager. <em>Do you need one</em>? No, not really. You can always manage your plugins by hand, and I’d argue a plugin manager merely simplifies the process of cloning the git repository into the right folder, keeping it updated, cleaning unused plugins, etc. That’s it. Now, <em>do you want one</em>? Yes you do. It’s about quality of life. There are many things I like doing by hand, since I hate handing over control just for the sake of convenience, but there’s nothing magical going on behind the curtains. This is a thing I don’t even wanna think about doing by hand.</p><figure><img alt="Plugin manager updating packages" src="https://cdn-images-1.medium.com/max/785/1*i_H-54YmDnBjqyfeYcfUdA.gif" /><figcaption>I mean, look at this… of course you want one.</figcaption></figure><p>You can find everything you need to know about plug in their <a href="https://github.com/junegunn/vim-plug">git repo</a>, from installation to automation and commands. I can give you a TL;DR for <em>Vim on unix-like systems</em>. Not Neovim, not Windows. All that info is in <a href="https://github.com/junegunn/vim-plug">their repo</a>.</p><p>Open your favorite terminal emulator and curl that mofo:</p><pre>curl -fLo ~/.vim/autoload/plug.vim --create-dirs \<br>    <a href="https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim">https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim</a></pre><p>Basically you’re creating a folder called autoload/ inside your $HOME/.vim/ directory, and downloading plug.vim from GitHub into that folder.</p><p>Then, you only have to add a call plug#begin() and a call plug#end() to your .vimrc and add the plugins you want to install in between those sections. Refer to my gist up above. When you’re done, save, reload and :PlugInstall away.</p><p>You can notice I specified a path on the plug#begin() section, like so:</p><pre>call plug#begin(<strong>&#39;~/.vim/plugged&#39;</strong>)</pre><p>That’s where the plugins will get installed. You can name it whatever you want, but as per the documentation, you should avoid using standard Vim directory names like ‘plugin’.</p><p>Oh, and why <strong>plug</strong> and not, say, <a href="https://github.com/VundleVim/Vundle.vim"><strong>vundle</strong></a>? I used vundle at first, then switched to plug because I heard it hasn’t been actively maintained for years. Honestly I never had a problem with vundle. But well, here we are.</p><h4><a href="https://github.com/morhetz/gruvbox">Grubvox</a></h4><p>Gruvbox is a beautiful theme with a retro look. It was love at first sight and I can’t see myself using any other theme in the foreseeable future.</p><figure><img alt="Gruvbox colors in terminal emulator" src="https://cdn-images-1.medium.com/max/1024/1*Nfo-Hc1_X-RrzO6soT9hlw.png" /><figcaption>I even set my terminal colors to match Gruvbox</figcaption></figure><p>Maybe you’re a <a href="https://github.com/dracula/vim">Dracula</a> person. It doesn’t matter, the logic is all the same, but I’ll be discussing a few tweaks that may or may not be particular to gruvbox so it’s a good idea to keep them in mind. Remember these settings from Part 1?</p><pre>set termguicolors<br>let g:gruvbox_italic=1<br>colorscheme gruvbox<br>set background=dark<br>hi Normal guibg=NONE ctermbg=NONE<br>let g:terminal_ansi_colors = [<br>    \ &#39;#282828&#39;, &#39;#cc241d&#39;, &#39;#98971a&#39;, &#39;#d79921&#39;,<br>    \ &#39;#458588&#39;, &#39;#b16286&#39;, &#39;#689d6a&#39;, &#39;#a89984&#39;,<br>    \ &#39;#928374&#39;, &#39;#fb4934&#39;, &#39;#b8bb26&#39;, &#39;#fabd2f&#39;,<br>    \ &#39;#83a598&#39;, &#39;#d3869b&#39;, &#39;#8ec07c&#39;, &#39;#ebdbb2&#39;,<br>\]</pre><p>truecolor is a specification for 24-bit color values for your pixels. It amounts to 16,777,216 possible colors; that’s a couple more than the 256 possible colors from 8-bit. You should check if your terminal supports truecolor by running echo $COLORTERM, and performing the tests suggested in <a href="https://github.com/termstandard/colors">this repo</a>. If your terminal supports truecolor, then we can safely set <strong>termguicolors</strong> in our .vimrc to enable 24-bit colors in Vim. Believe or not, I unknowingly spent almost a year without termguicolors, it felt like I’d been living in a lie all that time.</p><figure><img alt="24-bit color support on and off" src="https://cdn-images-1.medium.com/max/1024/1*cXyHC7hWS4lWRmrh6zyCvw.png" /><figcaption>It’s night and day</figcaption></figure><p>Note that if you’re not using Vim from the terminal but rather from a GUI, you probably don’t need to mingle with the colors.</p><p>To enforce italics, you must declare the variable<strong>let g:gruvbox_italic=1</strong> <em>before</em> calling <strong>colorscheme gruvbox </strong>or else they might not work. <strong>background=dark </strong>sets gruvbox’s dark theme, as opposed to background=light. Give it a try if you want but my eyes can’t stand it, light themes on text editors bring back painful memories of some old <em>macromedia </em>dreamweaver version.</p><p><strong>hi Normal guibg=NONE ctermbg=NONE </strong>sets the vim editor and vim terminal backgrounds to none , rendering them transparent, as seen on my screenshots. The slightly translucent background is actually my terminal emulator’s, which is set to 95% opacity.</p><p>The array of hex colors assigned to the <strong>terminal_ansi_colors </strong>variable are the vim terminal colors. Since we enabled termguicolors, for some reason the Vim terminal falls back to your system’s default palette, which is definitely not pretty, so we have to set it by hand. And yeah, in case you didn’t know, you can run a terminal inside vim with :term. Check out :help terminal for more info.</p><p>If you didn’t get the termguicolors to work, try :help xterm-true-color where they talk about setting explicitly some settings. If you’re using tmux, you might need to also set it up accordingly.</p><p><a href="https://vimcolorschemes.com/top">Check this site out for more themes</a>.</p><h4><a href="https://github.com/preservim/nerdtree">NerdTree</a></h4><figure><img alt="NerdTree file system explorer" src="https://cdn-images-1.medium.com/max/787/1*ASoy46ZWS56k5HiNONr2Fg.gif" /><figcaption>NerdTree file system explorer</figcaption></figure><p>There’s not much to say here. You need a file system explorer on an IDE. Some might argue you don’t need NerdTree since you can achieve the same results with the native Vim explorer, try :Explore or :Vexplore for a vertical split. Check <a href="https://vonheikemen.github.io/devlog/tools/using-netrw-vim-builtin-file-explorer/">this</a> article out. Decide for yourself. <em>Meh</em>.</p><p>NerdTree has a couple of <a href="https://github.com/preservim/nerdtree#nerdtree-plugins">interesting plugins</a> from which I use <em>absolutely none</em>, but you can get icons for your different file formats like on VSCode, or show Git flags, etc. Were you to give NerdTree a try, you should check out the full list of commands by pressing ? within the tree. The ones I use the most are s to open a file in a vertical <strong>split</strong>, t to open a file in a new <strong>tab</strong>, and R to <strong>refresh</strong> the tree and show changes to the directory made outside of Vim.</p><p>Just in case you didn’t know it, you can navigate between splits by hitting control w + direction, w as in window. ^wl goes right, ^wk goes up, and so on. I’m telling you this because not only NerdTree allows you to open splits, but is a split itself: you can navigate back into NedTree with ^wh. The arrows work too. Also, you navigate through tabs with gt and gT to the right and to the left respectively. Yes, Vim support tabs. More on that in Part 3.</p><pre>nnoremap &lt;C-t&gt; :NERDTreeToggle&lt;CR&gt;<br>let NERDTreeShowHidden=1<br>let NERDTreeRespectWildIgnore=1<br>set wildignore+=*.DS_Store,*.min.*<br>autocmd BufWinEnter * silent NERDTreeMirror.</pre><p>The <strong>nnoremap</strong> remaps <strong>^t</strong> (control + t) to toggle the NerdTree on or off. <strong>NERDTreeShowHidden</strong> does exactly what it sounds like, it shows hidden files; I want to be able to access my .env files from within NerdTree, but not the annoying .DS_Store system files. That’s why I enabled <strong>NERDTreeRespectWildIgnore </strong>and set the list to include .DS_Store and any minified .min file. You can make that list grow as needed. The last line with the <strong>autocmf</strong> <strong>BufWinEnter</strong> is telling Vim to open a copy of your current NerdTree whenever you open a new tab, hence the <strong>NERDTreeMirror</strong>.</p><p>There are many more setting examples in their <a href="https://github.com/preservim/nerdtree#frequently-asked-questions">repo</a>, you should check it out.</p><h4><a href="https://github.com/vim-airline/vim-airline">Airline</a></h4><figure><img alt="Airline status bar form Vim" src="https://cdn-images-1.medium.com/max/1024/1*DXFIQve-rbqxGUOADqDqcw.gif" /><figcaption>Airline in action</figcaption></figure><p>Of course, you can always create your own custom status line, like a good self-respecting Vim nerd. Maybe someday I will, but in the meantime…</p><p><a href="https://github.com/vim-airline/vim-airline">Airline</a> is a lightweight status line form Vim. It gives you info on the mode (normal, insert, visual, etc.), the file path, the file format, errors, and the cursor position. It can also handle tabs but I never liked the feel of it.</p><p>If you want something more system-wide, check out <a href="https://github.com/powerline/powerline">Powerline</a>. It’s not a Vim plugin anymore, it’s written in Python and it integrates with tmux, bash, zsh and several other applications.</p><p>You should consider installing and using a <a href="https://github.com/powerline/fonts">Powerline Font</a> or a <a href="https://github.com/ryanoasis/nerd-fonts">Nerd Font</a> for the nice symbols to show up in Airline, albeit it works just fine without.</p><h4><a href="https://github.com/sheerun/vim-polyglot">Polyglot</a></h4><p>Polyglot is an extensive collection of language packs that allow Vim to correctly highlight syntax. Instead of installing different languages as different plugins, just install polyglot once and be done with it. Only one plugin to update, only one line in your .vimrc, and each language pack is loaded automatically on demand so <em>it</em> <em>won’t affect your startup time. </em>Take a look at the list of supported <a href="https://github.com/sheerun/vim-polyglot#language-packs">languages</a>, it’s actually pretty impressive; half of those I’ve never even heard of.</p><p>By the way, Polyglot comes with some pre-configured concealing options. Actually not Polyglot, but each individual language package. Look at this and you’ll get it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FQ5QLIa91RkGLMQYlVG3rA.gif" /><figcaption>You can conceal keywords into single characters</figcaption></figure><p>Behind curtains, it’s doing something like this:</p><pre>syntax match jsFunction function conceal cchar=ƒ<br>syntax match { tag } { keyword } conceal cchar={ character }   </pre><p>Only it does it with a ternary operator that checks your .vimrc to see if you declared the javascript_conceal_function somewhere, and if you did, it assigns its value to the cchar parameter. So all you really have to do is to actually declare this:</p><pre>let g:javascript_conceal_function=&quot;ƒ&quot;</pre><p>You have the full <strong>javascript</strong> list <a href="https://github.com/pangloss/vim-javascript#concealing-characters">here</a>. Remember polyglot is a collection, so if you want language-specific details, check the list in their <a href="https://github.com/sheerun/vim-polyglot#language-packs">repo</a>.</p><p>You can set your custom conceals with that pattern. I’ll let you google the specifics. It can also take regex instead of a keyword, and tag is whatever you name that group of concealed characters. Say you want to conceal &lt;= into ≤ and &gt;= into ≥, you’ll probably tag them both as jsOperatos for example. But that’s beyond the scope of this article.</p><p>Note that this feature might conflict with another plugin, <strong>Indentline</strong>. We’ll discuss more about concealing when we talk about Indentline down below.</p><h4><a href="https://github.com/mattn/emmet-vim">Emmet</a></h4><figure><img alt="Emmet demonstration" src="https://cdn-images-1.medium.com/max/780/1*EFl8sjnM18_jmpQDdEV92g.gif" /></figure><p>If you’ve done some HTML in the past, you probably know emmet. If you haven’t, you’re missing out. Simply put, you must only write one line of instructions and emmet quickly expands it into markup. I’ll leave you the docs <a href="https://docs.emmet.io/abbreviations/syntax/">here</a>.</p><p>It even works with React, automatically inserting className=&quot;&quot; instead of class=&quot;&quot; and so on. If you’re like me and you always add the .jsx extension to React files <em>as one should</em>, you need to add this to your .vimrc to ensure emmet recognizes the file extension:</p><pre>let g:user_emmet_settings = {<br>\  &#39;javascript&#39; : {<br>\      &#39;extends&#39; : &#39;jsx&#39;,<br>\  },<br>\}</pre><p>The only thing to bare in mind is how one expands the emmet-string in Vim. You must hit <strong>^y,</strong> , that’s control + y + ,. You can remap the ^y to ^z or whatever combination you like, but the <strong>, </strong>is always the final trigger.</p><h4><a href="https://github.com/tpope/vim-commentary">Commentary</a></h4><figure><img alt="Commenting out sections" src="https://cdn-images-1.medium.com/max/780/1*8ieyuE7yZsP4uJQnuxnvtQ.gif" /><figcaption>Easy</figcaption></figure><p>gcc to comment a line, gc to comment visual selection, like on the gif above. Repeat to uncomment.</p><p>gc in <em>Normal</em> mode also takes distance + direction parameters, so for example gc5j will comment your line and five below. Now you understand why we set up the relativenumber in our .vimrc.</p><p>There’s also the <a href="https://github.com/preservim/nerdcommenter">Nerd Commenter</a>, but I haven’t tried it yet.</p><h4><a href="https://github.com/tpope/vim-surround">Surround</a></h4><figure><img alt="Adding and changing surrounding characters with ease" src="https://cdn-images-1.medium.com/max/780/1*d5kVpCfts0_9d-YOcr0gKg.gif" /><figcaption>Surround with ease. Ease is the keyword here.</figcaption></figure><p>Your bread and butter is going to be, in <em>Normal</em> mode, ysw + character. Think of it as “you surround word” with “something”. Just keep in mind that if you enter an opening or a closing brace, it’s gonna behave differently: ysw} is going to surround your word like this {word} as you would expect, but an opening brace ysw{ will give you { word } with inner spaces. The same goes for [, ], (, and ). The w is a distance parameter, so you totally can do stuff like ys5w&#39; and surround five words in single quotes. In <em>Visual </em>mode, make a selection and surround it directly with capital S + character.</p><p>Is your stuff is <em>already</em> surrounded and you want to change or delete it, you cs or ds respectively. Think “change surround this for that” and “delete surrounding character”. For instance, cs&quot;&#39; would change the surrounding double quotes for single quotes, and ds( would delete the surrounding parenthesis altogether. You don’t need to input the distance anymore since you are telling it what to target.</p><p>And what about html tags like &lt;p&gt;...&lt;/p&gt;? You use the t, t as in <em>tag</em>. For example, yswt li &gt; would surround your word in &lt;li&gt;...&lt;/li&gt; tags. When you enter t, Vim expects an input and you tell him you’re done with the closing bracket &gt;. Read the full list of commands in the <a href="https://github.com/tpope/vim-surround">repo</a>.</p><h4><a href="https://github.com/dense-analysis/ale">ALE</a></h4><p>ALE stands for <strong>Asynchronous Lint Engine</strong>. It’s only the engine, not the linter. A linter is a tool that checks your code for errors, bugs and dubious style. ALE integrates effortlessly with many standard services including <a href="https://eslint.org/docs/user-guide/getting-started">ESlint</a> or various <a href="https://microsoft.github.io/language-server-protocol/">LSP</a>s like Microsoft’s tsserver. Remember we enabled a signcolumn in <a href="https://medium.com/@edominguez.se/vim-101-a-comprehensive-guide-to-using-vim-like-an-ide-1-3-vimrc-d484cc41fc2">part 1</a>? That’s where ALE will flag your errors.</p><p>Personally, I use ALE <em>only</em> for ESLint integration. After <a href="https://eslint.org/docs/user-guide/getting-started">installing and <strong>initializing</strong></a> ESLint on your Javasript project with your package manager of choice, ALE will <em>automatically</em> lint your code in real time and flag any mistakes whenever you exit Insert mode. I always use the <a href="https://github.com/airbnb/javascript">Airbnb javascript style rules</a>, but ESLint will prompt you to chose which ever ruleset you prefer upon initialization.</p><figure><img alt="ESLint error flag" src="https://cdn-images-1.medium.com/max/1024/1*Zk9jshRiMRAmp9m1MaVkMg.png" /><figcaption>Error flag and description</figcaption></figure><p>It goes without saying that we don’t want to have to set up ESLint for every single .js file we create. Sometimes we just wanna quickly try some code, and it’s neither worth the time nor the effort to install and configure all the packages, but we would still like some kind of linting. Well, as I said, ALE integrates with the Typescript tsserver to provide you with VSCode-like <a href="https://code.visualstudio.com/docs/editor/intellisense">IntelliSense</a>. That means you don’t only get error flags but also autocompletion, for which ALE provides integration with <a href="https://github.com/Shougo/deoplete.nvim">Deoplete</a>, a plugin that manages the autocompletion list. You can read the details <a href="https://github.com/dense-analysis/ale#2iii-completion">here</a>. But as I said, I <strong>exclusively</strong> use ALE for ESLint because I use <em>another</em> plugin for autocompletion. We’ll talk about in a minute.</p><p>It’s worth noting that ALE can auto-fix your code based on whatever rules you use. We already talked about ESLint, but if you use Prettier (I don’t), ALE can also use it for auto-fixing on save. There’s also a dedicated <a href="https://github.com/prettier/vim-prettier">Prettier plugin for Vim</a>. You have choices. If you’d like to try the autofix feature, you can set up ALE like this in your .vimrc:</p><pre>let g:ale_fixers = {<br>\   &#39;*&#39;: [&#39;remove_trailing_lines&#39;, &#39;trim_whitespace&#39;],<br>\   &#39;javascript&#39;: [&#39;prettier&#39;, &#39;eslint&#39;],<br>\   &#39;javascriptreact&#39;: [&#39;prettier&#39;, &#39;eslint&#39;],<br>\}</pre><p>You can set up the rules manually, or tell ALE to pick them from either eslint, prettier, both, or whatever <a href="https://github.com/dense-analysis/ale/blob/master/supported-tools.md">services you use for your language</a>: you only have to create an array of services for the language in question. To run the auto-fixer just enter the command :ALEFix, or set it up to do it automatically on save like this in your .vimrc:</p><pre>let g:ale_fix_on_save = 1</pre><h4><a href="https://github.com/neoclide/coc.nvim">COC</a></h4><figure><img alt="Autocompletion in action" src="https://cdn-images-1.medium.com/max/1024/1*vYtekHnccfYZYlyCioy7pA.gif" /><figcaption>IntelliSense suggest ‘return’. TabNine correctly infers the module import.</figcaption></figure><p>COC is my preferred autocompletion tool. I already mentioned <a href="https://github.com/Shougo/deoplete.nvim">Deoplete</a>, and I’ve also used <a href="https://github.com/ycm-core/YouCompleteMe">YouCompleteMe</a> in the past. Feel free to try them yourself. I can only tell you that once I tried COC I never looked back. Zing.</p><p>So, you install the plugin. Now what? You want tsserver integration for IntelliSense? :CocInstall coc-tsserver. Want <a href="https://www.tabnine.com/">AI-assisted autocompletion</a>? :CocInstall coc-tabnine. Instead of suggesting completions from a language documentation dictionary, <a href="https://www.tabnine.com/">TabNine</a> learns from your code and suggests stuff in a way that makes you say “how did it know what I was going to type?”.</p><p>I already know my setup, so I did it in one line:</p><pre>:CocInstall coc-tsserver coc-tabnine coc-pyright coc-html coc-css</pre><p>Check out the <a href="https://github.com/neoclide/coc.nvim/wiki/Language-servers#contents">full list</a> of supported language servers. Hell, if you don’t want to use ALE for ESLint you can even :CocInstall coc-eslint, and <a href="https://github.com/neoclide/coc-eslint#features">set it up the way you want</a> in your :CocConfig.</p><p>I encourage you to read their <a href="https://github.com/neoclide/coc.nvim#example-vim-configuration">example configuration</a>, to add some useful lines to your .vimrc. Since I disabled swapfiles set updatetime=300 is not needed, that’s the swapfiles update time, but I did add this one:</p><pre>set shortmess+=c</pre><p>It appends the c to the messages configuration so you don’t get unnecessary info in your suggestions dropdown, like “match 1 of 2”. Probably c stands for cropped, but who knows for sure.</p><p>Lastly, since I’m using ALE for linting, and I want ALE to display the error messages in my status line (and not COC in a dialog box), I added this line to my :CocConfig :</p><pre>&quot;diagnostic.displayByAle&quot;: true</pre><p>And this one to my .vimrc, telling ALE to leave the Language Server Protocol part all to COC:</p><pre>let g:ale_disable_lsp = 1</pre><p>If you just fresh installed COC, your:CocConfig file will probably be empty. Remember it’s a .json file, so simply wrap it in curly braces.</p><h4><a href="https://github.com/SirVer/ultisnips">UltiSnips</a></h4><figure><img alt="UltiSnips snippet demonstration" src="https://cdn-images-1.medium.com/max/1024/1*srjEeQGEBAZo57xoT1lYyw.gif" /><figcaption>‘React Functional Component’ snippet</figcaption></figure><p>UltiSnips allows you to save chunks of code that you happen to find yourself reusing quite often, a.k.a snippets, and call them with a simple abridged command. UltiSnips is actually only the engine, if you want a full library of functioning snippets, install these <a href="https://github.com/honza/vim-snippets">snippets</a>.</p><p>I erased it the snippets pluggin (the snippets themselves, not the engine), since I realized the only snippet I really found myself using was a React simple functional component with export, and I din’t even like the style of the default one, so I created one myself. To do so, open a file with your desired language extensions, in my case I was already working with a .jsx file, and trigger :UltiSnipsEdit to <strong>automatically</strong> create a new file in ~/.vim/UltiSnips/ for that specific language, in this case it’s javascriptreact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*adt5iPTka-GD2lUeTm2YLg.png" /><figcaption>Polyglot calls it ‘javascriptreact’</figcaption></figure><pre>snippet <strong><em>rfc</em></strong> &quot;react functional component&quot; b<br>import React from &#39;react&#39;;</pre><pre>function ${1:`!p snip.rv = snip.basename`}(${2}) {<br>  return (<br>    &lt;&gt;${3:}<br>    &lt;/&gt;<br>  );<br>}</pre><pre>export default $4`!p snip.rv = snip.basename`;<br>endsnippet</pre><p>I wrote the above snippet, you can see it in action in the gif above. If you copy/paste it you might have to retab or make sure to replace the spaces with tabs. A good source of inspiration are the <a href="https://github.com/honza/vim-snippets/tree/master/UltiSnips">snippet files</a> I mentioned above, you can just look at them in the repo, no need to install them.</p><p>Now, whenever I want to expand my snippet, just type rfc and trigger it with ^j, (control + j), because I set it that way in my .vimrc:</p><pre>let g:UltiSnipsExpandTrigger=&quot;&lt;c-j&gt;&quot;<br>let g:UltiSnipsListSnippets=&quot;&lt;c-l&gt;&quot;</pre><p>^j, or whatever combination you want to set it to, also jumps between the “stops”. See the 1:, 2:, etc? Those are the stops the jump is gonna make, they allow me to quickly insert props if needed, or insert some code inside of the &lt;&gt; fragments. On the other hand, ^l allows you to enter a partial snippet name and deploy a list of matches, in case you don’t recall what the snippet complete name was. In my case it’s totally useless since I only have the one and only rfc snippet.</p><p>Although I don’t use it, you might want your snippets to appear in the COC autocompletion list. In that case, take a loot at <a href="https://github.com/neoclide/coc-snippets">this</a> extension, that you can install as usual with :CocInstall coc-snippets.</p><p>One last thing, if you do decide to install the Vim snippets collection, make sure to take a good a how the files are named and how your status line calls your file formats. Let me explain: <em>probably</em> because of Polyglot’s React library, my Vim calls .jsx files &#39;javascriptreact&#39; and the snippets are read in a file with that exact name. If you take a look at the Vim snippets <a href="https://github.com/honza/vim-snippets/tree/master/UltiSnips">repo</a>, their file for React is called &#39;javascript_react&#39; and UltiSnip will not read it with my actual settings, so I would have to delete the underscore by hand. I don’t know why this is, maybe for compatibility with another library, but it’s a detail to keep in mind.</p><h4><a href="https://github.com/junegunn/fzf">FZF</a> &amp; <a href="https://github.com/junegunn/fzf.vim">FZF.VIM</a></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*UtWzrYdWEhIyW5qGEOtmSQ.gif" /><figcaption><strong>fzf</strong> running in the shell with partial names</figcaption></figure><p>fzf is a fuzzy search process that lets you quickly search a filename match within the contents of a directory, directly from your terminal. It’s way faster than my OS’ spotlight, specially if I’m already in the terminal.</p><p>I installed it with brew install fzf but you can get it with your system’s package manager, even Window’s choco. I also included it as a Vim plugin but I honestly don’t know if that’s <em>redundant</em> or <em>necessary</em>.</p><p>The thing is that even if you can keep fzf up to date with your plugin manager, fzf is not really a Vim plugin with proper integration, hence <a href="https://github.com/junegunn/fzf.vim">fzf.vim</a>! It has a couple of dependencies you need to install in your system to be able to fully access its functionalities, but believe me, they all are worth it.</p><p>You obviously need fzf for fzf.vim to work properly. You trigger file searches with :File and it looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*22RkD2qCVoFHVnsjGKLO9w.gif" /><figcaption>Files fuzzy search</figcaption></figure><p>You also need either the Rg (<a href="https://github.com/BurntSushi/ripgrep">ripgrep</a>) or Ag (<a href="https://github.com/ggreer/the_silver_searcher">the silver searcher</a>) for fzf.vim to be able to search <em>within</em> your project files. You can get them system wide via your packet manager, and you trigger them within Vim with :Rg or :Ag. I use Rg, and it looks like this:</p><figure><img alt="Matching patterns within files" src="https://cdn-images-1.medium.com/max/783/1*TUZOYwkP4HuDYtVtrTLM9g.gif" /><figcaption><strong>Rg</strong> gets regex matches within files</figcaption></figure><p>You can also install a <a href="https://github.com/universal-ctags/ctags">ctags implementation</a>, that allows you to index the ‘tags’ in your files (functions, variables, classes…) and then browse through them project-wide with :Tags. Tags will also come in handy for the next plugin.</p><h4><a href="https://github.com/preservim/tagbar">Tagbar</a></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D8Y6PWw1Sd3cwJO61EUG-A.png" /><figcaption>Same as last plugin’s <strong>:Tags</strong> but for a buffer</figcaption></figure><p>It doesnt’ really makes sense for a small file like the one above, but this screenshot clearly illustrates how Tagbar indexes the tags in your current file. It gets classes, functions, variables, primitives, etc. It really shines when you have to edit a behemoth undocumented 1500-lines ES5 file. It might never happen to you, but if it does, you’ll be glad to have Tagbar.</p><p>Remember to throw in something like this in your .vimrc:</p><pre>nmap &lt;F8&gt; :TagbarToggle&lt;CR&gt;</pre><p>And there you have it, toggled by the f8 key.</p><h4><a href="https://github.com/Yggdroot/indentLine">IndentLine</a></h4><figure><img alt="Indentation marks" src="https://cdn-images-1.medium.com/max/1024/1*6wELlaXTEQ2qRBNvgux_9w.png" /><figcaption>Visual lines for space-indentation</figcaption></figure><p>I don’t want to revive the decades old tab vs space indentation dilema. I can provide sensible arguments for both sides, but I do happen to use spaces. If you use tabs, you don’t need IndentLine, simple go back to your .vimrc and set whatever character you want the tabs to be shown as. Refer to <a href="https://medium.com/@edominguez.se/vim-101-a-comprehensive-guide-to-using-vim-like-an-ide-1-3-vimrc-d484cc41fc2">part 1 </a>if you need a refresher.</p><p>If you use spaces on the other hand, you’ might find this plugin useful. Or not. In any case, it takes advantage of Vim’s concealing feature, and it’s quite configurable since it allows you override the default highlighting settings for the conceal group. You want the lines to be green over an orange bg, go crazy with something like:</p><pre>let g:indentLine_color_gui = &#39;#A4E57E&#39;<br>let g:indentLine_bgcolor_gui = &#39;#FF5F00&#39;</pre><p>or something like:</p><pre>let g:indentLine_color_term = 239<br>let g:indentLine_bgcolor_term = 202</pre><p>if you didn&#39;t enable the termguicolors in your .vimrc.</p><p>The thing is I want them to be as subtle as possible, I don’t want to get distracted by them, so I set them to an appropriate gray with low contrast. However, I told you these settings override the conceal group default highlighting settings, so if you were using concealing for keywords like ‘null’ or ‘function’ as we discussed above, they also will get greyed out and will be barely visible, which in my opinion is a no-no.</p><p>You can always pick a color that is visible enough to clearly see the concealing characters, but not distracting enough so that the indent lines become all noisy in your screen. I could not find such color so I chose subtle IndentLines over concealing syntax altogether, and ended up disabling it. You might chose the opposite. I may happen to change my mind tomorrow. Who knows.</p><p>Check out more configuration options for IndentLine in their <a href="https://github.com/Yggdroot/indentLine#customization">repo</a>. You can change the indent character with something like:</p><pre>let g:indentLine_char = &#39;.&#39;</pre><p>and your file will be indented with dots instead. Just make sure your .vimrc’s character encoding is set to UTF-8.</p><h3>Furthermore…</h3><h4><a href="https://github.com/editorconfig/editorconfig-vim">EditorConfig</a></h4><p>Just as I was wrapping this article, <a href="https://medium.com/u/4540da9eb8c6">Simone Conti</a> pointed out that instead of hard-coding the tab settings for each language, like I suggested in <a href="https://medium.com/@edominguez.se/vim-101-a-comprehensive-guide-to-using-vim-like-an-ide-1-3-vimrc-d484cc41fc2">part 1</a>, it would actually be better to use the <a href="https://editorconfig.org/">EditorConfig</a> convention ensuring consistency across editors, files and projects. Here’s the <a href="https://github.com/editorconfig/editorconfig-vim">Vim plugin</a>. I still have to try it out but if it’s about enforcing consistency, count me in.</p><h4><a href="https://github.com/puremourning/vimspector">Vimspector</a></h4><p>A graphical debugger very much like the VSCode one. A must have.</p><h4><a href="https://github.com/kiteco/vim-plugin">Kite</a></h4><p>Provides both AI <strong>and</strong> documentation assisted autocompletion. Instead of using COC+tsserver+TabNine, Kite provides all of those services in one plugin, but better. The main problem is that you need to run the Kite engine as a dedicated desktop app to which the Vim plugin connects to, but the <a href="https://www.kite.com/download/">download</a> has been unavailable <em>for almost a year</em> now. I happen to have a .dmg lying around, but I don’t think the Kite guys would like me to share it. I’m totally NOT offering you the installer. I’m seriously NOT encouraging you to ask me for it so you can try it. DON’T, because I will definitely NOT send you a download link. Wink, wink.</p><h4><a href="https://github.com/frazrepo/vim-rainbow">Rainbow Parenthesis</a></h4><p>If you’d rather have coloured bracket pairs instead of indent lines, give it a try.</p><h4><a href="https://github.com/tpope/vim-fugitive">Fugitive</a></h4><p>I just realized Fugitive has ‘git’ in the middle of the word. Another one by Tim Pope, the creator of Surround and Commentary, Fugitive allows you to call Git commands from your buffer.</p><p>Since we’re talking Git, You might also want to check the <a href="https://github.com/airblade/vim-gitgutter/">Git Gutter</a>. Just giving you options here, I never really used it.</p><h4><a href="https://github.com/tpope/vim-pathogen">Pathogen</a></h4><p>Also by Tim Pope, this one allows you “to install plugins and runtime files in their own private directories” if you’re into that stuff.</p><p>As promised, here’s my plugin configuration:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/947f62f7b79958d470454f436e09ac30/href">https://medium.com/media/947f62f7b79958d470454f436e09ac30/href</a></iframe><p>I tried to configure the tagbar to index .jsx files, but I never got it quite on point. Then I realized it was a waste of time since my components are always small and I don’t really need tagbar for .jsx…</p><p>That’s all folks, stay tuned for part 3 where we will discuss all about Vim navigation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8eae1b77497" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/fuzzy-searchhow-to-set-up-vim-in-2021-2-3-b8eae1b77497">How to set up Vim in 2021? (2/3)</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to set up Vim in 2021? (1/3)]]></title>
            <link>https://medium.com/@edominguez.se/vim-101-a-comprehensive-guide-to-using-vim-like-an-ide-1-3-vimrc-d484cc41fc2?source=rss-270e861d6b04------2</link>
            <guid isPermaLink="false">https://medium.com/p/d484cc41fc2</guid>
            <category><![CDATA[ide]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[beginner]]></category>
            <category><![CDATA[vim]]></category>
            <dc:creator><![CDATA[Enrique Domínguez]]></dc:creator>
            <pubDate>Thu, 04 Nov 2021 09:32:14 GMT</pubDate>
            <atom:updated>2022-09-05T23:49:44.813Z</atom:updated>
            <content:encoded><![CDATA[<h3>A comprehensive guide to setting up Vim like an IDE Part 1: the .vimrc</h3><p><em>This is part of a series aimed at teaching you the Vim fundamentals. Part one is about my .vimrc configurations. </em><a href="https://medium.com/@edominguez.se/fuzzy-searchhow-to-set-up-vim-in-2021-2-3-b8eae1b77497"><em>Part two is all about the plugins</em></a><em>. Part three will be about navigating Vim like a pro.</em></p><p><em>I’m writing these articles for the Vim newbie I once was. But even as of yesterday I’m still learning new things about Vim, so who knows, stay awhile and listen!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ChCRhwrhDj--5mmIGKn9BQ.png" /><figcaption>Looking good</figcaption></figure><p>Great, another Vim article, just what we needed in 2021… Hold on. My aim here is to share not only the <em>whats </em>and the<em> hows,</em> but most importantly the <em>whys</em> of my setup. There are many articles out there telling you what plugins to install or what configs to copy/paste, and I’m grateful for them as they did solve my issues one way or another. The problem was that most of the time I didn’t really understand what I was doing; it took me about a year of progressive experimentation get where I am now. Hopefully all my past struggles will save your precious time.</p><p>Without further to do, grab a drink and let’s get into it. This one is gonna be a thorough one.</p><h4>Let’s break down my .vimrc</h4><p>I’m assuming nothing about your level of Vim expertise, but If you just wanna take a look at my .vimrc and move on, here it is:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5cc2ea98b2c14cf378b62bf72af1177d/href">https://medium.com/media/5cc2ea98b2c14cf378b62bf72af1177d/href</a></iframe><p>Actually I’m assuming you do know how to exit vim. You surely know how to enter commands like :q or :w. Keep in mind that colon logic, as it is going to pop up down below.</p><h3>I Am Devloper on Twitter: &quot;I&#39;ve been using Vim for about 2 years now, mostly because I can&#39;t figure out how to exit it. / Twitter&quot;</h3><p>I&#39;ve been using Vim for about 2 years now, mostly because I can&#39;t figure out how to exit it.</p><p>I’m also assuming you know your can configure Vim via a file $HOME/.vimrc located in your home directory in <strong>unix-like systems.</strong> You can edit it with Vim itself or with whatever text editor you happen to have at hand. It’s a hidden file, hence the . in the filename.</p><p>Now, what do all of those settings even do? Let’s go block by block.</p><pre>syntax on</pre><p>This one is pretty straightforward: <strong>syntax on</strong> enables syntax highlighting on your code, like on any proper text editor.</p><pre>set fileformat=unix<br>set encoding=UTF-8</pre><p>Vim recognizes three types of file-formats: Unix, DOS &amp; Mac. The latter is deprecated, as modern Mac OS’ use unix file formatting. The difference between DOS and Unix is what <strong>line terminators</strong> each one uses (CR+LF and only LF respectively); I’ll let you google the specifics. If your garden-variety Windows VSCode user shares a file with you, you might get an ESLint error (because of the CRLF line terminators) depending on the ruleset you’re using, but do note that unix linebreaks are enforced by <a href="https://eslint.org/docs/rules/linebreak-style"><em>default</em></a>.</p><p>Also, I like to explicitly set my encoding to UTF-8, <em>just in case</em>.</p><pre>au BufNewFile,BufRead *.py<br>    \ set tabstop=4 |<br>    \ set softtabstop=4 |<br>    \ set shiftwidth=4 |</pre><p>I’m a big believer in enforcing code style. Readability, consistency and so on. But I don’t wanna be pressing those tabs twice when I’m writing python code! That’s why I’m telling Vim <em>“whenever you open a new buffer for a </em><strong><em>.py</em></strong><em> file, tabs are </em><strong><em>4 spaces long</em></strong><em>”.</em> <strong>shiftwidth</strong> is the value used for auto-indentation. | means “and”, and \ means “this new line is part of the previous scope”; if you were to remove those characters, Vim would interpret each new line as a global setting, not one specifically for python.</p><p>If my file is not .py, fall back to my global tab settings:</p><pre>set tabstop=2<br>set softtabstop=2<br>set shiftwidth=2<br>set autoindent<br>set smartindent<br>set smarttab<br>set expandtab</pre><p><strong>autoindent, </strong><strong>smartindent </strong>and<strong> </strong><strong>smarttab </strong>preserve the indentation when you break a new line, and add a new indentation level when appropiate. Smarttab is related to the softtabstop, but I rendered it irrelevant by setting them all to the same value. <strong>expandtab </strong>breaks your “tab” character into spaces.</p><pre>set nowrap<br>set list<br>set listchars=eol:.,tab:&gt;-,trail:~,extends:&gt;,precedes:&lt;</pre><p><strong>nowrap </strong>prevents line wrapping, which means that if a line length exceeds vim’s window width, the text will not be show in a new “intermediate” line. It will simply be cut off the screen. Think “overflow: scroll”. It’s a matter of preference, but why is your line so long in the first place? <strong>list</strong> and <strong>listchars</strong> allow me to see the “invisible characters”, the most useful for me being the trailing spaces at the end of a line. If you use a code formatter, you can set it to erase them automatically but I like <em>terminating</em> them by hand. More on that below.</p><pre>set cursorline<br>set number<br>set relativenumber<br>set scrolloff=8<br>set signcolumn=yes</pre><p>For this section, a picture is worth a thousand words:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*aIK1iUqc_YfcGF4V5PfSCA.gif" /><figcaption>Can you see those pesky trailing spaces?</figcaption></figure><p><strong>cursorline</strong> highlights the whole line my cursor is on, making it easier to find it. Currently it’s on line 6. <strong>number</strong> enables the line-number column, and <strong>relativenumber</strong> makes it so instead of the line numbers, I’m shown the offset of any given line to the one I’m positioned on. Why? Because I’d rather jump to that error 11 lines below by pressing <strong>11j</strong> (offset+direction) than <strong>:17⏎ </strong>(colon + line number + return). But it’s totally personal, do as you please. By the way, that error is ESlint telling me I’ve got a bunch of <em>trailing spaces</em> that need to be terminated.</p><p><strong>signcolumn </strong>enables the left-most column where the error is marked. You can set it to signcolumn=number if you want, and the errors will be shown on top of the line-numbers instead of a separate column. Lastly, <strong>scrolloff</strong> will make the document start scrolling 8 lines before my cursor reaches the bottom line. You can set it to whatever offset works for your screen size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*P0YGTEppsMpqYY8DmaBe_g.gif" /><figcaption>The scroll offset is set to 8</figcaption></figure><pre>set showcmd<br>set noshowmode<br>set conceallevel=1</pre><p><strong>noshowmode </strong>tells Vim not to show me if I’m in visual mode, insert mode, etc. Why? because I’ve got a beautiful plugin doing it for me as seen above. I don’t want them both showing me the same information at the bottom of my screen. <strong>showcmd </strong>“shows the command” I’m currently typing on the bottom-right of the screen, it’s useful for when you’re typing escape commands like control+W+shift+h... <strong>conceallevel </strong>refers to how the characters are concealed, more on that in <a href="https://medium.com/@edominguez.se/fuzzy-searchhow-to-set-up-vim-in-2021-2-3-b8eae1b77497">part 2</a>, but if you payed attention to the React code above, the “function” keyword is concealed as an “ƒ”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q6d_fSDfVIbNr6TWpdTlvw.png" /><figcaption>Showcmd: Control + W</figcaption></figure><pre>set noerrorbells visualbell t_vb=<br>set noswapfile<br>set nobackup<br>set undodir=~/.vim/undodir<br>set undofile<br>set clipboard=unnamed</pre><p><strong>noerrorbells visualbell t_vb=</strong> (note that it’s set to <em>nothing</em>) disables sounds, bells, beeps and my screen flashing white whenever an error occurs. Why? most errors are dumb errors like pressing the wrong key, and it quickly becomes annoying. Very annoying. Having it <em>do nothing</em> is already telling me <em>I did the wrong thing</em>, I don’t need an extra layer of irritation.</p><p>Swapfiles store changes made on the buffer, and if Vim crashes they allow us to recover those changes. I’ve disabled them with <strong>noswapfile </strong>alongside <strong>nobackup</strong> because I’m already saving my all my changes to an <strong>undofile </strong>located in the <strong>undodir </strong>path. And that allows me to have infinite undos even after I save, close and reopen a file a week later!</p><p>The <strong>clipboard</strong> thing is because in unix-like systems, there is more than one clipboard. I want my system command+c clipboard to be the same as my Vim y<strong> </strong>and<strong> </strong>p<strong> </strong>clipboard, to be able to copy from Vim into other applications and vice versa. I’ll let you research the proper clipboard settings for your OS.</p><pre>set ignorecase<br>set smartcase<br>set incsearch<br>set hlsearch<br>nnoremap &lt;CR&gt; :noh&lt;CR&gt;&lt;CR&gt;:&lt;backspace&gt;</pre><p>These are the search settings. Just in case you didn’t know, you can search for a character sequence in your file by directly hitting / and typing your search terms. You press return to confirm it and with n you navigate to the next search result.</p><p><strong>ignorecase</strong> ignores the uppercases, for instance “norwegianblue” will get both “norwegianBlue” and “NORWEGIANBLUE”. <strong>smartcase</strong> will make it so that if I intentionally put an uppercase character in my search term, <em>then</em> it will no longer be ignored: “norgegianBlue” will not get “norwegianblue” nor “NORWEGIANBLUE”. <strong>incsearch </strong>highlights the pattern matches as typed <em>so far. </em><strong>hlsearch </strong>highlights all matches <em>simultaneously.</em> So far so good.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*jfYRRgzR9bGMZ9i_c418HQ.gif" /><figcaption>Smart case in action</figcaption></figure><p>But what’s that weird last line with the <strong>nnoremap</strong>? Well, say you hlsearch, you find what you were looking for, and you start typing fresh code… only to realize all previous search results are still highlighted. They won’t clear off. Not until you enter the <strong>:noh</strong> command and return it. Hey, maybe you want them to keep highlighted, that’s what vim’s all about: options. I don’t, so I remapped my return key to execute three things: when in <em>Normal</em> mode enter the :noh<strong> </strong>command, return<strong> </strong>the command, and then return, so that it keeps its normal functionality after clearing out the search results. The last bit about the &lt;backspace&gt; was because Vim keeps showig the last command you typed and it was bugging me seeing that :noh there, all the time, in the bottom of my screen. It clears the clearing. You can always disable the hlsearch, I encourage you to try searching with and without it and the decide if you like it. But at least now you know about <em>remaps</em>. More on that later.</p><pre>so ~/.vim/plugins.vim<br>so ~/.vim/plugin-config.vim<br>so ~/.vim/autoclose.vim</pre><p>That’s me linking three Vim config files to my main .vimrc, with the intention ‘keeping concerns separated’ and not having a bloated humungous .vimrc. You can separate your configuration in as many files as you deem necesary with that pattern. Note how I load <strong>plugin-config </strong><em>after </em><strong>plugins</strong> is loaded: order matters, just as if those configs were inside my .vimrc, you would’t try to tell Vim what to do with the plugins before they were even called. We’re gonna <a href="https://medium.com/@edominguez.se/fuzzy-searchhow-to-set-up-vim-in-2021-2-3-b8eae1b77497">discuss plugins in part 2</a>, but before the end of this article we’re gonna see what that <strong>autoclose</strong> file is all about.</p><p>Lastly there’s the color config, but I’m gonna talk about that also in <a href="https://medium.com/@edominguez.se/fuzzy-searchhow-to-set-up-vim-in-2021-2-3-b8eae1b77497">part 2</a> because the theme I use, <strong>gruvbox,</strong> is installed as a plugin. Why aren’t those configs in the plugin-config.vim file? Because I feel they are mainly telling <strong>Vim</strong> what to do and not the plugin itself. They are down below, <em>after</em> the plugins were loaded because I do happen to call the plugin itself. You can put them in a separate file if you want, remember it’s <em>your</em> .vimrc now, not mine.</p><h4>Important considerations</h4><p>If you’re using python a lot, you might consider throwing in a <strong>textwidth</strong> setting telling Vim to have a maximum line length of 80 as per the PEP 8 recommendations.</p><pre>set textwidth=79</pre><p>Also, when sharing your screen or working with someone else, consider <strong>disabling the relative numbers</strong>, so that people can easily tell you “<em>line 72, do this and that”</em> instead of <em>“line fift…wait wtf ”</em>. You can do that for your current buffer only. In fact you can override any setting <em>from and for</em> your buffer only, because when Vim loads, it sets the .vimrc settings and any further manual change won’t affect your .vimrc.</p><pre>:set nornu<br>:set norelativenumber</pre><p>As you can see, most commands have abbreviated versions. Which one would you rather type?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*lCy2EojpP_bJal8x8AKqag.gif" /><figcaption>Don’t let the mouse distract you from the :nornu</figcaption></figure><p>Oh, yeah. You can enable your mouse in Vim. Even if you like running it from the terminal for some reason, like I do. The choice is yours, I won’t judge you.</p><pre>set mouse=a</pre><p>If you have any further doubts about any setting, you can always google, it or <em>read the documentation from within vim</em>. It’s actually not too shabby!</p><pre>:help &#39;command_name&#39;</pre><h4>What’s with that autoclose file anyway?</h4><p>There are many working plugins that manage the closing of bracket pairs, parenthesis pairs and so on. Try them out, by all means, maybe you’ll like them better. But why install a plugin if a couple of remaps can do the trick, natively and all?</p><p>Basically the remaps (below) are telling Vim “whenever one types one of those characters, automatically insert the closing pair”. But there’s little more depth into it: where do you want the cursor to be thereafter?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/1*94sluo8xpyruKOjgWQVFhg.gif" /><figcaption>Typing, return and tab do different things. Plus all the smartindent we already set up.</figcaption></figure><p>I know there are better ways to check for an empty string but I wanted to showcase all three behaviours, so I don’t want to hear it. The rules work for all remapped characters, (, { ,[ , “, etc.</p><p>If you open a ( and you start typing immediately, the cursor will be between the open and the <em>automatically inserted</em> closing parenthesis as in the (string) function parameter. If you open a { and return, the cursor will be in a new line in between the open and closing braces. If you enter a ‘ and tab away, the cursor will be placed right after the closing quotation mark. You can also alter the closing character with a , or a ; and it won’t affect the cursor position: in the example above I actually entered { ; return to get a semicolon inserted after the closing brace. You can see how useful it becomes when dealing with a bidimensional array of strings for example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf8a4d4ea36e28c7ba5f554893966fee/href">https://medium.com/media/cf8a4d4ea36e28c7ba5f554893966fee/href</a></iframe><p>If you pay close attention, the remaps are basically the same character sequences you would input to manually get there: { return } ; then escape to get into <em>Normal</em> mode and finally capital O, meaning shift o, to get a new line above. A new line that gets autoindented because we set it that way!</p><p>Well folks, that’s about it for now. Thank you for reading, I really hope you learnt something today. <a href="https://medium.com/@edominguez.se/fuzzy-searchhow-to-set-up-vim-in-2021-2-3-b8eae1b77497">Part 2 is out</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d484cc41fc2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>