Hot answers tagged

67 votes
Accepted

How do I open a file from another git branch?

You can use :Gedit/:Gsplit/:Gvsplit/... with the form {revision}:{filename} :Gedit branch:/foo/bar.c Note: If the file is the same as the current file you can abbreviate the command like so: :Gsplit ...
user avatar
28 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)...
user avatar
  • 413
25 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 ...
user avatar
  • 1,628
19 votes

How do I open a file from another git branch?

This is a little more broad than what OP asked, but for people not wanting to use plugins, and possibly other revision control systems, this little snippet tends to work fairly well: :new :r! git ...
user avatar
  • 8,072
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 ...
user avatar
  • 1,152
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 ...
user avatar
  • 584
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....
user avatar
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 ...
user avatar
  • 33.1k
11 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&...
user avatar
  • 4,040
9 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 ...
user avatar
  • 23.9k
9 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 ...
user avatar
  • 990
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 ...
user avatar
  • 23.9k
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 ...
user avatar
8 votes
Accepted

VimDiff incorrectly showing all lines as changed

I think the most likely culprit is another buffer still in diff-mode. This can happen if you're looking at multiple diffs, one after another, and don't turn off diff-mode between diffs. Disable diff-...
user avatar
  • 7,240
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'...
user avatar
  • 10.4k
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 ...
user avatar
  • 6,380
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 ...
user avatar
  • 33.1k
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 ...
user avatar
  • 171
7 votes
Accepted

Warning when opening commit message with Neovim

If I run :set spell, I get: spellfile#LoadFile(): There is no writable spell directory Shall I create /Users/adamharris/.nvim/spell (Y)es, [N]o: Select y Cannot find spell file for "en" in utf-8 ...
user avatar
  • 1,717
7 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 ...
user avatar
  • 28.1k
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:...
user avatar
  • 46.5k
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 ...
user avatar
  • 28.1k
6 votes

Is there a way to hook ctag changes to git branch checkouts and pulls?

Depending on how you update your ./tags file: If you do not commit your ./tags file to your branch/repository you can use a git hook that calls ctags -R . on each pull/checkout you do - this way your ...
user avatar
  • 396
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 ...
user avatar
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 ...
user avatar
  • 28.1k
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 ...
user avatar
  • 15.2k
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 ...
user avatar
  • 23.9k
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 ...
user avatar
  • 21.5k
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. ...
user avatar
  • 6,420
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 ...
user avatar
  • 175

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