Git can cause problems with vim-plug!
Published: 2022-05-20 14:53:34

---
title: Git can cause problems with vim-plug!
published: true
date: 2022-05-20 14:45:10 UTC
tags: 
canonical_url: 
cover_image: https://images.unsplash.com/photo-1629654291663-b91ad427698f?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxMTc3M3wwfDF8c2VhcmNofDJ8fGJhc2h8ZW58MHx8fHwxNjUzMDU3OTM1&ixlib=rb-1.2.1&q=80&w=2000
---

Or rather, bad configuration can do it.

See, I’ve just spent about an hour trying to figure this out, and for the life of me I couldn’t understand, what was happening.

I’ve recently fallen in love with the idea of adding new features to Vim using plugins. As I have four different machines running Linux in one way or another, I have decided to install the same two plugins (Ale and NerdTree) on all of them. Sounds simple enough, doesn’t it? And it was really simple!

On three out of four machines it worked perfectly. One command to install plug-vim on machine, copy the right section into my .vimrc… simple enough, it worked. Right until I tried to install it on my fourth, final and most important machine: Ubuntu in WSL2 on my personal laptop.

For reasons unknown to me at the time, every time I’ve tried to install plugins, I just got these errors:

```
Error detected while processing /home/hane/.vim/plugged/nerdtree/plugin/NERD_tree.vim:
line 15:
E492: Not an editor command: ^M
line 16:
E15: Invalid expression: exists('loaded_nerd_tree')^M
line 235:
E171: Missing :endif
Error detected while processing /home/hane/.vim/plugged/ale/plugin/ale.vim:
line 4:
E492: Not an editor command: ^M
line 6:
E492: Not an editor command: ^M
line 7:
E15: Invalid expression: exists('g:loaded_ale_dont_use_this_in_other_plugins_please')^M
line 353:
E171: Missing :endif
Press ENTER or type command to continue

```

They showed up every time I opened Vim, too, so nothing too pleasant.

## The culprit was good ol’ Git.

It took me more than an hour to find the right way to google this, and kudos to this specific [comment](https://github.com/vim/vim/issues/6156#issuecomment-1001134641) for helping me!

The fix was simple: Change git configuration and set property core.autocrlf to false.

One command:

```
git config --global core.autocrlf false

```

And after reinstalling plugins once again, all my problems were gone!

## So what happened?

Vim-plug uses git to download plugins. When **core.autocrlf** was set to **true** , it automatically set line endings for every file to CRLF, while Vim, when processing .vim files on Linux, was expecting LF endings. That caused the problem above:

```
E492: Not an editor command: ^M

```

## But what is an ^M, and what does it have to do with Line Endings?

^M is a CR in CRLF, which stands for Carriage Return. It’s a control character used to move a cursor to the beginning of the next line when reaching the end of a current line. As you can probably guess, it was not expected in this case, because only ^@ (Line Feed, LF in CRLF) was expected by Vim and the end of the line.

So Vim got one more character than expected and wasn’t ready to process it, effectively being unable to run installed plugins.

Of course, I could’ve spent much less time on fixing that, if I knew what ^M was beforehand, but hey - We’re all learning, right?

If you encountered this issue too, and this article helped you, please let me know!

_This article was originally posted on my personal website [Rumpel.dev](https://rumpel.dev). You can find more posts and informations about me there!_