PyTis
PyTis

Reputation: 1134

VIM Auto Wrapping

I cannot seem to get autowrap to work. I've tried ":set fo ?" and the result is " formatoptions=tcq " I just spent 30 hours in google and other sites, and 2 hours here trying to figure this out. I've tried everything stated at: https://coderwall.com/p/wbyv_a/vim-automatic-wrapping-at-80-characters

My "lvimrc file (which I know is being sourced, because of the right blue column):

"" default overrides for this folder only
set ts=2
set tabstop=2
set expandtab
set shiftwidth=2
set softtabstop=2

set formatoptions+=t
set textwidth=79
set wrapmargin=2

set colorcolumn=80
hi ColorColumn ctermbg=blue guibg=red

highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%80v.\+/

And when I am in a line at col 70, and start typing, I can type right paste my blue line into the red, and no AUTO-WRAPPING happens, Any ideas? screenshot

Upvotes: 1

Views: 332

Answers (2)

PyTis
PyTis

Reputation: 1134

AHA!!! It was:

:set paste

I went through my /home/{USER}/.vimrc line by line, until I figured it out.

Fixed with:

:set nopaste 

Upvotes: 0

romainl
romainl

Reputation: 196546

You need two things for general automatic as-you-type linebreaks:

  • t in the value of :help 'formatoptions',
  • a non-zero value for :help 'textwidth'.

You may also need c in the value of formatoptions if you want automatic linebreaks in comments.

Since the default value of formatoptions is tcq, all you really need is to set textwidth to the desired value:

set textwidth=80

text

For some (most?) programming languages, the default formatoptions is overridden by the active ftplugin so that only comments get that treatment. This is incidentally the case for PHP, where lines of code don't get broken but comments do:

php

Upvotes: 3

Related Questions