Repository navigation
Using Git Elegantly in Vim
Git and Vim are both powerful productivity tools for developers. However, when working inside Vim, frequently switching to the terminal to run Git commands (such as git status, git add -p, git commit) can interrupt your flow and break your focus.
With LeaderF’s built-in Git integration, you can bring the entire Git workflow directly into Vim and significantly improve your efficiency.
This article focuses on one core command:
:Leaderf git status
Run the command above in Vim to open the following view:

The screen is divided into two main panels:
The left side is the Navigation Panel, which displays the output of git status in a tree structure, grouped by file state:
- Staged Changes: Files already staged (ready to commit)
- Unstaged Changes: Modified files not yet staged
- Untracked Files: Files not tracked by Git
The right side is the Diff View Panel, which shows detailed changes of the selected file. It supports two modes:
- Unified Diff View
Provides character-wise diff highlighting, making differences more precise and visually clear. Traditional git diff does not highlight character-wise changes.
- Side-by-Side Diff View
Advantage: More intuitive for comparing code differences line by line.
- The left panel handles file selection and state management
- The right panel handles diff visualization and fine-grained operations
Together, they form a smooth and efficient Git workflow inside Vim.
In the Navigation Panel, you can perform the following operations:
| Key | Action | Description |
|---|---|---|
s |
Stage / Unstage file | On an unstaged file → move it to staged; on a staged file → move it back to unstaged |
d |
Discard changes | Discard file changes (with confirmation) |
D |
Force discard | Discard changes without confirmation (use with caution) |
r |
Refresh | Refresh the file tree when Git status changes externally |
Enter / o
|
Open diff view | View detailed changes of the file |
Notes:
-
s,d,Dalso work on directories (including the repository root) - Running
dorDon Untracked Files will delete the file - Press
F1in the panel to view more shortcuts
In the Diff View, you can operate on individual hunks (code blocks):
| Key | Action | Description |
|---|---|---|
s |
Stage/Unstage current hunk | Move current hunk between staged and unstaged |
S |
Stage/Unstage all hunks | Apply operation to all hunks in the file |
d |
Discard current hunk | Discard changes in current hunk (with confirmation) |
D |
Force discard current hunk | Discard without confirmation (use with caution) |
]c |
Next hunk | Jump to next hunk |
[c |
Previous hunk | Jump to previous hunk |
| Key | Action | Description |
|---|---|---|
< |
Back to Navigation Panel | Reopen if closed and jump to current file |
Enter |
Open file | Jump to file for editing |
let g:Lf_GitKeyMap = {
\ 'previous_change': '[c',
\ 'next_change': ']c',
\ 'edit_file': '<CR>',
\ 'open_navigation': '<',
\ 'stage_unstage_hunk': 's',
\ 'stage_unstage_all_hunk': 'S',
\ 'discard_hunk': 'd',
\ 'discard_hunk_no_prompt': 'D',
\ }
Once you have staged the desired changes in the Navigation Panel:
- Press
cto start committing - A new window opens for writing the commit message
- Enter your message
- Save and close the window
- The commit is completed
To cancel the commit, simply clear the message and close the window.
- Check status
-
Review changes
- Open
bug_fix.py - Use
]cto navigate hunks - Identify bug fix vs debug code
- Open
-
Stage selectively
- Press
son bug fix hunks - Leave debug code unstaged
- Press
-
Handle new feature
- Press
<to return - Open
new_feature.py - Press
Sto stage all hunks
- Press
-
Commit
- Press
c - Enter message:
- "Fix login validation bug and add search feature"
- Save and exit
- Press
Everything is done inside Vim without breaking context.
| Operation | CLI | LeaderF |
|---|---|---|
| View status |
git status (plain text) |
Visual file tree |
| Partial staging | git add -p |
Press s
|
| Discard changes | manual commands |
d / D
|
| Navigate changes | manual scrolling |
]c / [c
|
With Leaderf git status, you get a complete Git workflow inside Vim:
- Visual Git status
- File-level staging/unstaging
- Hunk-level fine control
- Quick discard
- Seamless commit workflow
All without leaving Vim.
nnoremap <leader>gs :<C-U>Leaderf git status<CR>