Posts tagged: vim

All posts with the tag "vim"

29 posts latest post 2026-01-04
Publishing rhythm
Jan 2026 | 1 posts

Today I discovered vim-speeddating by tpope. I’m sure I’ve seen years ago but it did not click for my workflow until today. I often go through pictures from my phone for the past few days and make Posts tagged: shots posts, but I want to date them to about when the image was taken most of the time. This allows me to quickly bump days up and down using c-a and c-x even around the new year.

Sound on, listen to those new switches.

Vim :noa is a command that runs what you call without autocommands on. This is typically used when you have some BufWritePre commands for formatting, most auto formatters are implemented this way in vim. It can be super useful if you have something like a yaml/json file that you have crafted perfectly how you want it, maybe it has some source code for a small script or sql embeded and your formatter wants to turn it into one line. You could get a better formatter, but for these one off cases that aren’t a big bother to me I run :noa w.

:noa w

fixed long standing nvim startup error

Here’s the diff, this is it. local M = {} M.setup = require("waylonwalker.setup") M.settings = require("waylonwalker.settings") + M.lazy = require("waylonwalker.lazy") M.options = require("waylonwalker.options") M.globals = require("waylonwalker.globals") M.keymap = require("waylonwalker.keymap") - M.lazy = require("waylonwalker.lazy") M.autocmds = require("waylonwalker.autocmds") M.util = require("waylonwalker.util") M.plugins = require("waylonwalker.plugins") M.snippets = require("waylonwalker.snippets") return M The error # [1] On first install of my dotfiles I’m presenting with this flashbang of an error filling the screen with red background. Its kinda hard to read, I’m not deep into lua and reading their tracebacks. It pops up in this pager that if I scroll too far it quits and the error is gone before I know what it is or how it got there. [2] For the longest time it just felt like it randomly showed up without much warning. I sent ai at the issue # [3] I...

When I want to put a date in a document like a blog post from vim I use !!date from insert mode. Note that entering !! from normal mode puts you in command mode with :.! filled out. This runs a shell command, i.e. date for this example.

It outputs the following

Fri Jan 31 08:46:11 PM CST 2025

You can also pass in a date such as tommorrow by pasdding in the -d date -d tomorrow.

It outputs the following

Sat Feb 1 08:53:20 PM CST 2025

codeium just taught me this one with autocomplete

:put =strftime('%Y-%m-%d')

This outputs the following

2025-01-31

What I like about the :put =strftime( method is that you can add a format, but that is a lot more for me to remember than !!date

A few weeks later #

I’m going through a bunch of blog posts and dont want my date formats to change to the Wed Feb format so I broke down and made these keybindings. I think I’m still going to be using .!date a lot, but these keybindings will be nice for editing blog post frontmatter.

set("n", "<leader>dd", "<cmd>put =strftime('%Y-%m-%d')<cr>", { noremap = true, silent = true })
set("n", "<leader>dt", "<cmd>put =strftime('%Y-%m-%d %H:%M:%S')<cr>", { noremap = true, silent = true })
  • dd 2025-02-12
  • dt 2025-02-12 12:53:47
  • :.!date Wed Feb 12 12:53:47 PM CST 2025

nvim-manager

I recently built a cli application as a nearly-one-shot-app called nvim-manager [1]. It manages your nvim dotfiles install. [2] Why # [3] How is nvim manager any better # [4] nvim-manager allows you to install pinned versions of your dotfiles, your friends dotfiles, and distros in ~/.config. This allows you to have stable versions that will not break installed while you change things. I’m sure most of us have experienced the pain of installing one plugin, only to update all of your plugins and break something. Or, you have small changes on every machine you use, because they are all just a bit different and now you have big merge conflicts to deal with. All of this aside you can install a distro to get you by, or a known working version of your own dotfiles. So all these versions in ~/.config # [5] ya, thats the magic of NVIM_APPNAME, I can boot up any of these intalled working versions in an instant with NVIM_APPNAME=nvim-waylonwalker-v0.0.1 nvim. I can still cowboy up an...
Support regex substitution command · Issue #2232 · helix-editor/helix Support regex substitution, comparable to vim :s or VSCode search & replace. I propose supporting regex replacements for selection s, files/, and the workspace scopes + /. This could be acc... GitHub · github.com [1] Here is a really good vim substitute with regex capture groups, saving this one for a rainy day. * Reading 1: This is a title to a link * Reading 2: This is another title :%s/\v(: )(.+)$/\1\[\2\]\( * Reading 1: [This is a title to a link]( * Reading 2: [This is another title]( References: [1]: https://github.com/helix-editor/helix/issues/2232#issuecomment-1228632218

Vim has a handy feature to format text with gq. You can use it in visual mode, give it a motion, or if you give it gqq it will format the current line. I use this quite often while writing in markdown, I do not use softwraps in vim, so gqq quickly formats my current line into a paragraph. Once I have done this for a single line one time I typically switch to the motion for around paragraph gqap to format the whole paragraph and not just the current line.

before formatting #

vim-gq-20240805122634078.webp

after formattting #

vim-gq-20240805122700026.webp

Refactoring one line links into wikilinks

Previously I had setup a feature of my website to expand one line links into a card. This was not a standard, even to the point that some formatters wrap the links with , thus breaking my custom plugin. Moving to the wikilink standard will allow my markdown posts to work accross more site builders without custom integrations. Expand One Line Links [1] What is a wikilink # [2] Wikilinks are standard to a lot of wikis written in markdown. markdown-it-wikilinks [3] The wikilink syntax is a slug wrapped in double square brackets. [[ slug ]] Marksman lsp will even autocomplete these for you, its pretty sweet. Note I recently implemented hover for wikilinks and and am pretty stoked about the result. Check this one out sick wikilink hover [4]. Vim Quickfix # [5] You could use vimgrep to fill your quickfix list will all of the one line links but I am less familiar with vimgrep and kept missing posts for some reason, I think it was something in my file glob missing some directori...
2 min read
![[None]] Install it { "ThePrimeagen/harpoon", branch = "harpoon2", dependencies = { "nvim-lua/plenary.nvim" }, config = function() require("waylonwalker.plugins.harpoon").setup() end, }, harpoon config local harpoon = require("harpoon") M = {} M.setup = function() -- REQUIRED harpoon:setup() -- REQUIRED vim.keymap.set("n", "<F10>", function() harpoon:list():append() end) vim.keymap.set("n", "<F9>", function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) vim.keymap.set("n", "<F1>", function() harpoon:list():select(1) end) vim.keymap.set("n", "<F2>", function() harpoon:list():select(2) end) vim.keymap.set("n", "<F3>", function() harpoon:list():select(3) end) -- these are cnext/cprev -- vim.keymap.set("n", "<F4>", function() harpoon:list():select(4) end) -- vim.keymap.set("n", "<F5>", function() harpoon:list():select(5) end) vim.keymap.set("n", "<F6>", function() harpoon:list():select(6) end) -- Toggle previous & next buffers stored within Harpoon list vim.keymap.set("n", "<F7>", function() harpoon:list():prev() end) vim.keymap.set("n", "<F8>", function() harpoon:list():next() end) -- basic telescope configuration local conf = require("telescope.config").valu...
- I found this statement quite intriguing. multi-cursors are just macros. This is quite a philisophical video and mostly prime talking about the things that make vim vim, and what prime needs in and editor vs what he can live without.
- I’ve heard prime say just give it the one eyed fighting kirby so many times, and execute it few times, and there is no way to find it online, so this will be the link that I will come to, when I need to remember what @theprimeagen means when he says Give it the one eyed fighting kirby. :s/\(.*\);/console.log(\1) So what is this? # [1] This is a vim substitute comand to replace text in the buffer. the one eyed fighting kirby is a regex capture group to capture everything between matches, and assign it a value to place back in after the match. substitute in a nutshell, :s/<what you want to replace>/<what you want to replace with> More examples # [2] Here is a contrived example of text. here there from here go there here = some_fuction(there) Now for some reason I want to switch all of the words here and there. I can do that with three capture groups, \1 is here, \2 is everything between, \3 is there. :%s/\(here\)\(.*\)\(there\)/\3\2\1 Just give it the one eyed fighting kirby ~Prime still struggling # [3] I thought this explaination from phind was good and more verbose than mine. --- describe this vim substitute regex :%s/(here)(.)(there)/\3\2\1 ANSWER | PHIND V9 M...

So after months of fighting with gf not going to template files, I finally decided to put in some effort to make it work.

This was the dumbest keybind in my config, that I copied from someone else without understanding it.

What I am trying to do #

I have jinja templates in a directory called templates. I want to bind gf to open a template file, but it is trying to open a new file ./base.html

{% extends "base.html" %}
{% if request.state.user %}
    {% block title %}Fokais - {{ request.state.user.full_name }} {% endblock %}
{% else %}
    {% block title %}Fokais {% endblock %}
{% endif %}
{% block content %}
    {% if request.state.user %}
        <h1 id="title"
            class="inline-block mx-auto text-5xl font-black leading-loose
            text-transparent bg-clip-text bg-gradient-to-r from-red-600
            via-pink-500 to-yellow-400 ring-red-500 text-shadow-xl
            text-shadow-zinc-950 ring-5">
            {{ request.state.user.full_name }}
        </h1>
    {% endif %}
    {% include "me_partial.html" %}
{% endblock %}

What did not work #

I tried all sorts of changes to my path, but it still didn’t work.

vim.api.nvim_command("set path+=templates/**")

What I found #

after digging into my keymap I found that I had remaped gf to edit years ago. This works great if the file is in your current directory, and if it’s not it makes the file. This bind completely breaks vim’s ability to :find files and was a terrible keybind that I added probably from someone else years ago and have literally never used this feature. If gf opens an empty file I always close it and assume that vim failed to :find the file.

-- Allow gf to open non-existent files
set("", "gf", ":edit <cfile><CR>")

Yes, after that fix I still needed to adjust my path #

I ended up with the following in my options.lua.

-- look for jinja templates in the templates directory
vim.opt.path:append("templates/**")
https://neovim.io/doc/user/diagnostic/ neovim.io [1] Clear out lsp diagnostics in nvim. lua vim.diagnostic.reset() References: [1]: https://neovim.io/doc/user/diagnostic.html#vim.diagnostic.reset()
Bob Belderbos (@bbelderbos) on X Forget Python for a sec, here's how Vim helped me out today … 💪 📈 Ever felt like you needed a quick string replacement without diving into a script? Here's a Vim trick I just used … I w… X (formerly Twitter) · twitter.com [1] I need to learn regex capture groups better. This is so dang powerful. I really like the \v that bob uses here, it really does cut down on the terseness of all the special characters. I wanted to replace all occurrences of: name,[email protected],0,171,,2023-09-21 With: name,[email protected] Easy to do with Python, but what about a bit of > regex in Vim? :%s/\v([^,]+,[^,]+),.*/\1/ References: [1]: https://twitter.com/bbelderbos/status/1709525676154368055
External Link github.com [1] neovim stopped formatting on save for me awhile ago and I have just been dealing with it. looks like there may have been an api change, idk. I had to make this update.4 - vim.lsp.buf.format() + vim.lsp.buf.format({async=false}) References: [1]: https://github.com/jose-elias-alvarez/null-ls.nvim/wiki/Formatting-on-save#code
🛠️ Installation | LazyVim You can find a starter template for LazyVim here lazyvim.org [1] Lately in 2023 I have been leaning on lazyvim for my new setups where I am not necessarily ready to drop my full config. It’s been pretty solid, and comes with a very nice setup out of the box, the docs are pretty fantastic as well. References: [1]: https://www.lazyvim.org/installation

extending vim with shell commands

Vimconf 2022 The pitch # [1] Extending vim does not need to be complicated and can be done using cli tools that you might already be comfortable with. Examples, setting up codeformatters with autocmds, using lf/ranger as a tui file manager, generating new files using a template framework like cookiecutter/copier/yeoman, using ag to populate your quickfix. run a command # [2] vimconf!!<esc>!!figlet formatters # [3] local settings = require'waylonwalker.settings' M.waylonwalker_augroup = augroup('waylonwalker', { clear = true }) M.format_python = function() if settings.auto_format.python then vim.cmd('silent execute "%!tidy-imports --black --quiet --replace-star-imports --replace --add-missing --remove-unused " . bufname("%")') vim.cmd('silent execute "%!isort " . bufname("%")') vim.cmd('silent execute "%!black " . bufname("%")') end end autocmd({ "BufWritePost" }, { group=M.waylonwalker_augroup, pattern = { "*.py" }, callback = M.format_python, }) File Navigation # [4...
1 min read

With the latest release of version of nvim 0.8.0 we get access to a new winbar feature. One thing I have long wanted somewhere in my nvim is navigation for pairing partners or anyone watching can keep track of where I am. As the driver it’s easy to keep track of the file/function you are in. But when you make big jumps in a few keystrokes it can be quite disorienting to anyone watching, and having this feedback to look at is very helpful.

“cybernetic soldier working on a rusting tape machine robot, cinematic lighting, detailed, cell shaded, 4 k, warm colours, concept art, by wlop, ilya kuvshinov, artgerm, krenz cushart, greg rutkowski, pixiv. cinematic dramatic atmosphere, sharp focus, volumetric lighting, cinematic lighting, studio quality” -s50 -W832 -H416 -C6.0 -Ak_lms -S2841371882

winbar #

nvim exposes the winbar api in lua, and you can send any text to the winbar as follows.

vim.o.winbar = "here"

You can try it for yourself right from the nvim command line.

:lua vim.o.winbar = "here"

Now you will notice one line above your file with the word here at the very beginning.

Clearing the winbar #

If you want to clear it out, you can just set it to an empty string or nil.

:lua vim.o.winbar = ""
:lua vim.o.winbar = nil

Setting up nvim-navic #

You will need to install nvim-navic if you want to use it. I added it to my plugins using Plug as follows.

call plug#begin('~/.local/share/nvim/plugged')
Plug 'SmiteshP/nvim-navic'
call plug#end()

Note! nvim-navic does require the use of the nvim lsp, so if you are not using it then maybe this won’t work for you.

I created an on_attach function long ago, cause that’s what Teej told me to do. Now I am glad I did, because it made this change super easy.

local function on_attach(client, bufnr)
    if client.server_capabilities.documentSymbolProvider then
        navic.attach(client, bufnr)
    end
end

Then you need to use that on_attach function on all of the lsp’s that you want navic to work on.

Then in a lua file you need to setup the winbar, for now I put this in my lsp-config settings file, but eventually I want to move my settings to lua and put it there.

vim.o.winbar = " %{%v:lua.vim.fn.expand('%F')%}  %{%v:lua.require'nvim-navic'.get_location()%}"

What my winbar looks like #

What I have right now is everything someone who is watching would need to know to navigate to the same place that I am in the project.

 waylonwalker/app.py   Link >  on_click
nvim-navic-example.webp

Diff #

Here are the changes that I made to to my plugins list and my lsp-config to get it.

 /home/u_walkews/.config/nvim/plugins.vim
call plug#begin('~/.local/share/nvim/plugged')
+Plug 'SmiteshP/nvim-navic'
#  /home/u_walkews/.config/nvim/lua/waylonwalker/lsp-config.lua
-local function on_attach() end
+local navic = require("nvim-navic")
+local function on_attach(client, bufnr)
+    if client.server_capabilities.documentSymbolProvider then
+        navic.attach(client, bufnr)
+    end
+end
+
+vim.o.winbar = " %{%v:lua.vim.fn.expand('%F')%}  %{%v:lua.require'nvim-navic'.get_location()%}"

GH commit #

If you want to see the change on GitHub, here is the diff

nvim-navic-setup-gh-diff.webp

How to vimgrep over hidden files.

I needed to delete all build pipeline steps that were named upload docs. I currently have about 60 projects running from the same template all running very similar builds. In the past I’ve scripted out migrations for large changes like this, they involved writing a python script that would load the yaml file into a dictionary, find the corresponding steps make the change and write it back out.

Today’s job was much simplar, just delete the step, were all steps are surrounded by newlines. My first thought was to just open all files in vim and run dap. I just needed to get these files:positions into my quickfix. My issue is that all the builds reside within hidden directories by convention.

The issue #

variability

After searching through all the projects it was clear that all the steps were in their own paragraph, though I was not 100% confident enough to completely automate it, and the word upload docs was in the paragraph.

some were a two liner

- name: upload docs
  script: aws s3 ...

Some had a variation in the name

- name: upload docs to s3
  script: aws s3 ...

some were more than 2 lines.

- name: upload docs
  script: |
    aws s3 ...

some used a different command.

- name: upload docs
  script: |
    python ...

Templates are great #

but they change

Templates are amazing, and tools like cookiecutter and copier are essential in my workflow, but those templates change over time. Some things are a constant, and others like this one are an ever evolving beast until they are tamed into something the team is happy with.

vimgrep over hidden files #

I know all the files that I care to search for are called build.yml, and they are in a hidden directory.

:args `fd -H build.yml`
:vimgrep /upload docs/ ##

Once opened as a buffer by using args, and a handy fd command I can vimgrep over all the open buffers using ##

Open buffers are represented by ##

Now I can just dap and :cnext my way through the list of changes that I have, and know that I hit every one of them when I am at the end of my list. And can double check this in about 10s by scrolling back through the quickfix list.

Vim points achieved #

You’re not a true vim enthusiast until you have spent 10 minutes writing a blog post about how vim saved you 5 minutes. Check out all the other times this has happened to me in the vim tag.