Hot answers tagged

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)...
Kaio's user avatar
  • 533
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 ...
xaizek's user avatar
  • 1,708
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 ...
Sukima's user avatar
  • 1,192
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 ...
adelarsq's user avatar
  • 594
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
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,590
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 ...
romainl's user avatar
  • 38.4k
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 ...
muru's user avatar
  • 24.7k
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 ...
Lithis's user avatar
  • 1,020
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.7k
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 ...
65-e9-7e-17's user avatar
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'...
jamessan's user avatar
  • 10.8k
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
  • 30.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,690
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 ...
romainl's user avatar
  • 38.4k
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
  • 49k
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
  • 30.9k
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
  • 30.9k
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 ...
the_velour_fog'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
  • 15.8k
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.7k
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

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,590
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
  • 24.8k
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,570
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.4k
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
  • 24.8k
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

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