40
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)...
28
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 ...
19
votes
Accepted
Easiest way to switch git branches
To summarize the answers, here are the ways to accomplish this:
Vanilla Terminal Vim in a shell with job control
Press CTRL-Z in normal mode will drop you back in to the shell and suspend Vim. After ...
13
votes
Easiest way to switch git branches
Use the vim-merginal plugin (fugitive extension). It offers interactive TUI for:
Viewing the list of branches
Checking out branches from that list
Creating new branches
Deleting branches
Merging ...
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....
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&...
11
votes
Accepted
Keeping personal vimrc and syntax files etc in source control?
Since 7.4, all your configuration files (even your vimrc) are expected to be in this directory:
%userprofile%\vimfiles\
But the name and location of that directory only matter to Vim. From Git's ...
10
votes
Accepted
Git mergetool vimdiff command
I used the trick from this SO question to see what the command line was, and got this:
:exe '!tr "\0" " " </proc/' . getpid() . '/cmdline'
:!tr "\0" " " </proc/23932/cmdline
gvim -f -d -c ...
10
votes
Accepted
How to detect whether swp files contain unsaved changes?
vim -r at the command line will list all swap files in the current directory and temporary directories, and whether they contain any unsaved changes. Look for the line that says modified: no/YES.
I ...
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 ...
8
votes
Easiest way to switch git branches
You should embrace your terminal. If you use CTRL-Z, it will background Vim (or whichever process you are currently running), then you can run any commands you want, the fg to bring the process back ...
8
votes
How to detect whether swp files contain unsaved changes?
Is it possible to only have .*.swp-files, when file on disk and file in vim are different?
Yes. The snippet below (adapted from tpope's vimrc) will disable the swap file for a buffer when it isn'...
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 ...
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 ...
7
votes
Accepted
Can I detect whether current Vim instance is launched by git?
$ git config --global core.editor "vim -Nu NONE"
tells Git to use Vim without sourcing your vimrc (-u NONE) and in "nocompatible" mode (-N).
And, well… you could even add something to start directly ...
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 ...
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:...
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 ...
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
...
6
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 ...
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 ...
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 ...
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 ...
5
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 ...
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 ...
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.
...
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 ...
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 (...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
git × 88plugin-fugitive × 19
vimdiff × 16
vimrc × 10
neovim × 7
syntax-highlighting × 4
microsoft-windows × 4
undo-redo × 4
fzf × 4
vimscript × 3
command-line × 3
version-control-systems × 3
key-bindings × 2
terminal × 2
autocompletion × 2
highlight × 2
plugin-system × 2
filetype-tex × 2
statusline × 2
bash × 2
ide × 2
merge × 2
filetype-git × 2
search × 1
gvim × 1