--- On Mon, 16/8/10, Tony Mechelynck <[email protected]> wrote:
> From: Tony Mechelynck <[email protected]> > Subject: Re: Writing files without EOL -> :set noeol > To: [email protected] > Cc: "Peter Hodge" <[email protected]> > Received: Monday, 16 August, 2010, 1:48 PM > On 16/08/10 03:18, Peter Hodge > wrote: > > --- On Mon, 16/8/10, Sven Guckes<[email protected]> > wrote: > > > >> From: Sven Guckes<[email protected]> > >> Subject: Re: Writing files without EOL -> > :set noeol > >> To: "vim_use"<[email protected]> > >> Received: Monday, 16 August, 2010, 11:13 AM > >> * Peter Hodge<[email protected]> > >> [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. I certainly don't want to be making sure ^M is at the end of each line, so I have written a command-line script to erase the last linebreak and an autocmd to call it when the 'eol' option is off. I understand the importance of having a newline at the end of the file, but in this circumstance it is more important to not change anything unless absolutely necessary. Regards, Peter -- 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
