2

I have been using vim for a while now and this is the first time I have gotten this issue.

When I open vim it complains about there being CRLF endings in my vimrc file (Error: Not an editor command ^M) but when I open the file using vim I don't see the ^M anywhere. The fileformat is set to unix and ffs is unix,dos.

Here is a screenshot (sorry I just made my account so I cannot post screenshots): https://i.stack.imgur.com/3PjM8.png

enter image description here

When I use unix2dos on my vimrc and open vim I still have the CRLF errors but this time there are significantly fewer errors and I still don't see the ^M at the end of the lines. The fileformat is set to dos and ffs is unix,dos.

Here is a screenshot (sorry I just made my account so I cannot post screenshots): https://i.stack.imgur.com/c74RE.png

enter image description here

I have tried using dos2unix and unix2dos, setting the ff and ffs using vim, using gedit and Sublime Text 3, and even getting my old vimrc file from GitHub. I have also tried downgrading vim and reinstalling it after completely removing it from my system. I am using Vim 7.4.778 on Arch Linux (the i686 gvim package).

Currently all I have in my .vimrc is this:

"NeoBundle Scripts-----------------------------
if has('vim_starting')
  if &compatible
    set nocompatible               " Be iMproved
  endif

  " Required:
  set runtimepath+=~/.vim/bundle/neobundle.vim/
endif

" Required:
call neobundle#begin(expand('~/.vim/bundle'))

" Let NeoBundle manage NeoBundle
" Required:
NeoBundleFetch 'Shougo/neobundle.vim'

" Add or remove your Bundles here:
NeoBundle 'Shougo/neosnippet.vim'
NeoBundle 'Shougo/neosnippet-snippets'
NeoBundle 'tpope/vim-fugitive'
NeoBundle 'ctrlpvim/ctrlp.vim'
NeoBundle 'flazz/vim-colorschemes'

" You can specify revision/branch/tag.
NeoBundle 'Shougo/vimshell', { 'rev' : '3787e5' }

" Required:
call neobundle#end()

" Required:
filetype plugin indent on

" If there are uninstalled bundles found on startup,
" this will conveniently prompt you to install them.
NeoBundleCheck
"End NeoBundle Scripts-------------------------

Here is what od -c .vimrc gives me:

0000000   "   N   e   o   B   u   n   d   l   e       S   c   r   i   p
0000020   t   s   -   -   -   -   -   -   -   -   -   -   -   -   -   -
0000040   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -  \n
0000060   i   f       h   a   s   (   '   v   i   m   _   s   t   a   r
0000100   t   i   n   g   '   )  \n           i   f       &   c   o   m
0000120   p   a   t   i   b   l   e  \n                   s   e   t    
0000140   n   o   c   o   m   p   a   t   i   b   l   e                
0000160                                               "       B   e    
0000200   i   M   p   r   o   v   e   d  \n           e   n   d   i   f
0000220  \n  \n           "       R   e   q   u   i   r   e   d   :  \n
0000240           s   e   t       r   u   n   t   i   m   e   p   a   t
0000260   h   +   =   /   h   o   m   e   /   a   d   m   n   u   n   p
0000300   w   n   d   /   .   v   i   m   /   b   u   n   d   l   e   /
0000320   n   e   o   b   u   n   d   l   e   .   v   i   m   /  \n   e
0000340   n   d   i   f  \n  \n   "       R   e   q   u   i   r   e   d
0000360   :  \n   c   a   l   l       n   e   o   b   u   n   d   l   e
0000400   #   b   e   g   i   n   (   e   x   p   a   n   d   (   '   /
0000420   h   o   m   e   /   a   d   m   n   u   n   p   w   n   d   /
0000440   .   v   i   m   /   b   u   n   d   l   e   '   )   )  \n  \n
0000460   "       L   e   t       N   e   o   B   u   n   d   l   e    
0000500   m   a   n   a   g   e       N   e   o   B   u   n   d   l   e
0000520  \n   "       R   e   q   u   i   r   e   d   :  \n   N   e   o
0000540   B   u   n   d   l   e   F   e   t   c   h       '   S   h   o
0000560   u   g   o   /   n   e   o   b   u   n   d   l   e   .   v   i
0000600   m   '  \n  \n   "       A   d   d       o   r       r   e   m
0000620   o   v   e       y   o   u   r       B   u   n   d   l   e   s
0000640       h   e   r   e   :  \n   N   e   o   B   u   n   d   l   e
0000660       '   S   h   o   u   g   o   /   n   e   o   s   n   i   p
0000700   p   e   t   .   v   i   m   '  \n   N   e   o   B   u   n   d
0000720   l   e       '   S   h   o   u   g   o   /   n   e   o   s   n
0000740   i   p   p   e   t   -   s   n   i   p   p   e   t   s   '  \n
0000760   N   e   o   B   u   n   d   l   e       '   t   p   o   p   e
0001000   /   v   i   m   -   f   u   g   i   t   i   v   e   '  \n   N
0001020   e   o   B   u   n   d   l   e       '   c   t   r   l   p   v
0001040   i   m   /   c   t   r   l   p   .   v   i   m   '  \n   N   e
0001060   o   B   u   n   d   l   e       '   f   l   a   z   z   /   v
0001100   i   m   -   c   o   l   o   r   s   c   h   e   m   e   s   '
0001120  \n  \n   "       Y   o   u       c   a   n       s   p   e   c
0001140   i   f   y       r   e   v   i   s   i   o   n   /   b   r   a
0001160   n   c   h   /   t   a   g   .  \n   N   e   o   B   u   n   d
0001200   l   e       '   S   h   o   u   g   o   /   v   i   m   s   h
0001220   e   l   l   '   ,       {       '   r   e   v   '       :    
0001240   '   3   7   8   7   e   5   '       }  \n  \n   "       R   e
0001260   q   u   i   r   e   d   :  \n   c   a   l   l       n   e   o
0001300   b   u   n   d   l   e   #   e   n   d   (   )  \n  \n   "    
0001320   R   e   q   u   i   r   e   d   :  \n   f   i   l   e   t   y
0001340   p   e       p   l   u   g   i   n       i   n   d   e   n   t
0001360       o   n  \n  \n   "       I   f       t   h   e   r   e    
0001400   a   r   e       u   n   i   n   s   t   a   l   l   e   d    
0001420   b   u   n   d   l   e   s       f   o   u   n   d       o   n
0001440       s   t   a   r   t   u   p   ,  \n   "       t   h   i   s
0001460       w   i   l   l       c   o   n   v   e   n   i   e   n   t
0001500   l   y       p   r   o   m   p   t       y   o   u       t   o
0001520       i   n   s   t   a   l   l       t   h   e   m   .  \n   N
0001540   e   o   B   u   n   d   l   e   C   h   e   c   k  \n   "   E
0001560   n   d       N   e   o   B   u   n   d   l   e       S   c   r
0001600   i   p   t   s   -   -   -   -   -   -   -   -   -   -   -   -
0001620   -   -   -   -   -   -   -   -   -   -   -   -   -  \n  \n
0001637

Here is what hexdump -C .vimrc gives me:

00000000  22 4e 65 6f 42 75 6e 64  6c 65 20 53 63 72 69 70  |"NeoBundle Scrip|
00000010  74 73 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |ts--------------|
00000020  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 0a  |---------------.|
00000030  69 66 20 68 61 73 28 27  76 69 6d 5f 73 74 61 72  |if has('vim_star|
00000040  74 69 6e 67 27 29 0a 20  20 69 66 20 26 63 6f 6d  |ting').  if &com|
00000050  70 61 74 69 62 6c 65 0a  20 20 20 20 73 65 74 20  |patible.    set |
00000060  6e 6f 63 6f 6d 70 61 74  69 62 6c 65 20 20 20 20  |nocompatible    |
00000070  20 20 20 20 20 20 20 20  20 20 20 22 20 42 65 20  |           " Be |
00000080  69 4d 70 72 6f 76 65 64  0a 20 20 65 6e 64 69 66  |iMproved.  endif|
00000090  0a 0a 20 20 22 20 52 65  71 75 69 72 65 64 3a 0a  |..  " Required:.|
000000a0  20 20 73 65 74 20 72 75  6e 74 69 6d 65 70 61 74  |  set runtimepat|
000000b0  68 2b 3d 2f 68 6f 6d 65  2f 61 64 6d 6e 75 6e 70  |h+=~|
000000c0  77 6e 64 2f 2e 76 69 6d  2f 62 75 6e 64 6c 65 2f  |wnd/.vim/bundle/|
000000d0  6e 65 6f 62 75 6e 64 6c  65 2e 76 69 6d 2f 0a 65  |neobundle.vim/.e|
000000e0  6e 64 69 66 0a 0a 22 20  52 65 71 75 69 72 65 64  |ndif.." Required|
000000f0  3a 0a 63 61 6c 6c 20 6e  65 6f 62 75 6e 64 6c 65  |:.call neobundle|
00000100  23 62 65 67 69 6e 28 65  78 70 61 6e 64 28 27 2f  |#begin(expand('/|
00000110  68 6f 6d 65 2f 61 64 6d  6e 75 6e 70 77 6e 64 2f  |~/|
00000120  2e 76 69 6d 2f 62 75 6e  64 6c 65 27 29 29 0a 0a  |.vim/bundle'))..|
00000130  22 20 4c 65 74 20 4e 65  6f 42 75 6e 64 6c 65 20  |" Let NeoBundle |
00000140  6d 61 6e 61 67 65 20 4e  65 6f 42 75 6e 64 6c 65  |manage NeoBundle|
00000150  0a 22 20 52 65 71 75 69  72 65 64 3a 0a 4e 65 6f  |." Required:.Neo|
00000160  42 75 6e 64 6c 65 46 65  74 63 68 20 27 53 68 6f  |BundleFetch 'Sho|
00000170  75 67 6f 2f 6e 65 6f 62  75 6e 64 6c 65 2e 76 69  |ugo/neobundle.vi|
00000180  6d 27 0a 0a 22 20 41 64  64 20 6f 72 20 72 65 6d  |m'.." Add or rem|
00000190  6f 76 65 20 79 6f 75 72  20 42 75 6e 64 6c 65 73  |ove your Bundles|
000001a0  20 68 65 72 65 3a 0a 4e  65 6f 42 75 6e 64 6c 65  | here:.NeoBundle|
000001b0  20 27 53 68 6f 75 67 6f  2f 6e 65 6f 73 6e 69 70  | 'Shougo/neosnip|
000001c0  70 65 74 2e 76 69 6d 27  0a 4e 65 6f 42 75 6e 64  |pet.vim'.NeoBund|
000001d0  6c 65 20 27 53 68 6f 75  67 6f 2f 6e 65 6f 73 6e  |le 'Shougo/neosn|
000001e0  69 70 70 65 74 2d 73 6e  69 70 70 65 74 73 27 0a  |ippet-snippets'.|
000001f0  4e 65 6f 42 75 6e 64 6c  65 20 27 74 70 6f 70 65  |NeoBundle 'tpope|
00000200  2f 76 69 6d 2d 66 75 67  69 74 69 76 65 27 0a 4e  |/vim-fugitive'.N|
00000210  65 6f 42 75 6e 64 6c 65  20 27 63 74 72 6c 70 76  |eoBundle 'ctrlpv|
00000220  69 6d 2f 63 74 72 6c 70  2e 76 69 6d 27 0a 4e 65  |im/ctrlp.vim'.Ne|
00000230  6f 42 75 6e 64 6c 65 20  27 66 6c 61 7a 7a 2f 76  |oBundle 'flazz/v|
00000240  69 6d 2d 63 6f 6c 6f 72  73 63 68 65 6d 65 73 27  |im-colorschemes'|
00000250  0a 0a 22 20 59 6f 75 20  63 61 6e 20 73 70 65 63  |.." You can spec|
00000260  69 66 79 20 72 65 76 69  73 69 6f 6e 2f 62 72 61  |ify revision/bra|
00000270  6e 63 68 2f 74 61 67 2e  0a 4e 65 6f 42 75 6e 64  |nch/tag..NeoBund|
00000280  6c 65 20 27 53 68 6f 75  67 6f 2f 76 69 6d 73 68  |le 'Shougo/vimsh|
00000290  65 6c 6c 27 2c 20 7b 20  27 72 65 76 27 20 3a 20  |ell', { 'rev' : |
000002a0  27 33 37 38 37 65 35 27  20 7d 0a 0a 22 20 52 65  |'3787e5' }.." Re|
000002b0  71 75 69 72 65 64 3a 0a  63 61 6c 6c 20 6e 65 6f  |quired:.call neo|
000002c0  62 75 6e 64 6c 65 23 65  6e 64 28 29 0a 0a 22 20  |bundle#end().." |
000002d0  52 65 71 75 69 72 65 64  3a 0a 66 69 6c 65 74 79  |Required:.filety|
000002e0  70 65 20 70 6c 75 67 69  6e 20 69 6e 64 65 6e 74  |pe plugin indent|
000002f0  20 6f 6e 0a 0a 22 20 49  66 20 74 68 65 72 65 20  | on.." If there |
00000300  61 72 65 20 75 6e 69 6e  73 74 61 6c 6c 65 64 20  |are uninstalled |
00000310  62 75 6e 64 6c 65 73 20  66 6f 75 6e 64 20 6f 6e  |bundles found on|
00000320  20 73 74 61 72 74 75 70  2c 0a 22 20 74 68 69 73  | startup,." this|
00000330  20 77 69 6c 6c 20 63 6f  6e 76 65 6e 69 65 6e 74  | will convenient|
00000340  6c 79 20 70 72 6f 6d 70  74 20 79 6f 75 20 74 6f  |ly prompt you to|
00000350  20 69 6e 73 74 61 6c 6c  20 74 68 65 6d 2e 0a 4e  | install them..N|
00000360  65 6f 42 75 6e 64 6c 65  43 68 65 63 6b 0a 22 45  |eoBundleCheck."E|
00000370  6e 64 20 4e 65 6f 42 75  6e 64 6c 65 20 53 63 72  |nd NeoBundle Scr|
00000380  69 70 74 73 2d 2d 2d 2d  2d 2d 2d 2d 2d 2d 2d 2d  |ipts------------|
00000390  2d 2d 2d 2d 2d 2d 2d 2d  2d 2d 2d 2d 2d 0a 0a     |-------------..|
0000039f
  • Curious. You've covered a number of the bases, but there's clearly still a problem — Vim won't complain if there isn't. Have you looked at the output from `od -c .vimrc` — are there any occurrences of `\r` in the output? Have you checked (by putting a deliberate syntax error at the top, for example), that Vim is looking at the file you expect — could it be looking at a different file from the one you're inspecting? – Jonathan Leffler Aug 04 '15 at 04:51
  • 2
    I observe that the line numbers in the error messages mostly don't match the line numbers in your `.vimrc` file, which suggests that Vim is looking at a different file from the one you're looking at. – Jonathan Leffler Aug 04 '15 at 04:56
  • If your file has `^M` in it, it is in DOS encoding, and you need to make it UNIX - use `dos2unix`, not `unix2dos`. You said you tried `unix2dos` too - what happened? Can you post the first couple of lines' worth of `hexdump -C .vimrc`? What does `:script` say (regarding @JonathanLeffler's suspicions)? – Amadan Aug 04 '15 at 07:23
  • @JonathanLeffler & @Amadan, I updated my question with the outputs for `od -c .vimrc` & `hexdump -C .vimrc`. – user5187937 Aug 05 '15 at 00:21
  • The `od -c` output doesn't contain any carriage returns. However, it also isn't the file for the first set of error messages. For example, your error messages lists line 31 `E15: Invalid expression: exists('g:loaded_neobundle') &&`, but line 31 in the `.vimrc` you show is `" Required:`. So, the reason you can't fix the problem by modifying your `.vimrc` is that it is not that file that is causing the trouble. You need to find out, somehow, which file(s) are being read (one has 374 or more lines according to the error messages), and fix those. In other words, you're looking in the wrong place. – Jonathan Leffler Aug 05 '15 at 00:29
  • If you can't think of a better way of doing it, then try: `strace -o /tmp/vim.strace vim ~/.vimrc` and exit from `vim`. Then look for `open` calls in `/tmp/vim.strace`. One or more of the files that it succeeds in opening is probably the one that causes grief. When I do that, with some careful `grep` tweaking, I get files such as `/etc/vimrc` and numerous files under `/usr/share/vim/vim70/`, as well as `~/.viminfo` and `~/.vimrc`. – Jonathan Leffler Aug 05 '15 at 00:38
  • @JonathanLeffler can you please post what `grep` tweaks you used? I opened `/tmp/vim.strace` in Sublime Text and got 305 matches for "open". Another thing is that I know the error message says "line 374" but I checked and was only able to see 38 lines in my .vimrc – user5187937 Aug 05 '15 at 01:02
  • I used: `grep open /tmp/vim.strace | grep -v '= -1 ENO' | grep -v '"."' | grep -o '".*"' | sort -u`. It ain't elegant, but it worked. The first `grep` removes the failures (`ENOTDIR`, `ENOENT`); the second removes opens of the current directory (a surprisingly large number of them); the third selects only the string between double quotes; the sort gives you one copy of each name. Don't bother looking at the `.viminfo` file(s); they're binary data and neither relevant nor readable. Likewise, you can ignore shared libraries and terminfo and locale files, etc. – Jonathan Leffler Aug 05 '15 at 01:05
  • You could also simply look for files that changed recently under `/usr/share/vim`. For example, `find /usr/share/vim -type f -mtime -30` for file changed in the last 30 days or so. If you find them, you may want to worry about why they were changed. – Jonathan Leffler Aug 05 '15 at 01:08
  • @JonathanLeffler Thank you. I got a bunch of files with `grep`. How can I find out which one is causing the issue? I did `find /usr/share/vim -type f -mtime -7`as this error started happening at the end of last week which gave me `/usr/share/vim/vimfiles/syntax/HGAnnotate.vim`. Is this file the problematic one? – user5187937 Aug 05 '15 at 01:16
  • If that file was in the list from grep and find then probably. If not, look at anything related to neobundle. Otherwise, try the 'file' command on the files and see if any are marked as having CRLF, DOS or similar line endings. If nothing shows up, then try 'od -c' on them and look for backslash r in the output. – Jonathan Leffler Aug 05 '15 at 01:22
  • Thank you @JonathanLeffler. I found out that the problem was with the neobundle files and replaced it with my old GitHub backup. Everything works now. – user5187937 Aug 05 '15 at 01:31
  • Unfortunately after installing all my plugins via NeoBundle from my old .vimrc I still get ^M errors. However this time I can access the NeoBundle plugin from vim. – user5187937 Aug 05 '15 at 01:44

1 Answers1

1

Transferring extensive comments into an answer.

It's curious. You've covered a number of the bases, but there's clearly still a problem — Vim won't complain if there isn't. Have you looked at the output from od -c .vimrc — are there any occurrences of \r in the output? Have you checked (by putting a deliberate syntax error at the top, for example), that Vim is looking at the file you expect — could it be looking at a different file from the one you're inspecting?

  • I observe that the line numbers in the error messages mostly don't match the line numbers in your .vimrc file, which suggests that Vim is looking at a different file from the one you're looking at.

I updated my question with the outputs for od -c .vimrc & hexdump -C .vimrc.

The od -c output doesn't contain any carriage returns. However, it also isn't the file for the first set of error messages. For example, your error messages list line 31

E15: Invalid expression: exists('g:loaded_neobundle') &&

but line 31 in the .vimrc you show is

" Required:

So, the reason you can't fix the problem by modifying your .vimrc is that it is not that file that is causing the trouble. You need to find out, somehow, which file(s) are being read (one has 374 or more lines according to the error messages), and fix those. In other words, you're looking in the wrong place.

If you can't think of a better way of doing it, then try:

strace -o /tmp/vim.strace vim ~/.vimrc

and exit from vim. Then look for open calls in /tmp/vim.strace. One or more of the files that it succeeds in opening is probably the one that causes grief. When I do that, with some careful grep tweaking, I get files such as /etc/vimrc and numerous files under /usr/share/vim/vim70/, as well as ~/.viminfo and ~/.vimrc.

Can you please post what grep tweaks you used? I opened /tmp/vim.strace in Sublime Text and got 305 matches for "open". Another thing is that I know the error message says "line 374" but I checked and was only able to see 38 lines in my .vimrc

I used:

grep open /tmp/vim.strace | grep -v '= -1 ENO' | grep -v '"."' |
    grep -o '".*"' | sort -u

It ain't elegant, but it worked. The first grep removes the failures (ENOTDIR, ENOENT); the second removes opens of the current directory (a surprisingly large number of them); the third selects only the string between double quotes; the sort gives you one copy of each name. Don't bother looking at the .viminfo file(s); they're binary data and neither relevant nor readable. Likewise, you can ignore shared libraries and terminfo and locale files, etc. –

You could also simply look for files that changed recently under /usr/share/vim. For example:

find /usr/share/vim -type f -mtime -30

for files changed in the last 30 days or so. If you find them, you may want to worry about why they were changed.

I got a bunch of files with grep. How can I find out which one is causing the issue? I did find /usr/share/vim -type f -mtime -7 as this error started happening at the end of last week which gave me /usr/share/vim/vimfiles/syntax/HGAnnotate.vim. Is this file the problematic one?

If that file was in the list from grep and find then probably. If not, look at anything related to NeoBundle. Otherwise, try the file command on the files and see if any are marked as having CRLF, DOS or similar line endings. If nothing shows up, then try od -c on them and look for backslash-r (\r) in the output.

I found out that the problem was with the NeoBundle files and replaced it with my old GitHub backup. Everything works now.

Unfortunately after installing all my plugins via NeoBundle from my old .vimrc, I still get ^M errors. However this time I can access the NeoBundle plugin from vim.

At this stage, you need to repeat or continue the exercise, finding the files with DOS-style CRLF line endings as I've already described. If vim runs at all, you can fix the files using the techniques you're already aware of, also described in How to convert the ^M linebreak to normal linebreak in a file that is opened in vim?.

And finally, user5187937 reports:

This fixed everything for me: git config --global core.autocrlf input Apparently git was converting all my plugins to CRLF format even though I had never changed my core.autocrlf setting.

Community
  • 1
  • 1
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278