1748198 Members
2646 Online
108759 Solutions
New Discussion

No line wrap in vi

 
SOLVED
Go to solution
yaron1
Advisor

No line wrap in vi

Hi,

I need to work with a file that has very long lines. I dont need the whole record, just the first 30 to 80 characters of those lines. Vi wraps the lines but I need to see them line below line without the line wraps between them. It’s a basic vi (no vim mode), so :set nowrap doesn’t work. :set all shows wrapmargin=0 but if I do wrapmargin=7 nothing happens.
What can be done?

Thanks for the answers.
8 REPLIES 8
Bill Hassell
Honored Contributor

Re: No line wrap in vi

wrapmargin=7 will wrap after the next white space that is less than 7 characters from the current right margin. With an 80 character line, typing text at column 73 will trigger a wrap. But only when inserting. It does not affect the appearance of existing lines. So :set wm=0 (vi and vim) is the same as :set nowrap (vim only).


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor
Solution

Re: No line wrap in vi

How long are your lines?
I suppose you could set COLUMNS very large and then have your terminal emulator have the lines fall off the right.
Viktor Balogh
Honored Contributor

Re: No line wrap in vi

> I dont need the whole record, just the first 30 to 80 characters of those lines.

If you really only need those characters:

# cut -c30-80 /path/to/file

****
Unix operates with beer.
yaron1
Advisor

Re: No line wrap in vi

Hi,

:set wm=0 doesnt help. Do I need to put it in a restart hidden file so it takes effect before vi starts (which file then)?
I want to be able to scroll the lines to the right if I need to, so cut is not good. I want to see the lines in normal size so making long column will not be convenient to work with long column. Here is my :set all
:set all
autoindent mesg noslowopen
autoprint nomodelines tabstop=8
autowrite nonumber taglength=0
nobeautify nonovice tags=tags /usr/lib/tags
directory=/var/tmp nooptimize tagstack
nodoubleescape paragraphs=IPLPPPQPP LIpplpipnpbp term=hp
noedcompatible prompt noterse
noerrorbells readonly timeout
noexrc redraw timeoutlen=500
flash remap ttytype=hp
hardtabs=8 report=1 warn
noignorecase scroll=11 window=23
keyboardedit sections=NHSHH HUuhsh+c wrapscan
nokeyboardedit! shell=/usr/bin/sh wrapmargin=0
nolisp shiftwidth=8 nowriteany
nolist showmatch
magic noshowmode
[Hit return to continue]
Viktor Balogh
Honored Contributor

Re: No line wrap in vi

in vim this should work:

:set nowrap
****
Unix operates with beer.
Steve Post
Trusted Contributor

Re: No line wrap in vi

if the filename is myfile.out
IF you just need to look at it without modifying it.

adjust myfile.out > boguscopy.out
vi boguscopy.out

or while in vi.....
vi myfile.out
:.,.!adjust
:q!


Bill Hassell
Honored Contributor

Re: No line wrap in vi

> scroll to the right...

It sounds as if you want exactly one line per line on the screen and then be able to scroll everything to the right. vi is designed to work with real terminal windows, not GUIs that represent the text file. You can certainly put settings into $HOME/.exrc which will take effect as vi starts but it won't change the appearance of existing lines.


Bill Hassell, sysadmin
Viktor Balogh
Honored Contributor

Re: No line wrap in vi

>Itâ s a basic vi (no vim mode), so :set nowrap doesnâ t work.
ok, that one for vim isn't an option for you, I just noticed it right after I posted. But another idea, if read-only mode is enough:

# less -S FILENAME

this way the long lines will be chopped, and you an navigate with arrow keys. I think that's what you want. If you want editing also, press h and see the last section of the help of less. I think somehow editing is also possible with less.

****
Unix operates with beer.