Between the RHEL package managers and the upstream providers for Vim, the default formatting options for some file types is wrong and exceedingly difficult to override. (I’m using Scientific Linux 6.0, but they deny changing the Vim packages provided by Red Hat.)
We want it our way, and we will fight until we get it. Most people do not use proper headings in their HTML files, but as long as things work, it’s no big deal. However, when the folks coding some of the most nit-picking purist orthodoxy in the world accommodate bad practices by forcing that accommodation on others, it’s just plain wrong. But I know better than to try appealing to the arrogant code gods for some flexibility. They are infallible, and won’t talk to ordinary users who can’t recite obscure pages of their voluminous documentation. Okay, so at least they write documentation. But it’s far outside the grasp of ordinary users, and the elitist mindset refuses to compromise with folks who simply want to use the software, not worship it. One way or another, you’re going to invest some time or the answers will not come.
I code my HTML files according to a currently accepted standard, known as XHTML Transitional. It renders well in all but a few obscure browsers, and it’s easier for me to remember all the precise details for tagging and so forth. As part of my training, I learned to put what are called “hard returns” at the end of each line, so that no matter what editor I had to use at the time, I could still read my own code and figure out what I did. Soft wrapping does not work for me. Again, it’s a valid choice, well understood and most text editors can work with that.
Except in Vim. I am by no means a Zen Master of Vim, nor do I ever want to be, nor should I have to be. I just use it for what I do. I took the time to learn how to construct a .vimrc
and .gvimrc
configuration files so I get Vim to behave as I like.
.vimrc
set spell spelllang=en
set spellfile=~/.vim/spellfile.add
set nocompatible
behave xterm
set shiftwidth=3
set tabstop=3
set backspace=indent,eol,start
set incsearch
syntax on
set showcmd
set wrap linebreak textwidth=72
set whichwrap=<,>,h,l,[,]
colorscheme koehler
I have fewer settings in my .gvimrc
because it inherits most of the settings from .vimrc
. The vast number of options are mind-numbing, and it was no small chore, but I found it worthwhile. But the code gods in their abundant wisdom have forced things which make Vim a real hassle when I use it for writing my HTML files. You see, they have developed this highly complex system of plugins for each file type, and they load after Vim parses my personal configurations. That means their choices cause Vim to ignore mine. It’s all explained here. I am utterly certain the Vim developers know this, and how it affects users, and probably snicker at the idea a really large number of duffers like me are either forced to become code gods themselves to fix it, or suffer in silence with the inconvenience.
I got lucky. I found out about querying Vim to see just where this hassle originates in the default plugin configurations. After poking around a bit, I discovered the problem was down to something which reset the format options from the default. In an open Gvim window, having typed nothing into the new unnamed file, hit the ESC key and then type exactly — :set formatoptions?
This returns "formatoptions=tcq"
. That’s what we like for those of use auto wrapping at fixed line widths.
But for HTML and related file types, that’s broken. If I load one of my HTML files, and perform the same incantations, I get "formatoptions=croql"
. Aside from a few other details, the missing “t” is what causes my pain. I used another query which pointed which file was doing this. After hitting the ESC key, I typed exactly — :verbose set formatoptions
— and found out it was /usr/share/vim/vim72/ftplugin/html.vim
.
So I logged in as root and opened that file. At around line 18, I found a batch of code starting with the highly offensive line — setlocal formatoptions-=t
— which specifically disables my line-wrap settings. Sure, after I finish a paragraph I can always wrap it with various commands to apply my chosen margins, but soft-wrap is very distracting for me while writing and trying to keep up with the HTML tags. I’d rather re-wrap after making changes. It’s the way I’ve done things since the first DOS editor I ever used, back in 1990. So I changed that file. Opening it in an editor, I used the peculiar Vim way of commenting out that (inserting a double quotation mark) and the next few lines which set those formatting options:
"setlocal formatoptions-=t
"if !exists("g:ft_xml_autocomment") || (g:ft_xml_autocomment == 1)
" setlocal formatoptions+=croql
"endif
I saved the file and test Gvim and all is now working as I like it.
Pingback: Taming the Beast: CentOS 6.2 and Inspiron 1525 Laptop « Do What's Right
Pingback: Tool Shed 5 | Do What's Right