I write code and occasionally blog posts.

Customizing Vim

I’ve been using vim (specifically neovim) for over a year, I really enjoy how customizable it is, though up until today, I’ve only customized it through plugins made by other people. Today I wrote two Lua functions to streamline my workflow. I’m not very familiar with Lua but it was quite easy to pick up.

First is a function to split my window so it would have two side by side, and a smaller one at the bottom, which gets turned into a terminal.

local createcodeenv = function ()
  vim.cmd('wincmd j')
  local win = vim.api.nvim_get_current_win()
  local height = vim.api.nvim_win_get_height(win)
  vim.api.nvim_win_set_height(win, height - 15)
  vim.cmd('wincmd k')
  win = vim.api.nvim_get_current_win()
  local buf = vim.api.nvim_get_current_buf()
  vim.api.nvim_win_set_buf(win, buf)
vim.api.nvim_create_user_command('CodeEnv', createcodeenv, {})

Second is a function to bind writing a file and returning to Netrw (the file explorer) to one command, :We.

local writeGoToNetrw = function()
vim.api.nvim_create_user_command('We', writeGoToNetrw, {})

Both of these were things I did manually basically every time I used vim. Defining custom commands to make them easier was a fun learning experience, I look forward to learning more about customizing vim.