Wednesday, September 19, 2012

Re: irritating ^M at the end of ach line

On 19/09/12 16:24, rudra wrote:
> Dear friends,
> I use vim-latex(http://vim-latex.sourceforge.net/) and fortran_codecomplete(http://www.vim.org/scripts/script.php?script_id=2487)
> My vimrc is:
> $ cat .vimrc
> set autoindent
> set smartindent
> set hlsearch
> set incsearch
> set ignorecase
> set smartcase
> set novisualbell
> set paste
> set ruler
> set expandtab
> set smarttab
> set shiftwidth=3
> set softtabstop=3
> "set mouse=a "enable mouse
> set nu "show line number
> "set cul "highlight current line
>
> if version >= 700
> set spell spl=en_us
> set nospell
> nmap <F7> :set spell!
> endif
>
> " Fortran stuff
> let fortran_do_enddo=1
> let fortran_more_precise=1
> let fortran_free_source=1
>
> filetype on
> filetype plugin on
> filetype indent on
>
> syntax enable
>
> " Always jump to last edited line
> if has("autocmd")
> au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
> \| exe "normal! g'\"" | endif
> endif
>
> "let g:Imap_UsePlaceHolders = 0
> set sw=2
> set iskeyword+=:
>
>
> The problem is for each file, I get an annoying ^M at the end of each line. Though this does not affect the program, its irritating to have a yellow box at every line.
>
> The filetype of the file is still unix. In my humble guess, this is caused by fortran_codecomplete. But I am not sure.
> Any help please?
>

An annoying ^M at the end of each line, or at the end of each line
except the last one?

It is a common defect of many ill-conceived Windows editors, that they
fail to put a proper end-of-line at the end of the last line. In that
case, Vim doesn't see the file as being in "dos" fileformat, because one
of the lines (the last one) lacks a DOS/Windows-like end-of-line. It
opens the file as "unix" fileformat then, with a visible ^M at the end
of every line except the last. This ensures that any line which ended in
CR+LF will keep it, and that any line which ended in LF only won't get
an added CR before it.

To "repair" the file and make sure that every line, including the last
one, ends in CR+LF, open it with ++ff=dos (see :help ++opt)
either (if the file was already open in Vim)
:e ++ff=dos
or (if it wasn't)
:e ++ff=dos filename.ext

++ff=dos will regard either CR+LF or LF-alone as an end-of-line, and
regard the file as being in "dos" fileformat. (This requires Vim 7.2.040
or later; if you still have an earlier version, I recommend that you
upgrade ASAP — the latest published version of the sources is 7.3.666.)

This won't help if one or more lines end in CR+CR+LF (i.e. with two or
more carriage-returns before the linefeed). In that case, write the file
as unix and reopen it as dos to eliminate one level of spurious carriage
returns. Or else, if you have lines with many carriage-returns at the end,

:%s/\r\+$//
:setlocal ff=dos
:w " optional - you may do it later on

will eliminate any number of carriage-returns except one (and add one if
there were none) immediately before the linefeed at the end of a line.


Best regards,
Tony.
--
ARTHUR: I command you as King of the Britons to stand aside!
BLACK KNIGHT: I move for no man.
The Quest for the Holy Grail (Monty
Python)

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment