Tips for configuring Neovim for Claude Code

How to setup Neovim to see Claude Code's changes instantly and paste code with file locations back into Claude Code

Author

Richard Gill

Date published

I switched from VSCode to Neovim last year. When Cursor came out I was tempted to switch back, but I've grown to love Neovim as an editor, and stubbornly decided I wasn't willing to give it up without a fight.

Most open source Cursor-like plugins for Neovim are worse than the VC-backed, commercial offerings. But thankfully, 'coding agents' like Claude Code allowed me to stay safely in my tmux terminal.

But my Neovim setup was still missing a couple of features:

  • I wanted to see Claude Code's changes immediately.
  • I wanted a fast way in Neovim to point Claude Code to a block of code.

Auto reload Claude Code's changes

By default Neovim doesn't update buffers when files are written outside of Neovim. You can run :e to reload files manually. The autoread option reloads files, but it only triggers on certain events like switching windows or focusing the terminal.

LazyVim has an autocmd that runs checktime to reload files on FocusGained and similar events. This helps when you switch away and come back to your buffer, but it doesn't help when you have a file open in a buffer, and the agent writes files in the background.

The solution is to reload buffers on:

  • FocusGained, TermLeave, BufEnter, WinEnter, CursorHold, CursorHoldI autocmd events.
  • File system changes in Neovim's current working directory.
    • This reloads buffers which are visible in the active Neovim 'tab' (we'll come back to this!)

I skip buffers I've modified in Neovim so I don't lose my changes. I also ignore special buffers for plugins like diffview.

Here's the config: hotreload.lua

To watch the filesystem for changes I wrote directory-watcher.lua which uses the native uv fs_event API to detect file changes.

Auto reload git diff changes in real time

Like any other engineer in 2025, I spend my days reviewing and correcting code generated by coding agents. I use diffview.nvim for diffing because it lets me use neovim to edit code inline right in the diff buffer. It's similar to the VSCode source code panel, and is still the best Neovim diff experience I've found with inline editing.

Unfortunately, diffview doesn't reload the tracked / untracked / staged files when edits are made outside of Neovim by Claude Code.

The solution is to call an diffview's update_files() function whenever there are changes in .git/ or non-gitignored files. This refreshes the left-hand panel showing you git status info without moving your cursor.

Here's the config: git-diff_diffview.lua

Diffview runs inside a Neovim tab, and the hotreload.lua config reloads visible buffers in the active tab, so you see Claude Code's changes appear live within the diffview.

Yanking with file paths for pasting into Claude Code

When chatting with Claude Code, I often want to reference code in a file and also point the agent to where the code is.

To help with this I created a new keybinding to yank the relative path along with the code.

Example pasted content:

This works great with Claude code, which immediately has the context of both the code and the file it's in.

Here's the config: yank.lua

The keymaps are in keymap.lua: I use <leader>yr for relative path and <leader>ya for absolute path.

Official Neovim support

I'm hoping a more 'official' Neovim solution is available soon. In the meantime, these tweaks really improve the experience of working with Claude Code for me.

The nice part is this approach is agent-agnostic - it'll work with Claude Code, Aider, OpenCode, Crush, Gemini, Codex or whatever comes next and with minimal plugins (diffview aside).

Related Posts