mirror of
https://github.com/jbranchaud/til
synced 2026-01-06 16:48:01 +00:00
Add Jump Between Changes In Current File as a Neovim TIL
This commit is contained in:
46
neovim/jump-between-changes-in-current-file.md
Normal file
46
neovim/jump-between-changes-in-current-file.md
Normal file
@@ -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).
|
||||
Reference in New Issue
Block a user