<rss version="2.0">
  <channel>
    <title>Meet Gor - Tag: vim</title>
    <link>https://www.meetgor.com</link>
    <description>Posts tagged with vim</description>
    <language>en-us</language>
    <pubDate>Sat, 09 May 2026 05:38:52 UTC</pubDate>
    <item>
      <title>Format JSON in Vim with JQ</title>
      <link>https://www.meetgor.com/til/format-json-in-vim-with-jq</link>
      <description>We can use :%!jq . To instantly format a json file opened in vim/neovim. I relied on online foramtter and opening vscode for formatting. But this quick tool jus</description>
      <pubDate>Sat, 05 Apr 2025 00:00:00 UTC</pubDate>
      <content>&lt;p&gt;We can use&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;:%!jq .&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;To instantly format a json file opened in vim/neovim.&#xA;I relied on online foramtter and opening vscode for formatting.&#xA;But this quick tool just saves a lot of hassle. Opening VS Co** == shutting down the laptop, it clogs the memory badly, so I avoid opening VS Co** as much as possible.&lt;/p&gt;&#xA;&lt;p&gt;Yes, to use this, you need to have &lt;a href=&#34;https://jqlang.org/&#34;&gt;jq&lt;/a&gt; installed on your system.&lt;/p&gt;&#xA;&lt;p&gt;If you are elsewhere and want to format json file using jq, you can quickly do this:&lt;/p&gt;&#xA;&lt;pre&gt;&lt;code&gt;jq . input.json | sponge input.json&#xA;&#xA;# OR&#xA;&#xA;jq . input.json &amp;gt; tmp.json &amp;amp;&amp;amp; mv tmp.json input.json&#xA;&#xA;&lt;/code&gt;&lt;/pre&gt;&#xA;&lt;p&gt;If you are in Vim and want to format other file, just add &lt;code&gt;!&lt;/code&gt; at the start of the command and that will run in the shell for you, so you don&#39;t have to exit vim.&lt;/p&gt;&#xA;</content>
      <type>til</type>
    </item>
    <item>
      <title>Map Vimscript Keymaps to Lua with a single function</title>
      <link>https://www.meetgor.com/til/vimscript-to-lua-keymapper</link>
      <description>Takeout the vimscript keymaps into lua with a single function call in Neovim</description>
      <pubDate>Mon, 11 Jul 2022 00:00:00 UTC</pubDate>
      <content>## Introduction&#xA;&#xA;Are you bored of writing all the keymaps from vimscript to lua? Try the below function to create all your keymaps to lua equivalent maps in Neovim.&#xA;&#xA;Take your vimscript keymaps and put them in lua don&#39;t write any lua for it ;)&#xA;&#xA;## The Lua Function&#xA;&#xA;The below-provided snippet is a lua function that takes in a table of strings(list of strings), the strings will be your keymaps. The function then maps these keymaps using lua functions. You don&#39;t have to type out all the keymaps by yourself. It can also print out the lua equivalent function calls required to map the existing keymaps from vimscript to lua runtime in Neovim. Though it won&#39;t handle all the options, we have passed in a default value to the keymap.&#xA;&#xA;```lua&#xA;function key_mapper(keymaps)&#xA;  for _, keymap in ipairs(keymaps) do&#xA;    local mode = keymap:sub(1,1)&#xA;    local delimiter = &#34; &#34;&#xA;    local lhs = &#39;&#39;&#xA;    local rhs_parts = {}&#xA;    local m = 0&#xA;    local options = {noremap = true}&#xA;    for matches in (keymap..delimiter):gmatch(&#34;(.-)&#34;..delimiter) do&#xA;      if m == 1 then&#xA;        lhs = matches&#xA;      end&#xA;      if m &gt;= 2 then&#xA;        table.insert(rhs_parts, matches)&#xA;      end&#xA;      m = m + 1&#xA;    end&#xA;    rhs = &#39;&#39;&#xA;    for _, p in ipairs(rhs_parts) do&#xA;      rhs = rhs .. &#34; &#34; .. p&#xA;    end&#xA;    --print(&#34;vim.keymap.set(&#34;..&#34;\&#39;&#34;..mode..&#34;\&#39;&#34;..&#34;, &#34;..&#34;\&#39;&#34;..lhs..&#34;\&#39;&#34;..&#34;, &#34;..&#34;\&#39;&#34;..rhs..&#34;\&#39;&#34;..&#34;, &#34;..vim.inspect(options)..&#34;)&#34;)&#xA;    vim.keymap.set(mode, lhs, rhs, options)&#xA;  end&#xA;end&#xA;```&#xA;&#xA;You can uncomment the print statement **once** to grab the keymaps and paste them into the config file. If you leave it uncommented, it might print every time you open up a new neovim instance. The function can be called like below:&#xA;&#xA;```lua&#xA;key_mapper({&#xA;  &#39;nnoremap cpp :!c++ % -o %:r &amp;&amp; %:r&lt;CR&gt;i&#39;,&#xA;  &#39;nnoremap c, :!gcc % -o %:r &amp;&amp; %:r&lt;CR&gt;&#39;,&#xA;  &#39;nnoremap py :!python %&lt;cr&gt;&#39;,&#xA;  &#39;nnoremap go :!go run %&lt;cr&gt;&#39;,&#xA;  &#39;nnoremap sh :!bash %&lt;CR&gt;&#39;&#xA;})&#xA;```&#xA;&#xA;![Keymapper demonstration](https://res.cloudinary.com/techstructive-blog/image/upload/v1657559501/blog-media/neovim-lua-keymapper.gif)&#xA;&#xA;We pass in a table of strings, these strings are just the vimscript keymaps. This function call will then map the keymaps into equivalent lua maps. You can customize it as per your needs.&#xA;&#xA;For further references, you can check out my [dotfiles](https://github.com/Mr-Destructive/dotfiles) on GitHub.&#xA;&#xA;## How the function works&#xA;&#xA;The function is simply a text scrapping from lua strings. We extract the first character in the string for the mode, grab the strings which are space-separated and finally sort out which are lhs and rhs sides of the maps.&#xA;&#xA;We iterate over the table in lua with the help of ipairs function which allows us to iterate over an ordered list of items in a table. Using the gmatch function, we find a pattern to split the string with the space as the delimiter. Thereby, we can have separate sets of strings identified as rhs and lhs. We can store them in variables as strings as the lua functions require them as strings.&#xA;&#xA;We simply add those variables into the [vim.keymap.set](https://neovim.io/doc/user/lua.html#:~:text=set(%7Bmode%7D%2C%20%7Blhs%7D%2C%20%7Brhs%7D%2C%20%7Bopts%7D)%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20*vim.keymap.set()*) or [vim.api.nvim_set_keymap](https://neovim.io/doc/user/api.html#nvim_set_keymap():~:text=nvim_set_keymap(%7Bmode%7D%2C%20%7Blhs%7D%2C%20%7Brhs%7D%2C%20%7B*opts%7D)%20%20%20%20%20%20%20%20%20%20%20%20%20*nvim_set_keymap()*) functions. We by default set the value of `{noremap: True}` to avoid teh recursive mapping of the keys. These option parameter is the one which needs to be a bit more dynamic in terms of wide variety of keymaps.&#xA;&#xA;So, this is how we can convert the vimscript keymaps to lua in Neovim. Hope you found this useful. Thanks for reading. Happy Viming :)</content>
      <type>til</type>
    </item>
    <item>
      <title>Autoformat Python file with Black after saving in Vim</title>
      <link>https://www.meetgor.com/til/vim-python-black-autoformat</link>
      <description>Automatically format python code in the current file after saving the file in Vim.</description>
      <pubDate>Tue, 29 Mar 2022 00:00:00 UTC</pubDate>
      <content>If you are like me who writes Python very badly, it has empty lines with whitespaces, no proper format in assigning variables, not formatted according to [PEP 8](https://peps.python.org/pep-0008/) standards, and you use Vim as your text editor then my friend you need a autocmd badly for it.&#xA;&#xA;## Install Black in Python&#xA;&#xA;Install the [black](https://pypi.org/project/black/) package in python globally or locally as per your preferences.&#xA;&#xA;```&#xA;pip install black&#xA;```&#xA;&#xA;OR with pipx&#xA;&#xA;```&#xA;pipx install black&#xA;```&#xA;&#xA;For a detailed guide about running packages with pipx head toward my article on [pipx](https://mr-destructive.github.io/techstructive-blog/pipx-intro/).&#xA;&#xA;## Set up Autocmd in Vim&#xA;&#xA;We can set up a autocmd. What is a autocmd? It is about running commands when certain events occur like running a command when a file is saved, a buffer is opened or closed, and so on. What we want is to run the black command from the shell when the current file is saved. &#xA;&#xA;So, we can create a autocmd as follows:&#xA;&#xA;```vimscript&#xA;autocmd BufWritePost * !black %&#xA;```&#xA;&#xA;Now, this will run when any type of file is saved, so we will make it specific to python by adding a `*.py` to add in the autocmd.&#xA;&#xA;```vimscript&#xA;autocmd BufWritePost *.py !black %&#xA;```&#xA;&#xA;This works, but it gives a prompt after the command has been executed, to run the command silently we can simply add the silent keyword before the execution of the command from the shell.&#xA;&#xA;```vimscript&#xA;autocmd BufWritePost *.py silent !black %&#xA;```&#xA;&#xA;This looks perfect! &#xA;&#xA;But still, we need to add a auto-group(`augroup`) that groups the autocmds and by adding `autocmd!` it will clear all the commands from the group. &#xA;&#xA;```vimscript&#xA;augroup python_format&#xA;    autocmd!&#xA;    autocmd BufWritePost *.py silent !black %&#xA;augroup end&#xA;```&#xA;We can now add it to the vimrc to work all the time.&#xA;&#xA;## Using pipx &#xA;&#xA;If you have used pipx to install black, you need to setup the autocmd a bit differently. &#xA;&#xA;```vimscript&#xA;autocmd BufWritePost *.py silent !pipx run black %&#xA;```&#xA;&#xA;It might be a bit slower than running with global installation, but it is a neat way to run python package. &#xA;&#xA;So, that&#39;s it we can now write clean and safe python code without breaking a sweat in Vim. Happy Coding :)</content>
      <type>til</type>
    </item>
    <item>
      <title>Why use Vim ?</title>
      <link>https://www.meetgor.com/posts/why-use-vim</link>
      <description>Introduction So, Why would one use Vim? As Vim being the most complicated Text editor when it comes to **closing it**!! Also, people think it&#39;s not worth the ti</description>
      <pubDate>Sun, 05 Sep 2021 00:00:00 UTC</pubDate>
      <content>## Introduction&#xA;&#xA;So, Why would one use Vim? As Vim being the most complicated Text editor when it comes to **closing it**!! Also, people think it&#39;s not worth the time or it&#39;s just not their type of Text Editor. Well, that&#39;s true, I am not forcing anyone to use Vim, just to tell the reasons why people use Vim. Again, it&#39;s not to show off to anyone that I use Vim, just to appreciate the power of Vim and its community, it&#39;s just amazing!!&#xA;&#xA;Vim is not a text editor just for anyone, it can be daunting initially but the more you use it, the more you love it. There is nothing called a time-wastage in learning Vim, if you think learning something is waste of time, just don&#39;t learn it! To have understood and got good at something you need to dedicate time and effort to it, there&#39;s no shortcut. When it comes to shortcuts, Vim is the fairyland of it, just use one or create your own. That&#39;s how cool Vim can be when used properly.&#xA;&#xA;Some of the most important and crucial reasons why people use Vim are:&#xA;&#xA;## Vim is Speed!&#xA;&#xA;Vim can be opened from the terminal, and that itself can speak that it is lightweight and uses lower system resources and hence causing minimal lag. This might not be an issue for high-end computers but when it comes to low-end machines, Vim behaves as a life-saver. Using certain commands feels so wicked fast and intuitive. Certain commands such as `t` or `f`, `u`, and many others are really powerful when it comes to editing in Vim. When you don&#39;t have to think about what keys you should type, you are really getting faster in Vim. &#xA;&#xA;![](https://s6.gifyu.com/images/screenrecording.gif)&#xA;&#xA;The above screencast is from my article [Vim: Set up for Python](https://mr-destructive.github.io/techstructive-blog/python/vim/2021/06/06/Vim-for-Python.html), which uses some key mappings to run python code directly from Vim itself by executing the shell commands from Vim&#39;s Command mode. A simple map can save a lot of time.&#xA;&#xA;```&#xA;nnoremap py :!python %&#xA;```&#xA;&#xA;&#xA;## Number of Commands/shortcuts&#xA;&#xA;When it comes to using key-bindings and shortcuts, there is no shortage of them. You can spend days, weeks, months, years but still, there will be some or the other thing to learn in Vim. That can be very intimidating to some people but that&#39;s how life is. **You cannot get perfect at anything but surely better is the word to focus on.** There is a good little cheatsheet at [devhints](https://devhints.io/vim) for beginners to quickly get started. Also, you can follow with the Youtuber- [ThePrimeagen](https://www.youtube.com/channel/UC8ENHE5xdFSwx71u3fDH5Xw), who focuses on switching and using Vim. Vim is has a robust set of command and key-bindings by far compared to other tex-editors. Here are some of my daily used [editing commands](https://mr-destructive.github.io/techstructive-blog/vim/2021/07/18/Vim-Enhancing-Editing-speed.html) and [navigation commands](https://mr-destructive.github.io/techstructive-blog/vim/2021/06/26/Vim-Enhancing-Movement-speed.html).&#xA;&#xA;## Power to use it as an IDE&#xA;&#xA;Vim provides some awesome features such as [terminal integration](https://mr-destructive.github.io/techstructive-blog/vim/2021/06/29/Vim-Terminal.html), [Key-mappings](https://mr-destructive.github.io/techstructive-blog/vim/2021/06/14/Vim-Keymapping.html), [Window Splits](https://mr-destructive.github.io/techstructive-blog/vim/2021/08/06/Vim-Window-Splits.html), etc to take text-editing and developer environment to a next-level. You can literally use Vim as an IDE for many of the programming languages like C/C++, Python, Java, Javascript, GO, etc. Though it can&#39;t replace entire IDE-like features, it is indeed powerful enough to add features in making a custom IDE experience. It might require some time and research to configure it to use it as a full-blown IDE, but it might be a very useful and self-motivating experience. There are definitely many articles, tutorials out to guide you in configuring the editor to an IDE. People might not use Vim for the features it has but also for the lightweights as compared to other IDEs such as Visual Studio, Android Studio, Eclipse, IntelliJ IDEA, etc.&#xA;&#xA;&#xA;![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1630827706766/cdN6GdnhH.png)&#xA;&#xA;From, the above screenshot, we can see that I have configured Vim almost like VSCode, Ok! Just the look of it is similar but ya we have the file manager as [NERDTree](https://mr-destructive.github.io/techstructive-blog/vim/2021/08/31/Vim-NERDTree.html), integrated Terminal, and the buffer opened as the editor. You can even add more functionality like autocomplete, keymaps to compile/run/build the code. There is are infinite possibilities when it comes to customization in Vim and to make it a full-blown IDE. OH! And by the way my Vim look changes from time to time XD&#xA;&#xA;## Available almost everywhere&#xA;&#xA;As said, Vim can be opened via the terminal, and hence it is quite viable when it comes to accessibility. It is pre-installed in almost every Linux-distributions, macOS, FreeBSD, etc. Hence it is quite reliable when it comes to compatibility and cross-platform support. You can start editing in any environment in Vim, so it becomes a good reason to learn to use Vim at least basic editing and opening, closing, etc. Vim being minimal and lightweight, it just becomes easy to work with servers. Production-environment, etc. It also isn&#39;t that complicated once you make your head around it. Being available in almost every Operating System has some value to it like it is the most dependable editor out there. Even after 30 years, yes Vim was released in 1991, it is still maintained by its producer [Brain Moolenaar](https://en.wikipedia.org/wiki/Bram_Moolenaar). That is mind-boggling, Vim is truly a vintage text editor silently but widely dominated in terms of its reach in Computing.   &#xA;&#xA;## The Level of Customization/Configuration &#xA;&#xA;It&#39;s kind of a double-sided sword for some people as it can be daunting to customize from scratch and also, it could be a rewarding and pleasurable experience of having the personalized experience.  With the number of plugins, custom vimrc and color schemes, etc Vim is very prone to personalization. It is **Open Source**, so we also have it&#39;s distributions such as [SpaceVim](https://github.com/SpaceVim/SpaceVim), [SPF-13](https://github.com/spf13/spf13-vim), etc. Some more distribution can be found [here](https://dev.to/ajeebkp23/some-popular-vim-distributions-a68). Some Distribution is pref-configured with some basic stuff and is ready to use, so they are quite beginner-friendly and introduce them to Vim in a better way. NeoVim which is an evolution of Vim written in Lua is much more powerful and provides even more customization keeping the basic key-bindings in mind. Editing Vimrc is quite an amazing and intuitive experience as it allows to add functionality or enhance the existing features in Vim. &#xA;&#xA;&#xA;## Conclusion&#xA;&#xA;&gt; Text Editors don&#39;t matter, what matters are the problem-solving skills&#xA;&#xA;Vim is a simple and minimal text editor, everyone can use it but not everyone finds the need to use it, that&#39;s fine. It might be ideal for me to use Vim than other editors but it might not be for you. But there is nothing to lose in knowing some basics of Vim. It might be useful somewhere, you never know! And if your favorite editor is not available, Vim might prove to be a great quick solution. Thanks for reading. Happing Coding :)&#xA;</content>
      <type>posts</type>
    </item>
  </channel>
</rss>