chtenb
chtenb

Reputation: 16184

How to set an option, using let, for the current buffer (vim)?

In vimlanguage, you can set options for the current buffer only using setlocal. However, I need to set a more complex expression than just a literal, which isn't possible with setlocal.

I currently have let &formatprg=s:prgpath." ".a:args, but this sets the formatprg for all buffers, which is not what I want. How would I set the formatprg like above, only for the current buffer?

Upvotes: 9

Views: 3371

Answers (2)

Ingo Karkat
Ingo Karkat

Reputation: 172510

Making a global option buffer-local requires changes to Vim's source code. Alternatively, I've just published the GlobalOptions plugin that uses autocmds to work around this, and turns any global option into a buffer- or window-local one.

Upvotes: 1

Nikita Kouevda
Nikita Kouevda

Reputation: 5746

Use let &l:option instead of let &option to only change the local value, like setlocal option. Similarly, let &g:option would only set the global value, like setglobal option. See :help :let-option for more information.

Note that formatprg in particular is global (no "local to buffer" in its help).

Upvotes: 20

Related Questions