49 votes

Git Fugitive how to git add a visually selected chunk of code

fugitive.vim now allows for staging a selection of a hunk with visual mode. Open the git summary with :Git (or :G) Expand the file which contains the lines you want to stage with > (or = to toggle)...
Kaio's user avatar
  • 623
31 votes
Accepted

Git Fugitive how to git add a visually selected chunk of code

There might be other ways, but this approach lets you to do more than adding a chunk, which is why I tend to use it quite a lot. Run :Gdiff command. It will open a split with version of current file ...
xaizek's user avatar
  • 1,788
13 votes

Git Fugitive how to git add a visually selected chunk of code

Stage Complete or Partial Hunks with vim-gitgutter Stage Complete Hunk <Leader>hs or :GitGutterStageHunk Stage Part of an Additions-only Hunk (since 8/2019) Visual mode {Visual}<Leader&...
Hotschke's user avatar
  • 4,750
13 votes

Git Fugitive how to git add a visually selected chunk of code

Vimcasts has a great series on Fugitive.vim. The episode Fugitive.vim - working with the git index would be the the most helpful for your question. You can use :Gdiff to stage only portions of a file....
Peter Rincker's user avatar
9 votes
Accepted

Open git tracked files inside editor

You could use the args command instead: command G execute ":args `git diff --name-only`" The first file should be opened, and if you run :ls after executing this, you should see other files listed ...
muru's user avatar
  • 24.9k
8 votes
Accepted

Populate a git-commit-template with variables

It's possible with some scripting. When editing a commit message, a temporary file .git/COMMIT_EDITMSG is created with the contents of the commit.template file. With autocmd we can execute a script ...
Tommy A's user avatar
  • 6,770
8 votes

Git Fugitive how to git add a visually selected chunk of code

As you specifically asked about solutions that use other plugins, I'll note that you can also stage visual selections using vimagit, which is a Git plugin (based on the other editor's popular Magit ...
Rich's user avatar
  • 31.9k
7 votes

Using vim diff to compare the working directory to the HEAD in git?

To view unstaged modifications to your git working tree in vimdiff, try: git difftool --tool=vimdiff or for staged changes git difftool --tool=vimdiff [ --staged | --cached ] These commands are ...
the_velour_fog's user avatar
7 votes

Easiest way to switch git branches

The fugitive Git checkout <branch> has a downside that it doesn't autocomplete the branch name. Using fzf.vim I've created this command: function! s:changebranch(branch) execute 'Git ...
kubek2k's user avatar
  • 171
7 votes
Accepted

How to load list of files in commit into quickfix

You could use the following function which has the advantage of not changing the state of your local git repo: function! CommitQF(...) " Get the commit hash if it was specified let commit = a:...
statox's user avatar
  • 49.8k
7 votes
Accepted

IDE-like inline diff highlighting in Vim

You can do this with the vim-gitgutter plugin. If you're not using git, then Signify has a similar feature. After installing vim-gitgutter, you can switch the highlighting on and off with the ...
Rich's user avatar
  • 31.9k
6 votes

How to load list of files in commit into quickfix

Plugin Fugitive v3.2 (Jan 2020) vim-fugitive has added new commands since the OP raised this question which can do exactly what the OP has asked. Now you can call :Git difftool or the abbreviated ...
Hotschke's user avatar
  • 4,750
6 votes

Turn Vim's multiple undo history into git commits?

Here's a quick and dirty function that does what you request: function! UndoCommits(steps) for i in range(a:steps) undo endfor for i in range(a:steps) write ...
Rich's user avatar
  • 31.9k
5 votes
Accepted

Vim Function to Send Highlighted Text to a Git Commit

GitLocations won't work as expected, since you'll be calling Vim's :find, not the find command. You might try something like: return system('find $HOME -name ".git" -printf "%h\n"') And you could ...
muru's user avatar
  • 24.9k
5 votes

Easiest way to switch git branches

Ever since this commit in Jul 2019, this has been possible using Git fugitive only. Type :G branch will open a split buffer with all the branches in a list. Place your cursor on the branch and press ...
hernytan's user avatar
5 votes
Accepted

How do I get back to the current working copy while viewing git revisions?

The Gedit command is here for you. It takes an argument which is the revision you want to use, using the same logic as git-rev-parse (meaning you can use it without argument to get back to your ...
nobe4's user avatar
  • 16k
5 votes

How to load list of files in commit into quickfix

Here are two related approaches. Both use git-* scripts; if you put them on your PATH, you can invoke them as if they were subcommands of git. Use the contrib script git-jump The git-jump script ...
D. Ben Knoble's user avatar
  • 26.2k
5 votes
Accepted

Create a specific .vimrc for git commits usage?

It is strange that the error just appear with git commit -- I guess you have two versions of Vim installed, and the one used by git is older/have less features and thus complain about that option. ...
mMontu's user avatar
  • 6,640
5 votes
Accepted

`vimdiff` nor `nvim -d` are working as an external diff tool for git

I tried git config --global diff.tool vimdiff3 git config --global difftool.vimdiff3.path nvim git config --global merge.tool vimdiff3 git config --global mergetool.vimdiff3.path It worked like a ...
Pie's user avatar
  • 175
5 votes
Accepted

shared vimrc on two machines; only run command for one of them

You can surround the config/code in question with a conditional based on an environment variable. If you're using Bash environments a good candidate is envvar HOSTNAME which will probably be unique (...
B Layer's user avatar
  • 19.8k
5 votes

Review: git branch in statusline

The most general improvements I can give are to avoid the long ?: and to make use of the get function on dictionaries. For example, I would write return get(g:, 'git_branch', '') For the if, use a ...
D. Ben Knoble's user avatar
  • 26.2k
5 votes

How to break-up gutter fights?

Vim currently supports assigning sign priorities (https://vimhelp.org/sign.txt.html#sign-priority). The plugins placing the signs need to use the newer sign APIs.
Yegappan Lakshmanan's user avatar
5 votes
Accepted

How to get Vim to show git status in the statusline?

The easiest way would be to call git inside %{} like so: let &statusline = '%{substitute(system("git status -s"), "\n", " ", "g")}' Anything inside %{} get ...
Martin Tournoij's user avatar
5 votes

Call plugin-defined function in .vimrc

All directories in your Vim runtimepath can have a directory called after which can contain directories like plugin and ftplugin but get sourced after the regular ol' plugin and ftplugin directories ...
Chris Heithoff's user avatar
4 votes
Accepted

Commiting pathogen bundles?

Using git submodules is a common way of doing this. The VimCasts episode is a great explanation, but the basic commands are as below: Adding a new plugin cd ~/.vim git submodule add http://github....
Rich's user avatar
  • 31.9k
4 votes

How to compile vim for user only and use git to track it?

Google for vim to find their homepage. You find http://www.vim.org . Look on their homepage, where is their upstream source. If you have luck, they are on the github. On the "Download" section, they ...
peterh's user avatar
  • 1,149
4 votes

Review: git branch in statusline

0- +1 to D. Ben Knoble suggestions. Regarding pure vim-scripting 1- Never define autocommands globally. Prefer to define them in their own group, and when filling the group, start by clearing it. ...
Luc Hermitte's user avatar
  • 17.4k
4 votes

GitLens-like issue linking in vim

You might want fugitive's :Git blame combined with tpope/vim-rhubarb. Doing so will let :GBrowse work with GitHub-based remotes, so that you can quickly open those PRs. Another option might be ...
D. Ben Knoble's user avatar
  • 26.2k
3 votes
Accepted

Make autoformating insert a line break instead of two spaces after full stop

When Vim joins a line that ends with a period to another line, it inserts two spaces between them. This is because joinspaces is on by default. To make gq only insert one space between lines, use: :...
Eric's user avatar
  • 318
3 votes

Easiest way to switch git branches

The answer provided by @kubek2k is so phenomenal. That solution is better than I could have imagined and implemented in in less lines of code that I could have imaged. It opened the door to help me ...
radke's user avatar
  • 131

Only top scored, non community-wiki answers of a minimum length are eligible