4

I have recently installed cygwin (as I am confined to a Windows OS) and would like to utilize Vim within it. Everything is installed and I can access vim readily and can modify .vimrc and the like. From a prior post, I have learned that my plugins must be in vimfiles for a Windows OS and have done so. However, now when I try to verify pathogen I get an error stating:

E492: Not an editor command: ^M (this repeats a couple times)
E15: Invalid expression: exists("g:loaded_pathogen") || &cp^M
E117: Unknown function: pathogen#infect

My .virmc (again very basic as just trying to start everything up)

version 6.0
if &cp | set nocp | endif
let s:cpo_save=$cpo
enter code here
set cpo&vim
map! <C-Home> <C-Home>
map! <C-End> <C-End>
let &cpo=s:cpo_save
unlet s:cpo_save
set autoindent
set ff=unix
set background=dark
set backspace=2
set fileencodings=ucs-bom,utf-8,default,latin1
set helplang=en
set history=50
set laststatus=2
set ruler
set shelltemp
set viminfo='100,<50,s10,h
set window=55
" vim: set ft=vim :
call pathogen#infect()
syntax on
filetype plugin indent on

Regards,

romainl
  • 186,200
  • 21
  • 280
  • 313
Liam
  • 203
  • 2
  • 5
  • 2
    it looks like some of your files, `autoload/pathogen.vim` for example, have windows line endings. [Fix that](http://stackoverflow.com/questions/1110678/m-at-the-end-of-every-line-in-vim). – romainl Dec 19 '12 at 20:49
  • How do I fix that? Forgive my ignorance – Liam Dec 19 '12 at 20:53
  • I see the link you provided but I am confused to the application of the :%s/^M$// command. I have tried within vim and opening pathogen.vim and it says the sequence is not found. – Liam Dec 19 '12 at 21:01
  • Open `pathogen.vim` in Vim, you should see `^M` at the end of each line. Type this exactly: `:%s/` then hit `Ctrl+v` then hit the `Enter` key (you get a single character that looks like `^M`, it's Vim's representation of a newline) then `//` then the `Enter` key again to run the command. The whole thing looks like `:%s/^M//`. It means "substitute every `^M` in this file with nothing". – romainl Dec 19 '12 at 21:20
  • I do that and it responds E486: Pattern not found: ^M – Liam Dec 19 '12 at 21:22

3 Answers3

3

from the shell, try executing the following command:

find ~/.vim -type f -exec dos2unix \"{}\" \;

this will convert all files under your ~/.vim directory into unix file format. it should remove the ^M errors you're seeing.

nullrevolution
  • 3,937
  • 1
  • 18
  • 20
  • 3
    In my environment(Cygwin), this `find ~/.vim -type f -exec dos2unix '{}' \;` works, but yours not. – Hong May 07 '14 at 03:04
0

In your .vimrc file I notice

set ff=unix

But in vim the following commands explain some things,

:help dos-file-formats

If the 'fileformat' option is set to "dos" (which is the default), Vim accepts
a single <NL> or a <CR><NL> pair for end-of-line (<EOL>).  When writing a
file, Vim uses <CR><NL>.  Thus, if you edit a file and write it, Vim replaces
<NL> with <CR><NL>.             

If the 'fileformat' option is set to "unix", Vim uses a single <NL> for <EOL>
and shows <CR> as ^M.

You can use Vim to replace <NL> with <CR><NL> by reading in any mode and
writing in Dos mode (":se ff=dos").
You can use Vim to replace <CR><NL> with <NL> by reading in Dos mode and
writing in Unix mode (":se ff=unix").

Vim sets 'fileformat' automatically when 'fileformats' is not empty (which is
the default), so you don't really have to worry about what you are doing.

So, you should try to remove the

set ff=unix

line, or fix the end of lines of your file.

Truc
  • 9
  • 1
  • Thank you, I added ff=unix after searching some other related postings and forgot to remove it after it failed to help. This seems to have fixed it. – Liam Dec 19 '12 at 20:49
  • Sorry, this actually didn't fix it. Still get the error for ^M. Thought it was clean but after reopening vim it still does not work. – Liam Dec 19 '12 at 20:52
  • To insert a ^M while in insert mode or while entering a command, you must issue a CTRL+V followed by a CTRL+M. This way you should be able to remove the unwanted characters. – Truc Dec 19 '12 at 21:10
  • Are these ^M in the pathogen.vim file? I downloaded via git within cygwin. Where exactly do I remove these characters? thanks – Liam Dec 19 '12 at 21:12
  • I guess these characters are there, yes. You'll see them very clearly when editing the file (they appear as ^M ;)) – Truc Dec 19 '12 at 21:16
  • I have opened pathogen.vim and I cannot find any ^M characters. – Liam Dec 19 '12 at 21:20
0

I just had the same problem. The above solution (proposed by nullrevolution) of calling "dos2unix" on your bundle files should fix your problem for the current plugins.

For the future, I found my problem was was caused by cloning git repos into the bundles directory with git config core.autocrlf set to true. After I set the git config core.autocrlf back to false, I git cloned the plugins again, and it was back to UNIX-y file endings.

warriorpostman
  • 2,268
  • 2
  • 16
  • 26