vim editor -> uncounted new line


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users vim editor -> uncounted new line
# 1  
Old 03-19-2010
vim editor -> uncounted new line

Hi,

I entered the following text in a new file through vim: "Four score and seven years ago" saved and exit.

When I looked at the file size, it was 31B, although is supposed to be 30. I reedited the file (again with vim) to check for errors, but everything seemed fine. When I opened the file with smultron (just another text editor, if you wondered) I noticed there was a new line. Deleting this new line, solved the issue => file size =30B.

Once again I reopened the file with vim , without even going into "insert" mode, and closed it. The file was once again 31B.

What is happening ?

Thank you.

P.S. Using OS X 10.5
# 2  
Old 03-22-2010
Quote:
Originally Posted by prostiiinet
Once again I reopened the file with vim , without even going into "insert" mode, and closed it. The file was once again 31B.
What do you mean by "closed it". I'll assume you saved, vs exiting without saving the file.

Quote:
Originally Posted by prostiiinet
What is happening ?
I think it's obvious. vim is adding a newline char to your file. The correct question would be _why_ is vim adding the newline to your file?

When you open the file in vim (use the same file), type :set fileformat & see if it says "unix" or "dos" -- if it says dos, that's why it's adding the file.

Check your .vimrc and see if it's set in there. Also, vim might be adding that setting based on your file extension. I've had a similar problem with vim automatically adding a newline (during my edit session) after 80 characters in length because my file extension was .txt.
# 3  
Old 03-22-2010
Quote:
What do you mean by "closed it". I'll assume you saved, vs exiting without saving the file.
I exited without saving.

Quote:
set fileformat & see if it says "unix" or "dos"
it is unix

Quote:
I've had a similar problem with vim automatically adding a newline (during my edit session) after 80 characters in length because my file extension was .txt.
It has the same behavior regardless the extension.

Quote:
Check your .vimrc and see if it's set in there
my .vimrc only contains

Code:
set background=dark
set number


P.S. Thank you for your answer. And yes you are right, I was wondering why vim does that.
# 4  
Old 03-24-2010
Quote:
Originally Posted by prostiiinet
I exited without saving.
Then it should not have written any extra data to your file at all, regardless.

If there's no newline char at all, vim will add one (but not if you exit without saving). I don't know if it's possible to not add it.

I misread your initial message as it keeps adding a windows formfeed char, instead of just a newline char.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Vim, vi and nano editor shows help.txt automatically

Hi, Whenever i try to open a file in any editor like vi, vim and nano i get this help.txt showing up in split screen without any key being pressed. This continues to pop up even when i close the help.txt. This behavior happens only when i am connected via putty. Is there a fix to this issue? ... (1 Reply)
Discussion started by: sunil0391
1 Replies

2. UNIX for Dummies Questions & Answers

VIM Editor - To disable the status on existing

When i exist the vim editor .. to gives '0' in the console... i think it is status of the exit.. How to disable that ... (14 Replies)
Discussion started by: greenworld123
14 Replies

3. UNIX for Dummies Questions & Answers

vim copy line and paste at the beginning, middle, and end of another line

How would you do vim copy line and paste at the beginning, middle, and end of another line. I know yy copies the whole line and p pastes the whole line, but on its own separate line. Sometimes I would like to copy a line to the beginning, middle, or end of another line. I would think this would be... (3 Replies)
Discussion started by: cokedude
3 Replies

4. UNIX for Dummies Questions & Answers

the turn on color in vim editor

how to turn on the color in vim editor."syntax on" is not working for me. when i do syntax on it only make some of the text basically header files nd functions name in bold.i am working on "secure crt" ..my vim is in /usr/share i also have .vimrc file in my home folder "~" Please help me... (11 Replies)
Discussion started by: ascetic
11 Replies

5. UNIX for Dummies Questions & Answers

tip: Simple script won't run in cygwin - vim editor involved

I ran into this issue and thanks to various postings in various forums, was able to figure out the solution but didn't see one posting that laid the whole issue out cleanly. So thought the following might help others ... ------------------------------------------------------------------------... (2 Replies)
Discussion started by: oxysep
2 Replies

6. UNIX for Dummies Questions & Answers

Syntax coloring for .pc files in VIM editor

Hi, i am using VIM editor through Putty. By the option of Syntax on in .vimrc file i am able to see syntax colors in .c and .cpp files but not in the files with .pc extension. How can this be done? :confused: (2 Replies)
Discussion started by: RuchK
2 Replies

7. UNIX for Advanced & Expert Users

Ctags in VIM Editor

Hi, I want to use ctags for multiple folders containing .c and .h files. Can anyone help me with it? I have been using ctags for 1 folder at a time but I would like to link multiple folders and access all .c files at a time using ctags. Thanks, shahsm (1 Reply)
Discussion started by: shahsm
1 Replies

8. UNIX for Advanced & Expert Users

line completion in vim

how we achive line completion and word completion in vim editor? (2 Replies)
Discussion started by: lakshmananindia
2 Replies

9. UNIX for Dummies Questions & Answers

vim as command line editor

Here is my problem, I manage a SunOs 5.8 Server, vi is the default command line editor, I have a line on each users .kshrc profile as follows: export EDITOR=/bin/vi I want to use vim as the command line editor, the below line doesn't work export EDITOR=/bin/vim Thank you (1 Reply)
Discussion started by: tony3101
1 Replies

10. Programming

vim editor

in vim editor, if i want to save that file, i have to save and exit (ZZ). i want to be able to save the file without exiting. that way, i can compile the code and if i need to change some coding, i can just switch over without retyping "vim myprogram.c". is there a way to save without exit?... (7 Replies)
Discussion started by: bb00y
7 Replies
Login or Register to Ask a Question