LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-26-2004, 02:25 PM   #1
gschrade
Member
 
Registered: Oct 2003
Posts: 52

Rep: Reputation: 15
how to avoid new line character


I am useing Red Hat 9. I am trying to edit an XML file with vi. I have one line that wraps to the next line and puts a new line character in automatically. I tried to use a hard return and that does not work either. Anyway, the XML parser pukes when it sees any of these characters. Is there any way to avoid that?

Thank you in advance
 
Old 02-26-2004, 02:51 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
In command mode:

:set tw=<number>

If you want to make it permanent, edit (create) .vimrc and add (edit) the line.

You can also specify (although this may be vim only) a tw associated with a file type:

Something like this (in /etc/vimrc or .vimrc, up to you):

if has("autocmd")
" Set some pre-defined text width's
" text
autocmd BufRead *.txt set tw=78
" shell & programming
autocmd BufRead *.sh,*.bash,*.ksh,*csh,*zsh set tw=256
autocmd BufRead *.awk,*.c,*.cpp,*.perl,*.sed set tw=256
" web
autocmd BufRead *.htm,*.html,*.xml set tw=128
autocmd BufRead *.php,*.css set tw=256
" misc.
autocmd BufRead *.cf*,*.conf*,*sql set tw=128
endif


In this example .html (.htm) and .xml have a tw of 128 chars.

Hope this helps.
 
Old 02-26-2004, 03:20 PM   #3
gschrade
Member
 
Registered: Oct 2003
Posts: 52

Original Poster
Rep: Reputation: 15
I tried entering :set tw=128 and it did not work. Am I missing something?
 
Old 02-26-2004, 04:41 PM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Where/how did you enter this?
 
Old 02-26-2004, 04:51 PM   #5
gschrade
Member
 
Registered: Oct 2003
Posts: 52

Original Poster
Rep: Reputation: 15
The file is server.xml. I entered vi server.xml. Then I entered :set tw=128
 
Old 02-26-2004, 04:53 PM   #6
dford
Member
 
Registered: May 2003
Location: Kansas
Distribution: RH 9, OpenBSD, FreeBSD
Posts: 60

Rep: Reputation: 19
Go into vi and hit ESC then :set all

Copy the output and let us see it.
 
Old 02-26-2004, 05:07 PM   #7
gschrade
Member
 
Registered: Oct 2003
Posts: 52

Original Poster
Rep: Reputation: 15
there is a large amount of output. Is there something in particular that I should be looking for?
 
Old 02-26-2004, 05:15 PM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Better try that with : set, less info but the basics should be there.

The thing you should be looking for is the textwidth=<number> line. It should change if you use the ESC :set tw=<number> sequence.

tw is an abbriviation for textwidth.

Last edited by druuna; 02-26-2004 at 05:17 PM.
 
Old 02-26-2004, 05:29 PM   #9
gschrade
Member
 
Registered: Oct 2003
Posts: 52

Original Poster
Rep: Reputation: 15
textwidth=0
 
Old 02-26-2004, 05:37 PM   #10
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
Before and after you tried the ESC:set tw=<number> sequence?

Start vi with your file, once 'inside' vi make sure you are in command mode (press ESC to make sure). Then:
:set tw=128 <enter>
:set

The textwidth= line should say 128 and lines should be broken off around the 128-th character.

If this doesn't work, try editing your .vimrc file (should be in you home dir, if not, create it). Put the following in it:

set tw=128

After that start a vi session and check again (:set).
 
Old 02-26-2004, 05:38 PM   #11
dford
Member
 
Registered: May 2003
Location: Kansas
Distribution: RH 9, OpenBSD, FreeBSD
Posts: 60

Rep: Reputation: 19
Okay here is mine:

:set all
noautoindent
autoprint
noautowrite
nobeautify
directory=/var/tmp
nodoubleescape
noedcompatible
noerrorbells
noexrc
flash
hardtabs=8
noignorecase
keyboardedit
keyboardedit!
nolisp
nolist
magic
mesg
nomodelines
nonumber
nonovice
nooptimize
paragraphs=IPLPPPQPP LIpplpipnpbp
prompt
noreadonly
redraw
remap
report=5
scroll=19
sections=NHSHH HUuhsh+c
shell=/bin/ksh
shiftwidth=4
noshowmatch
noshowmode
noslowopen
tabstop=4
taglength=0
tags=tags /usr/lib/tags
tagstack
term=vt100
noterse
timeout
timeoutlen=500
ttytype=vt100
warn
window=39
wrapscan
wrapmargin=0
nowriteany



In this version of vi the only thing I would look out for is "wrapmargin". If it is non-zero that will cause a problem: it will autowrap lines that value prior to the end of the visible line. Your version of vi may have other options that will affect each line.

Otherwise you shouldn't have any newlines inserted that you don't put in. Note that there is a limit to how long the line can be: on my system it is 4095 (plus the newline makes 4096).
 
Old 02-26-2004, 06:07 PM   #12
gschrade
Member
 
Registered: Oct 2003
Posts: 52

Original Poster
Rep: Reputation: 15
I set tw to 128 and verified that when I went to set. I also verified that wrapmargin is set to 0. However, when I edited the file it still wrapped at the end of the line and the xml parser still does not like it.
 
Old 02-27-2004, 04:50 AM   #13
dford
Member
 
Registered: May 2003
Location: Kansas
Distribution: RH 9, OpenBSD, FreeBSD
Posts: 60

Rep: Reputation: 19
Quote:
Originally posted by gschrade
I set tw to 128 and verified that when I went to set. I also verified that wrapmargin is set to 0. However, when I edited the file it still wrapped at the end of the line and the xml parser still does not like it.
:set tw=0

Setting textwidth to a non-zero value is exactly what you don't want. It will break the line on whitespace to attempt to get a line the length you specified. The wrapmargin setting does essentially the same thing, but bases its linebreak from the width of the screen.

In vi type
:help 'textwidth'
to get more info.

You might also check out
:help 'paste'
which sets a number of settings to "safe" values for pasting text.

Hope this helps.
 
Old 02-27-2004, 09:28 AM   #14
gschrade
Member
 
Registered: Oct 2003
Posts: 52

Original Poster
Rep: Reputation: 15
If I set it to 0 or if I set it to 128 it is the same--it still wraps and causes the xml parser to fail
 
Old 02-27-2004, 09:42 AM   #15
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389Reputation: 2389
I suggested putting the line in ~/.vinrc, did you try that.

If that still doesn't work try vim's homepage:

http://www.vim.org/
Especially:
http://vimdoc.sourceforge.net/vimfaq.html#19.1
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ text file line by line/each line to string/array Dimitris Programming 15 03-11-2008 08:22 AM
Perl - Tpl file - Need to replace new line character. knnirmal Programming 2 09-07-2004 02:27 PM
end of line character hyperriven Linux - General 1 04-07-2004 08:24 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM
Bash scripting - add a character to a line. welby Programming 1 01-14-2004 10:09 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration