Sunday, August 15, 2010

Re: Writing files without EOL -> :set noeol

On 16/08/10 03:18, Peter Hodge wrote:
> --- On Mon, 16/8/10, Sven Guckes<guckes@guckes.net> wrote:
>
>> From: Sven Guckes<guckes@guckes.net>
>> Subject: Re: Writing files without EOL -> :set noeol
>> To: "vim_use"<vim_use@googlegroups.com>
>> Received: Monday, 16 August, 2010, 11:13 AM
>> * Peter Hodge<toomuchphp-vim@yahoo.com>
>> [2010-08-16 03:08]:
>>> Is there a way to make vim write a file using dos
>> line
>>> endings (<CR> <NL>) but *without* the EOL
>> at the end?
>>
>> yes... use ":set noeol"
>
> No, the 'eol' option is ignored unless I set 'binary' also. But if I set 'binary', the file is written as though fileformat=unix, I need it to be written with fileformat=dos.
>
> Peter
>
>
>
>

Well, then you'll just have to open the file with

:e ++bin ++ff=unix filename

then make sure that there is a visible ^M at the end of each line except
the last. You can put it there by hitting Ctrl-V (or Ctrl-Q if you use
Ctrl-V to paste) followed by <Enter> just before (and in addition to)
the <Enter> which breaks the line. You may even make the mappings (to be
sourced in an "after-plugin" of the ftplugin kind whenever you open one
of those files:

(untested)
map <buffer> o A<C-V><CR><CR>
map <buffer> O O<C-V><CR><Left>
imap <buffer> <CR> <C-V><CR><CR>

and maybe others. Of course this will still not take care of lines
broken by means of a \r in the "replace by" part of a :substitute -- I'm
not sure how to insert a "real" ^M at that point.

Or else, maybe you could write a BufWritePre autocommand to add a ^M at
the end of any line (other than the last) which hasn't yet got one.
Something like this (untested)

function! AddCarRet()
if getline('.') !~ '\r$'
exe "normal A\<C-V>\r\e"
endif
endfunction
au BufWritePre <buffer> 1,$-1call AddCarRet()

Note that if ever you try to concatenate two files, the first one of
which lacks a proper EOL on its last line, the resulting file will have
the last line of the first part and the first line of the second part
concatenated as one long line. Not something desirable IMHO.


Best regards,
Tony.
--
The opposite of a profound truth may well be another profound truth.
-- Bohr

--
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: