if __name__ is None
if __name__ is None

Reputation: 11533

How to set wrap for single buffer

When I start up Vim, my .vimrc instructs the :nowrap mode. I hate the wrap while coding, as it ruins indentation and supports the coding style, where single lines get too long, too complex and less readable/concise.

However, while editing files like HTML, wrap mode is helpful, specially where there is lots of text content. It allows for faster line navigation (gj, gk...), and having long lines doesn't really matter.

So I'd like Vim set the :wrap setting based on current filetype. I tried:

autocmd FileType html,eruby,erb set wrap

However, once .html file is opened, this affects all open buffers. I would like this to affect just .html containing buffers.

Any ideas?

Upvotes: 3

Views: 1531

Answers (1)

Daan Bakker
Daan Bakker

Reputation: 6332

If you look at the help page for 'wrap', you'll see that it applies to windows instead of buffers:

                                        *'wrap'* *'nowrap'*
'wrap'      boolean    (default on)
            local to window
            {not in Vi}

This means that you have 3 options:

  • Create an autocommand for BufEnter that reapplies wrap whenever you switch buffers
  • Use an easy hotkey to switch between wrapping, such as: nnoremap <F2> :set invwrap
  • Close windows like these instead of re-using them

Upvotes: 3

Related Questions