From 5ce5eccb0ac2266baf18215d0b25a4f460efd1ad Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Sun, 26 Oct 2025 16:52:24 -0500 Subject: [PATCH] Add Jump Between Changes In Current File as a Neovim TIL --- README.md | 3 +- .../jump-between-changes-in-current-file.md | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 neovim/jump-between-changes-in-current-file.md diff --git a/README.md b/README.md index ba9b567..5d51813 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186). -_1666 TILs and counting..._ +_1667 TILs and counting..._ See some of the other learning resources I work on: @@ -748,6 +748,7 @@ If you've learned something here, support my efforts writing daily TILs by - [Allow Neovim To Copy/Paste With System Clipboard](neovim/allow-neovim-to-copy-paste-with-system-clipboard.md) - [Create User Command To Open Init Config](neovim/create-user-command-to-open-init-config.md) +- [Jump Between Changes In Current File](neovim/jump-between-changes-in-current-file.md) - [Run A Lua Statement From The Command Prompt](neovim/run-a-lua-statement-from-the-command-prompt.md) - [Run nvim With Factory Defaults](neovim/run-nvim-with-factory-defaults.md) - [Set Up Vim-Plug With Neovim](neovim/set-up-vim-plug-with-neovim.md) diff --git a/neovim/jump-between-changes-in-current-file.md b/neovim/jump-between-changes-in-current-file.md new file mode 100644 index 0000000..84d2ec4 --- /dev/null +++ b/neovim/jump-between-changes-in-current-file.md @@ -0,0 +1,46 @@ +# Jump Between Changes In Current File + +With the [gitsigns.nvim plugin](https://github.com/lewis6991/gitsigns.nvim) for +Neovim, I get some handy Git-related capabilities like gutter highlighting of +additions, deletions, and changes to lines in the current file. These contiguous +sections of modification to the versioned state of a file are called hunks. + +Here are two mappings (in Lua) for gitsigns that allow me to jump to the next +(`]h`) or previous (`[h`) hunk in the current file. + +```lua +---@type LazyKeysSpec[] +M.gitsigns_mappings = { + + -- Navigation + { + ']h', + function() + if vim.wo.diff then + vim.cmd.normal { ']c', bang = true } + else + require('gitsigns').nav_hunk 'next' + end + end, + desc = 'Next Hunk', + }, + + { + '[h', + function() + if vim.wo.diff then + vim.cmd.normal { '[c', bang = true } + else + require('gitsigns').nav_hunk 'prev' + end + end, + desc = 'Prev Hunk', + }, +} +``` + +This is particularly useful when I've just opened a big file and I want to jump +directly to active changes in that file. + +I got this mapping directly from [Dorian's +dotfiles](https://github.com/dkarter/dotfiles).