0

I've read quite a few posts/documentations about Vim's visual block feature (such as prepend not working), however, I'm still not able to apply a visual block prepend operation to multiple lines when I'm using Vim called from a Git Bash terminal. If I'm using Windows' cmd or Windows Power Shell it works just fine.

To be clear, from inside a vim buffer that was created via the Git Bash version 2.16.windows.1 environment, I follow the following steps:

  1. Hit CTRL+V (the result is the text 'VISUAL BLOCK' displayed at the bottom)
  2. Highlight multiple lines (just the first character of each line)
  3. Hit SHIFT+I (the result is 'INSERT' being displayed at the bottom)
  4. Type the '#' character (result is '#' being written to the first/original line)
  5. Hit ESC (The result is that I'm put back into normal mode)

Note that only one line received a prefix character. If I follow the same steps from cmd or powershell the prefix character is applied to all lines selected.

Is there a workaround to this? Is this a known Vim bug? Or is Git somehow interfering with Vim features?

lonious
  • 676
  • 9
  • 25

1 Answers1

1

It seems like the vim that you are using is the one that came installed with git-bash, since vim works like you'd expect from within powershell and cmd prompt.

Follow the steps here to see if changing the vim version to your own makes the visual block prepend feature work. https://superuser.com/questions/423532/how-do-i-use-installed-vim-in-git-bash-instead-of-the-one-that-came-with-git

From top answer by 'nevermind':

By default Git runs vim from Git\bin\vim. This is actually a script that contains path to the executable itself:

#!/bin/sh
exec /share/vim/vim73/vim "$@"

Therefore you can edit this file to point to your Git location.

The default editor can be overridden in Git\etc\gitconfig:

[core]
editor = path_to_your_editor

I hope this helps!

Community
  • 1
  • 1
Rafe H
  • 106
  • 5
  • I just noticed that adding 'C:\Program Files (x86)\Vim\vim81\vim.exe' as my path_to_editor made my .gitconfig file invalid and all my git commands have been disabled. Do you happen to know a way specify a valid path in this file? – lonious Mar 17 '19 at 11:45
  • I went ahead and renamed Git's vim folder and set the editor variable back to just 'vim' so the .gitconfig file would be valid and Git would call the vim binary listed in my PATH variable. Git Bash reports a few errors when I call vim, but everything still works as expected (full vim8.1 and Git features as far as I can tell). – lonious Mar 17 '19 at 11:59