Guy Avraham
Guy Avraham

Reputation: 3690

Set vim default language when commiting with git

I'm using vim as my editor in git on my Linux machine (I have set it explicitly by running the command: git config --global core.editor vim).

The thing is, that each time git opens vim in order for me to enter my commit message (for example), the default language is NOT English (as I wish it was), yet it is Hebrew (the second language I have on my machine).

Note: When I open vim "directly" (for editing some text file - not via "some git" command), the default language is indeed English.

I'm using:

1) git version 2.17.1

2) vim version 8.0.1453

3) My OS is Ubuntu 18.04.1

How can I fix this ?

Thanks!

Upvotes: 2

Views: 463

Answers (1)

Ondrej K.
Ondrej K.

Reputation: 9664

If I understand correctly what you are looking for, you should be able to achieve that by adding the following line to your .vimrc configuration file:

au BufNewFile,BufRead COMMIT_EDITMSG,MERGE_MSG,TAG_EDITMSG language en_US.UTF-8

It's using the autocmd and the event and pattern to match to know when a commit message is being edited I have shamelessly stolen from filetype.vim on my system which comes with my vim installation and in this case sets the correct filetype (and with that syntax).

EDIT: As pointed out by torek. Since commit message should already be a recognized FileType event (after all I've copied the above line from common distro detection thereof), you can use that with autocmd as well:

au FileType gitcommit language en_EN.UTF-8

Upvotes: 1

Related Questions