Larry Alkoff wrote:
Larry Alkoff wrote:
I frequently copy and paste text from web pages and would like to break lines at (say) 72 without splitting words.

My preference is to do this either on the command line
or by
ESC :command

I've read the post in the thread "auto-wrapping text" by A.J.Mechelynck
in which he suggests gggqG
but I can't see how to do this from either command line or EX command.

vim wrapmargin=40 testfile
does not work.

The best thing I've seen so far is, in vi
:set wm=0   or   :set wm=5
both of which cause vi to wrap lines at 0 or 5 characters from the _right_ margin which comes to a maximum line of 62 which is a little small.

I've also tried
set tw=nn
which doesn't seem to do anything.

I can't seem to find the appropriate command either on line of using my favorite reference O'Reilly's "VI Editor Pocket Reference".

Could someone help me?

Larry


Following up on the above post I have found that the command
:set textwidth=72
does what I want.

Is there any way I can do this when I invoke vim for the purpose of pasting in text from websites?

My present .vimrc contains the lines:
autocmd FileType text setlocal textwidth=78
which doesn't appear to work when pasting text.
Maybe the line should be a simple
textwidth=72 ??

Looking at the book "VI Improved Vim"
it appears that I could have a special .vimrc called .vimrcp
which would be my normal .vimrc with the line above changed to
textwidth=72
and vim would be invoked with the alias
alias vimpaste='-u .vimrcp'

I'll try this tomorrow.

Larry


Larry,

As far as I know, Vim won't autowrap blocks of text you paste in. Something could be written I suppose, but I don't know of something already doing it.

However, there is a reasonably convenient command to accomplish what you want on a paragraph-by-paragraph basis. Placing your cursor on any part of any line of the paragraph you wish to rewrap to your specified right margin, type:

gqip

and there you are. Now, you must ensure that there is at least one blank line between the first line and the preceding paragraph of text as well as another between the last line and the succeeding paragraph. If not, then you'll wrap those into your paragraph as well with this command.

Last comment: this incantation will respect your indentation. If the first character of the first line begins in, say, column 40, then all the text will be indented to 40 as it's wrapped (between 40 and 72).

Best regards and Vim on...

Russ

Reply via email to