Skip to content

Feature: Easy navigation from diff view to actual file in repository #8

Description

@hay-kot

Description

Add a quick way to jump from the diff view to the actual file in the repository at the corresponding line.

Use Cases

  1. Edit the file: See an issue in diff, jump to file to fix it
  2. Deeper context: View surrounding code not shown in diff
  3. Cross-reference: Check how code is used elsewhere
  4. Quick fixes: Make changes directly while reviewing

Proposed Implementation

Commands

:DiffReviewOpenFile      " Open file in new buffer
:DiffReviewOpenFileSplit " Open in split
:DiffReviewOpenFileVsplit " Open in vertical split

Keybindings (in diff window)

  • gf - Open file at current line (follows Neovim convention)
  • <C-w>f - Open file in horizontal split
  • <C-w>gf - Open file in vertical split
  • gF - Open file at exact line number from diff

Behavior

  1. Detect current file from diff header
  2. Map diff line to actual file line number
  3. Open file and position cursor at corresponding line
  4. Preserve diff view (don't close review)

Line Number Mapping

For modified lines:

  • Added lines (+): Jump to new file line number
  • Deleted lines (-): Jump to old file line number (if file still exists)
  • Context lines: Jump to current line number

Edge Cases

  • File doesn't exist locally (deleted/not checked out): Show error
  • Line number out of sync (file changed): Open at approximate location
  • Binary files: Open but warn can't position cursor
  • New files: Open at line 1

Configuration

require('diff-review').setup({
  keymaps = {
    diff = {
      open_file = 'gf',
      open_file_split = '<C-w>f',
      open_file_vsplit = '<C-w>gf',
    }
  }
})

Benefits

  • Seamless workflow between review and editing
  • Follows Neovim conventions (gf)
  • Enables quick fixes during review
  • Better understanding of full context

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions