3

I have a section of my vimrc (which I don't fully understand) that wraps text over 80 columns and and if there is such a line, colors the excess red.

set textwidth=80
set tw=80
set wrap
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%81v.\+/

This works quite well in general but I want to disable the entire thing (wrapping and matching) when the filetype is .py (and in principle, other filetypes).

Similar, but not quite the same question at Limiting a match in vim to certain filetypes?

Community
  • 1
  • 1
mgold
  • 5,551
  • 4
  • 35
  • 41
  • This looks like a duplicate of this question: http://stackoverflow.com/questions/3146410/enablind-and-disabling-word-wrap-automatically-on-different-file-extensions-on-v – joce Aug 22 '12 at 23:32

1 Answers1

4

First, a note: tw and textwidth are the same thing (tw is just the abbreviated name, variables generally have a long and short form) so you only need one of those first two lines in any case.

I suspect what you're really looking for is what I was looking for earlier, which is: how to keep settings specific to various file types. It actually gets fairly complicated because some settings (like textwidth) are what vim calls "local to buffer", and others (like wrap) are "local to window". The difference boils down to what happens if you (for example) run vim foo.txt and then use :split to get two windows viewing foo.txt. There is now one buffer, hence one textwidth, for foo.txt, but there are two windows, hence two wraps.

Until you start using this feature for things, though, you probably just want to try out the suggestions in http://vim.wikia.com/wiki/VimTip1510 for making each setting depend on what filetype is set to. Editing a file named foo.py will use the Python settings, because vim automatically sets filetype=python for files whose name ends in .py. You can manually set the file type (:set filetype=whatever) if the file name suffix is unknown or ambiguous (e.g., when editing file zog which has no suffix at all but is actually a shell script, you can manually :set filetype=sh), and there is a lot of other info you can find on making vim automatically recognize particular file types.

(Another side note: I don't agree with their setting tabstop=4; I use softtabstop=4 and smarttabs and expandtabs so that I get nothing but spaces in my *.py files. This avoids the fight over whether tabs are placed at every 4 or 8 columns. :-) )

As for highlighting long lines in general, see http://vim.wikia.com/wiki/Highlight_long_lines for an explanation of what you're doing now, and why it's obsoleted if you have vim 7.3. See also vim-80-column-layout-concerns.

Community
  • 1
  • 1
torek
  • 330,127
  • 43
  • 437
  • 552