” Toggle color highlight on 80th character I’d love to hear if it can be sensibly abbreviated. I’ve been wrestling with it for a while this morning, and I don’t really know what I’m doing, but this seems to work. Someone above asked about a function to toggle the highlights. I prefer the overlength line highlights shown here, instead of cursorcolumn, because this method only highlights lines that are actually too long, so is visually silent if nothing is wrong. This will highlight all characters past 74 columns (tweak that number as desired) in dark grey (tweak that color as desired), and is a nice visual cue when auto linewrapping isn't turned on when you should think about breaking things.ģ8 Responses to “How to use Vim’s textwidth like a pro” For further good measure, I explicitly say set fo-=t in my vimrc, to prevent myself from being surprised (since I do primarily coding in vim).Īutocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#592929Īutocmd BufEnter * match OverLength /\%74v.*/ You probably have a statusline of your own just add that small snippet minus the ellipses in somewhere convenient. The value of format-options will drastically change the way Vim behaves, so I highly recommend keeping it displayed some where you can reference it quickly. The curly braces move you between paragraphs. vap is also equivalent, although it selects a whole paragraph and is more appropriate if you want to, say, delete it. The big one is vip (preceding v puts us in visual mode, for selection), which selects an "inner paragraph" this means that if you're anywhere inside of a paragraph, you can type vip and have the entire thing instantly selected for you, possibly for you to run gq subsequently.
gq: performs a "formatting operation", which in our universe means "rewrap the text." This will respect leading indent and symbolic characters, which is usually nice but a little obnoxious if you're reflowing a bullet point (since the text will suddenly acquire asterisks in front of everything).Note also that some filetype will automatically give you fo+=t, while others won't. Notice that to get automatic wrapping you need both fo+=t as well as tw or wm to be nonzero. tw=72 fo=cqt wm=0: Automatic wrapping at col 72.tw=0 fo=cqt wm=5: Automatic wrapping at a 5 col right margin.tw=0 fo=cqt wm=0: No automatic wrapping, rewrapping will wrap to 72.tw=72 fo=cq wm=0: No automatic wrapping, rewrapping will wrap to 72.tw=0 fo=cq wm=0: No automatic wrapping, rewrapping will wrap to 80.Understanding the interaction between these two options is important. wrapmargin (or wm): controls when to wrap based on terminal size I generally find using this to be a bad idea.There are also a number of auxiliary format options, but they're not as important. Toggle the flag on with :set fo+=t, and toggle it off with :set fo-=t. formatoptions (or fo): controls whether or not automatic text wrapping is enabled, depending on whether or not the t flag is set.
If this value is set, you're entirely at the whimsy of the below formatoptions, which is often filetype sensitive. Use :set tw=72 to set the wrap width by default it's unset and thus disables line-wrapping.
#HOW COME MY MACVIM .VIM IS EMPTY CODE#
When programming, automatic line wrapping can be a little obnoxious because even if a piece of code is hanging past the recommended 72/80 column width line, you probably don't want to immediately break it but if you're writing a text document or an email message, that is specifically the behavior you want. This post falls into that category, but I'm hoping to do a more comprehensive view into one small subsystem of Vim's configuration: automatic line wrapping. There are lots of little blog posts containing advice about various one-line options you can do in Vim.