Is there a way to make vim write a file using dos line endings (<CR> <NL>) but *without* the EOL at the end?
Currently it seems vim will only let me:
A) Add newlines for no good reason
B) Convert files to Unix line endings
It looks like I will need to write a shell script to strip the EOL after writing, set up an autocmd to run it, and also set up an autocmd to skip the FileChanged warning ... isn't there a better way?
Peter
yes... use ":set noeol"
Sven
Peter Hodge wrote:
> Dear Vimmers,
>
> Is there a way to make vim write a file using dos line endings (<CR> <NL>) but *without* the EOL at the end?
Isn't this just another way of saying "mac format"?
:set ff=mac
:help ff
Brett Stahlman
Have you experimented with the 'noeol' option?
:help 'eol'
> Currently it seems vim will only let me:
>
> A) Add newlines for no good reason
It's actually for very good reasons[1]
It's one of those "just because Vim allows you to do it, doesn't
mean that it's a good idea" options. But if you're willing to
deal with the consequences of ":set noeol", you're welcome to and
Vim won't stop you. :)
-tim
[1]
http://stackoverflow.com/questions/729692/why-should-files-end-with-a-newline
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
Stahlman Family wrote:
>
>
> Peter Hodge wrote:
>> Dear Vimmers,
>>
>> Is there a way to make vim write a file using dos line endings (<CR>
>> <NL>) but *without* the EOL at the end?
>
> Isn't this just another way of saying "mac format"?
Ah. It occurred to me after I'd read Sven's reply that you probably
meant "without the EOL at the end of the file". I was thinking you mean
without the newline at the end of the line. Sorry for the confusion...
Brett Stahlman
...[snip]...
>>
>>
>>
>
> From: Stahlman Family <bretts...@comcast.net>
> Subject: Re: Writing files without EOL
> To: vim...@googlegroups.com
> Received: Monday, 16 August, 2010, 11:15 AM
>
>
> Peter Hodge wrote:
> > Dear Vimmers,
> >
> > Is there a way to make vim write a file using dos line
> endings (<CR> <NL>) but *without* the EOL at the
> end?
>
> Isn't this just another way of saying "mac format"?
Sorry, I do mean fileformat=dos, but I need vim to NOT write a CRNL at the very end of the file, unless there was already one there.
Peter
> From: Tim Chase <v...@tim.thechases.com>
> Subject: Re: Writing files without EOL
> To: vim...@googlegroups.com
> Cc: "Peter Hodge" <toomuch...@yahoo.com>
> Received: Monday, 16 August, 2010, 11:15 AM
> > Is there a way to make vim write
> a file using dos line endings
> > (<CR> <NL>) but *without* the EOL at
> the end?
>
> Have you experimented with the 'noeol' option?
>
> :help 'eol'
The 'eol' option only works if I also turn on 'binary', but if I use 'binary' I can only write the file using fileformat=unix. I need to write the file using fileformat=dos but without \r\n at the very end of the file, unless it was already there.
>
> > Currently it seems vim will only let me:
> >
> > A) Add newlines for no good reason
>
> It's actually for very good reasons[1]
I know there are reasons for having newlines at the end of a file, but I need to avoid changing code unnecessarily.
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
--- On Mon, 16/8/10, Tony Mechelynck <antoine.m...@gmail.com> wrote:
> From: Tony Mechelynck <antoine.m...@gmail.com>
> Subject: Re: Writing files without EOL -> :set noeol
> To: vim...@googlegroups.com
> Cc: "Peter Hodge" <toomuch...@yahoo.com>
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
On So, 15 Aug 2010, Peter Hodge wrote:
> 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.
How about something like this:
fun! WriteFilewithoutEOF(filename)
let a=getline(1,line('$')-1)
let b=map(a, 'v:val . nr2char(13)')
call extend(b, getline('$', '$'))
call writefile(b,a:filename, 'b')
endfun
com! -complete=file -nargs=1 WriteFile :call WriteFilewithoutEOF(<q-args>)
You could call this via a BufWriteCmd autocommand.
(I think, this should write DOS like files without an EOF, but please
verify.)
regards,
Christian
--
Letzte Worte eines Informatikers:
"Ich bleibe hier, bis das Problem gel�st ist."
--
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
I saw that there were mentioned several solutions. Did you try them?
regards,
Christian
--
On Tue, November 16, 2010 9:35 am, Lenin Lee wrote:
> Yes, Peter has made himself very clear, we do have tried some solutions,
> the problem is:
Yes, I understand already from your previous request. But if I read
the whole thread at
http://groups.google.com/group/vim_use/browse_frm/thread/95fb82624647bab2
there were mentioned several solutions, like Tony's:
http://groups.google.com/group/vim_use/msg/32e2d3ad0041381c
or mine:
http://groups.google.com/group/vim_use/msg/0470265234fd4317
Did you try those?
regards,
Christian
I used to, and I wouldn't be surprised if the person there is still that anal.
--
.
A text file that does not end in a line break is usually considered
"broken". For some definition of "broken". Quite often it means it was
truncated. Or it was written by an editor which I would call "broken".
A binary file does not need to end in a line break. So that's how it
works. And yes, this is old vi behavior.
A line break is certainly not invisible. If it looks that way, your
change management system is hiding that from you.
--
(letter from Mark to Mike, about the film's probable certificate)
For an 'A' we would have to: Lose as many shits as possible; Take Jesus
Christ out, if possible; Loose "I fart in your general direction"; Lose
"the oral sex"; Lose "oh, fuck off"; Lose "We make castanets out of your
testicles"
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
regards,
Christian