How to wrap up

0 views
Skip to first unread message

Ajay Jain

unread,
Nov 19, 2008, 6:15:55 AM11/19/08
to vim...@googlegroups.com
Hi,

When I write a C code, I would like to wrap up after say 80 columns. Can
I do this in Vim? If yes, how? What are the related and useful commands
to wrap around while coding?

Regs,
Ajay.

Ben Schmidt

unread,
Nov 19, 2008, 7:01:55 AM11/19/08
to vim...@googlegroups.com

Make sure 't' is in formatoptions to wrap code and not just comments:

:set fo+=t

and set textwidth to 80

:set tw=80

are the main two.

:help 'fo'
:help fo-table
:help 'tw'

You'll probably also want auto-indenting of some kind turned on.

:filetype indent on

may well suit you. If not, just

:set autoindent

:help :filetype-indent-on
:help 'ai'

The gq command is helpful for rewrapping stuff that's already written. I
tend to use linewise visual mode (shift-V) to highlight lines and then
type gq.

:help gq
:help v_q

Others may have more tips. There are so many...

Ben.

Peter Palm

unread,
Nov 19, 2008, 8:36:20 AM11/19/08
to vim...@googlegroups.com, Ajay Jain
Op woensdag 19 november 2008, schreef Ajay Jain:
> Hi,

Hi,

:help wrap

eventually leads to 'textwidth', press <Ctrl>] to go to that help page.

so

:set textwidth=80

will set the maximum textwidth.

When you re-edit the already wrapped lines, visually select (press 'V')
the lines you want to reformat and hit gq (or just use gq$ to format
till the end of the line).

Regards,


Peter Palm

fritzophrenic

unread,
Nov 20, 2008, 10:43:02 AM11/20/08
to vim_use
The others have given you an answer, but I personally don't like my
code to auto-wrap (though I love that my comments do so).

Instead, I highlight any text after a certain line length, so that I
know I should probably shorten the line somehow:

http://vim.wikia.com/wiki/Highlight_long_lines

Erik Hahn

unread,
Nov 20, 2008, 11:45:35 AM11/20/08
to vim...@googlegroups.com

Mark the lines you want to wrap (with Shift-V or any other of the
v-commands), then type "!fmt<CR>"

-Erik

--
v4sw5RUYhw2ln3pr5ck0ma2u7Lw3+2Xm0l6/7Gi2e2t3b6AKMen5+7a16s0Sr1p-8.12/-6.56g6OR

Reply all
Reply to author
Forward
0 new messages