LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to avoid new line character (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-avoid-new-line-character-150844/)

gschrade 02-26-2004 02:25 PM

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

druuna 02-26-2004 02:51 PM

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.

gschrade 02-26-2004 03:20 PM

I tried entering :set tw=128 and it did not work. Am I missing something?

druuna 02-26-2004 04:41 PM

Where/how did you enter this?

gschrade 02-26-2004 04:51 PM

The file is server.xml. I entered vi server.xml. Then I entered :set tw=128

dford 02-26-2004 04:53 PM

Go into vi and hit ESC then :set all

Copy the output and let us see it.

gschrade 02-26-2004 05:07 PM

there is a large amount of output. Is there something in particular that I should be looking for?

druuna 02-26-2004 05:15 PM

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

gschrade 02-26-2004 05:29 PM

textwidth=0

druuna 02-26-2004 05:37 PM

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).

dford 02-26-2004 05:38 PM

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).

gschrade 02-26-2004 06:07 PM

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.

dford 02-27-2004 04:50 AM

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

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

Hope this helps.

gschrade 02-27-2004 09:28 AM

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

druuna 02-27-2004 09:42 AM

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

dford 02-27-2004 09:54 AM

You might want to try
:set paste
This disables a bunch of the smart stuff that vi can do for you and in this case you want it to be "dumb".

How are you entering the code? Straight typing? Copy and Paste?

Are you in an Xterm, Kterm, command line (non-X environment), gvim,...?

Could you paste a short example into a message for us? Try to make the shortest XML that displays the problem.

:confused:

gschrade 02-27-2004 09:57 AM

I tried putting the line in ~/.vinrc and when I go to the file and check the sets, it does not set it to the number. I will try looking at the sites. Thanks

gschrade 02-27-2004 10:13 AM

I tried :set paste. That did not work either. I am just straight typing in command line mode.

The line I am trying to type is something like <value>jdbc:mysql://somemachine.someverylongdomainnameforaserver/somedatabase?user=someuser&password=somepassword</value>

druuna 02-27-2004 10:17 AM

Just though of something: I there a line in your xml code (at the top or bottom) that looks like:

/* vim:tw=4: */

The 4 can be another number.
If this line excists, vi will overrule all the other settings and use this (4 in the above example) as default for this document.

gschrade 02-27-2004 10:22 AM

just checked, nothing like that in the file. How can I tell if I have vim instead of vi? If it type vim at the command line, it does not recogize the command.

druuna 02-27-2004 10:32 AM

On my system (suse & slack):

/bin/vi -> vim (link to vim)
/bin/vim

dford 02-27-2004 10:38 AM

Most of the things we have been talking about only work in vim. Typically, on Linux, you have vim. When you type ":help" I think it tells you what program it is. Actually, just the fact that ":help" works indicates it is vim or a vim variant; native vi doesn't have alot of these extensions.

Unfortunately, here at work I only have access to vi. When I get home tonight I'll do some more looking.
Does arbitrary text line break?
Is it breaking on white space or always at the same point? What point does it break at?

gschrade 02-27-2004 10:45 AM

It breaks at the end of the screen. If tw was set to 255, would it still wrap or scroll to the right?

dford 02-27-2004 10:52 AM

wrap causes the display to wrap at the end of the screen.
wrapmargin and textwidth cause the data to wrap at the point specified. Although both of these break on whitespace by default.

If tw=255 and wrap is on the screen will show something like 3 full 80 characters display lines and a short 15 character line (given lucky white space). If nowrap is set the display will scroll right. Of course the above assumes the standard 80 character line, but since you said you were in the native command line that is a somewhat reasonable assumption.

dford 02-27-2004 11:14 AM

Okay, another thought.
:set compatible
make vim compatible with vi. This should override any vim special features leaving you with a smaller set of settings to worry about.


All times are GMT -5. The time now is 06:45 AM.