Using vim, is there a command so that the inserted text is automatically wrapped in a line?

CONTEXT . Part of the work I do involves inserting paragraphs of text from the word doc into a ruby ​​file.

PROBLEM . These paragraphs are inserted as one very long line of text, and I have to manually insert new lines to make lines of reasonable length.

SOLUTION Is there a way to make the insert function "aware" of the valid field boundaries and wrap the text when pasting?

+8
ruby vim text edit
source share
4 answers

first execute the given text width

:set tw=80 

then do gqq - for one line

for the whole file

 ggVGgqq 
+12
source share

Of course you can do it with

:set wrap

This will show the text as wrapped without changing the basic structure or inserting line breaks. Sometimes it is also useful:

:set linebreak

This makes vim wrap itself up without breaking words.

It is also possible:

:set wrapmargin

Determines how far the right packaging should begin.

+4
source share

vi, vim and gvim support ex level commands:

 :set ws wm=10 

which sets the transfer marker with 10 characters from the right border and forcibly performs the β€œwrapping” - automatic packaging as you type. This will not work to insert text. To do this, there is the 'fmt' command, which is native to Unix / Linux and is provided on Cygwin and GnuWin32 (see How can I get functionality for Vim on Windows? ) ..

The fmt command provides a filter for reformatting existing text with word breaks and accepts a numeric flag (for example, "-80") to indicate the line width. You can call this from the vim editor after pasting in long lines.

You do:

 !!fmt 

reformat a long line (key combination for ex: ".! fmt" command)

Or, to redo the whole paragraph:

 !}fmt 

from the first line of the paragraph.

This should save some time.

+4
source share

I usually need to import text and then wrap the entire document: I use:

:g/./normal gqq

Hope this helps.

+3
source share

All Articles