{
  "$type": "site.standard.document",
  "content": {
    "$type": "site.standard.content.markdown",
    "text": "⚠️ _**Warning: This post is very cringe as I hate talking about my tools instead of my work. You've been warned.**_\n\n![\"Friendship ended with Vimscript, Now Lua is my best friend\" meme](https://eligundry.com/../../assets/img/neovim-lua/friendship-ended-with-vimscript.png)\n\nLooking over my notes for this post, it seems like I've been using Vim in some sort or another for over a decade at this\npoint? Time flies when you can't `:quit` Vim. Folks, I'll be here all week.\n\nI guess I switched to Neovim at some point in 2014? One of the main reasons that Neovim exists is that mainline Vim,\nhistorically, resisted allowing configuration in languages that were not Vimscript. Vimscript is… not a good language.\nPeople that love it, love it, all the more power to them, but I am not one of them. I recall at some point during my\nmainline Vim days using some plugins that were written in Python, but those seem to break all the time.\n\nAll this time though, I have been maintaining a [very detailed and commented Vim config in Vimscript](https://github.com/eligundry/dots/blob/b6ec01b9fefb3d2883d12ffa2676e9fb1b6a6d48/config/nvim/init.vim).\nI have put a lot of sweat equity into this config! Perfecting it got me fired from a job in 2012. Lesson learned, you\nmove on. I even kept it backwards compatible with ancient versions of Vim that I will never encounter in reality. It was fun and made me feel\nlike a hacker. I would see people on Reddit talking about their configs in Lua and I would just tune them out. I have\nmy config and it's already held together with Popsicle sticks and glue. If I even look at it wrong, I'll lose a day of\ndevelopment time.\n\nAt some point in 2018, I discovered [coc.nvim](https://github.com/neoclide/coc.nvim) and it was a revelation. It was added\nVisual Studio Code's basic code completion features to my super custom Vim config! I could jump to definition!\nI could have accurate code completion! It probably does a lot more IDE like things, but I'm a simple man and that's\nall I need. My config would still break from time to time, but at least I became 1.3x more efficient.\n\n[I started working at Chord in 2022](https://eligundry.com/blog/job-search-2k22) and discovered that, for the first time, I had coworkers\nthat used Vim! I started a little `#vim` channel and we got to sharing tips and configs. It's always nice to find\npeople like you.\n\nOn a Friday evening in November, [Chad](https://www.linkedin.com/in/chadnickell/) posts his brand new Neovim config\nwritten in Lua. Well that just pushed all of us over the Lua cliff and we all spent our weekend updating our configs.\n\n[**You can checkout how I did this in this pull request!**](https://github.com/eligundry/dots/pull/7)\n\nChad's [base config](https://github.com/nickell/yadm/commit/5cc342cb5637294506421742b155a4db44b6c4fb) was a great base\nthat I was able crib into my config as I converted it to Lua. It had all the code completion plugins that I needed to\nreplace coc.nvim. At this point, he had his configs in a bunch of different files, which I have done in the past and\nhated as it's impossible to find anything easily, but I was able to work around that. (It should be noted that I mentioned\nmy experience with multiple files in the past and he converted his [config to a single file](https://github.com/nickell/yadm/blob/4b057ddd343292f2f726336b4552a4231bd1cbf6/.config/nvim/init.lua)).\n\nWithout any further ado, let's dive into what this conversion gave me!\n\n# I got a chance to switch up my plugins!\n\nSince I was moving from Vimscript to Lua, it only made sense that I switch some of my old plugins to newer, actively\nmaintained Lua alternatives. Here are some packages I upgraded to.\n\n## plug.vim ➡️ [packer.nvim](https://github.com/wbthomason/packer.nvim)\n\nI like Packer's syntax and how I can inline package configs right next to how I install them. Since I started porting,\nit seems that the new hotness is [lazy.nvim](https://github.com/folke/lazy.nvim), which I suppose I will check out 3\nyears from now.\n\nPacker seems to have the ability to \"snapshot\" configs that allow you to rollback in case package upgrades bork your\nsetup, but I haven't dived into that just yet.\n\n## coc.nvim ➡️ Various LSP plugins\n\ncoc.nvim is pretty nice. It manages all of the language server stuff for you in it's own config format that is closer\nto Visual Studio Code than Neovim. It was great when the Neovim LSP space was somewhat immature. Today though, Neovim's\nLSP support is now first class it makes sense to use it directly.\n\n_Unfortunately_, using Neovim's LSP directly does not free you from installing plugins. No, you will install many plugins\nand like it. Luckily, they all seem to work together. Here's a sampling of said plugins:\n\n- [mason.nvim](https://github.com/williamboman/mason.nvim): This manages the installation of the desired LSP plugins.\n  Ex: Typescript server, linting, gopls.\n- [nvim-cmp](https://github.com/hrsh7th/nvim-cmp): This is what powers all autocompletion prompts as you type. What makes\n  this better than coc.nvim's completions is that it works when in insert mode, searching, command line completions and\n  more!\n- [null-ls](https://github.com/jose-elias-alvarez/null-ls.nvim): This the glue that binds the LSPs that Mason installs\n  to the editor. It's slightly annoying to get going if you don't read the docs (which I wasn't when copying the config),\n  but once you do, you'll be like a Greek god of Vim.\n\nHere's a video of it all at work. Notice all the code completion and the auto formatting. It really works great!\n\n<DemoVideo\n  src=\"/video/neovim-lua/lsp-completion.webm\"\n  alt=\"Video showing off the code compeltion plugins I setup\"\n/>\n\n## ctrlp ➡️ [telescope](https://github.com/nvim-telescope/telescope.nvim)\n\nTelescope is a revelation! It's the single coolest thing that I introduced into my config in this sprint. It allows for\nsearching in all sorts of ways. I used to use ctrlp to do fuzzy path searching exclusively and was planning on continuing\nto use it in this config, but ctrlp kept crashing this Vim setup like 20% of the time (and always when I hadn't saved\na file 😤). I decided to map `<Ctrl-p>` to Telescope's find files function. Not only does it work exactly the same,\nI get a little preview of the file. And Telescope can search files for strings, search active buffers and more!\n\nYou have to see it to believe it!\n\n<DemoVideo\n  src=\"/video/neovim-lua/telescope.webm\"\n  alt=\"Video showing all the cool things Telescope can do (fuzzy path matching, live grepping)\"\n/>\n\n# What was once a dream is now easy!\n\nLua is an actual scripting language that is fun to use, unlike Vimscript. As such, I was able to add custom functionality\nthat I would have struggled to add in Vimscript.\n\nFor example, I am a big fan of combining `set number relativenumber` such I can see the current line number and also\nhave the surrounding line numbers be the number of lines relative to the current line. This allows for easier composition\nof linewise movements while knowing where the heck I am! But, sometimes I want normal line numbering and other times, I\nwant no numbering at all. I had a very nasty Vimscript function that could do this that I despised until I rewrote it in\nLua!\n\n<GithubFile url=\"https://github.com/eligundry/dots/blob/eeed2f2fcbf3c1aa02b6981e2abea746b1c50cd6/config/nvim/init.lua#L647-L684\" />\n\nBelow is a video of me calling that function with <kbd>,rn</kbd> in normal mode.\n\n<DemoVideo\n  src=\"/video/neovim-lua/numbering-modes.webm\"\n  alt=\"Video showing the different Vim numbering modes being cycled through with ,rn\"\n/>\n\nAnother example is how I was able to finally make sense of my love of [Vim's `autochdir`](https://vim.fandom.com/wiki/Set_working_directory_to_the_current_file)\nwith how plugins work with it. I will let the following code block explain what I mean.\n\n<GithubFile url=\"https://github.com/eligundry/dots/blob/eeed2f2fcbf3c1aa02b6981e2abea746b1c50cd6/config/nvim/init.lua#L802-L850\" />\n\nFor my final example, I technically had this working in Vimscript, but I really want to show it off! I am the biggest fan\nof [Hipster Ipsum](https://hipsum.co/) for dummy text. I made Vim function that call's it's HTTP API and inserts the copy\ninto the file!\n\n<GithubFile url=\"https://github.com/eligundry/dots/blob/eeed2f2fcbf3c1aa02b6981e2abea746b1c50cd6/config/nvim/init.lua#L852-L857\" />\n\nBy pressing <kbd>,hi</kbd>, I get a paragraph of the finest hipsum!\n\n<DemoVideo\n  src=\"/video/neovim-lua/hipster-ipsum.webm\"\n  alt=\"Video showing how to insert Hipster Ipsum with ,hi in Neovim\"\n/>\n\n# Conclusion\n\nSwitching my Neovim config to Lua was a fun experience that yielded pretty big advances in how I work. I can search more\neasily, I have more IDE features than I know what to do with and I definitely feel \"with it.\"\n\nAt the same time, my Neovim still breaks randomly when I upgrade packages or Neovim itself. I still need to tend to it\nlike a garden. I wish I had chosen an editor that it more stable than what I have now, but like I said, I can't `:quit`\nVim!\n\nAlso, I just want to say goodbye to [Chad](https://www.linkedin.com/in/chadnickell/). He's moving on to bigger and better\nthings. He was responsible for hiring me at Chord and has been an absolute delight to work with. Best of luck, bud!",
    "version": "1.0"
  },
  "description": "Lua is now my best friend for configuring Neovim.",
  "path": "/blog/neovim-lua/",
  "publishedAt": "2023-02-21T04:00:00.000Z",
  "site": "https://eligundry.com",
  "tags": [
    "code"
  ],
  "textContent": "⚠️ Warning: This post is very cringe as I hate talking about my tools instead of my work. You've been warned.\n\nLooking over my notes for this post, it seems like I've been using Vim in some sort or another for over a decade at this\npoint? Time flies when you can't  Vim. Folks, I'll be here all week.\n\nI guess I switched to Neovim at some point in 2014? One of the main reasons that Neovim exists is that mainline Vim,\nhistorically, resisted allowing configuration in languages that were not Vimscript. Vimscript is… not a good language.\nPeople that love it, love it, all the more power to them, but I am not one of them. I recall at some point during my\nmainline Vim days using some plugins that were written in Python, but those seem to break all the time.\n\nAll this time though, I have been maintaining a very detailed and commented Vim config in Vimscript.\nI have put a lot of sweat equity into this config! Perfecting it got me fired from a job in 2012. Lesson learned, you\nmove on. I even kept it backwards compatible with ancient versions of Vim that I will never encounter in reality. It was fun and made me feel\nlike a hacker. I would see people on Reddit talking about their configs in Lua and I would just tune them out. I have\nmy config and it's already held together with Popsicle sticks and glue. If I even look at it wrong, I'll lose a day of\ndevelopment time.\n\nAt some point in 2018, I discovered coc.nvim and it was a revelation. It was added\nVisual Studio Code's basic code completion features to my super custom Vim config! I could jump to definition!\nI could have accurate code completion! It probably does a lot more IDE like things, but I'm a simple man and that's\nall I need. My config would still break from time to time, but at least I became 1.3x more efficient.\n\nI started working at Chord in 2022 and discovered that, for the first time, I had coworkers\nthat used Vim! I started a little  channel and we got to sharing tips and configs. It's always nice to find\npeople like you.\n\nOn a Friday evening in November, Chad posts his brand new Neovim config\nwritten in Lua. Well that just pushed all of us over the Lua cliff and we all spent our weekend updating our configs.\n\nYou can checkout how I did this in this pull request!\n\nChad's base config was a great base\nthat I was able crib into my config as I converted it to Lua. It had all the code completion plugins that I needed to\nreplace coc.nvim. At this point, he had his configs in a bunch of different files, which I have done in the past and\nhated as it's impossible to find anything easily, but I was able to work around that. (It should be noted that I mentioned\nmy experience with multiple files in the past and he converted his config to a single file).\n\nWithout any further ado, let's dive into what this conversion gave me!\n\nI got a chance to switch up my plugins!\n\nSince I was moving from Vimscript to Lua, it only made sense that I switch some of my old plugins to newer, actively\nmaintained Lua alternatives. Here are some packages I upgraded to.\n\nplug.vim ➡️ packer.nvim\n\nI like Packer's syntax and how I can inline package configs right next to how I install them. Since I started porting,\nit seems that the new hotness is lazy.nvim, which I suppose I will check out 3\nyears from now.\n\nPacker seems to have the ability to \"snapshot\" configs that allow you to rollback in case package upgrades bork your\nsetup, but I haven't dived into that just yet.\n\ncoc.nvim ➡️ Various LSP plugins\n\ncoc.nvim is pretty nice. It manages all of the language server stuff for you in it's own config format that is closer\nto Visual Studio Code than Neovim. It was great when the Neovim LSP space was somewhat immature. Today though, Neovim's\nLSP support is now first class it makes sense to use it directly.\n\nUnfortunately, using Neovim's LSP directly does not free you from installing plugins. No, you will install many plugins\nand like it. Luckily, they all seem to work together. Here's a sampling of said plugins:\nmason.nvim: This manages the installation of the desired LSP plugins.\n  Ex: Typescript server, linting, gopls.\nnvim-cmp: This is what powers all autocompletion prompts as you type. What makes\n  this better than coc.nvim's completions is that it works when in insert mode, searching, command line completions and\n  more!\nnull-ls: This the glue that binds the LSPs that Mason installs\n  to the editor. It's slightly annoying to get going if you don't read the docs (which I wasn't when copying the config),\n  but once you do, you'll be like a Greek god of Vim.\n\nHere's a video of it all at work. Notice all the code completion and the auto formatting. It really works great!\n\nctrlp ➡️ telescope\n\nTelescope is a revelation! It's the single coolest thing that I introduced into my config in this sprint. It allows for\nsearching in all sorts of ways. I used to use ctrlp to do fuzzy path searching exclusively and was planning on continuing\nto use it in this config, but ctrlp kept crashing this Vim setup like 20% of the time (and always when I hadn't saved\na file 😤). I decided to map  to Telescope's find files function. Not only does it work exactly the same,\nI get a little preview of the file. And Telescope can search files for strings, search active buffers and more!\n\nYou have to see it to believe it!\n\nWhat was once a dream is now easy!\n\nLua is an actual scripting language that is fun to use, unlike Vimscript. As such, I was able to add custom functionality\nthat I would have struggled to add in Vimscript.\n\nFor example, I am a big fan of combining  such I can see the current line number and also\nhave the surrounding line numbers be the number of lines relative to the current line. This allows for easier composition\nof linewise movements while knowing where the heck I am! But, sometimes I want normal line numbering and other times, I\nwant no numbering at all. I had a very nasty Vimscript function that could do this that I despised until I rewrote it in\nLua!\n\nBelow is a video of me calling that function with ,rn in normal mode.\n\nAnother example is how I was able to finally make sense of my love of Vim's \nwith how plugins work with it. I will let the following code block explain what I mean.\n\nFor my final example, I technically had this working in Vimscript, but I really want to show it off! I am the biggest fan\nof Hipster Ipsum for dummy text. I made Vim function that call's it's HTTP API and inserts the copy\ninto the file!\n\nBy pressing ,hi, I get a paragraph of the finest hipsum!\n\nConclusion\n\nSwitching my Neovim config to Lua was a fun experience that yielded pretty big advances in how I work. I can search more\neasily, I have more IDE features than I know what to do with and I definitely feel \"with it.\"\n\nAt the same time, my Neovim still breaks randomly when I upgrade packages or Neovim itself. I still need to tend to it\nlike a garden. I wish I had chosen an editor that it more stable than what I have now, but like I said, I can't \nVim!\n\nAlso, I just want to say goodbye to Chad. He's moving on to bigger and better\nthings. He was responsible for hiring me at Chord and has been an absolute delight to work with. Best of luck, bud!",
  "title": "Friendship ended with Vimscript",
  "updatedAt": "2025-02-12T02:34:47.000Z"
}