Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set wrap for single buffer

Tags:

vim

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?

like image 623
if __name__ is None Avatar asked Mar 09 '26 02:03

if __name__ is None


1 Answers

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
like image 159
Daan Bakker Avatar answered Mar 10 '26 20:03

Daan Bakker