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?
Use the ":sbuffer" command passing the name of the buffer or the buffer number. Vim will split open a new window and open the specified buffer in that window. You can enter the buffer number you want to jump/edit and press the Ctrl-W ^ or Ctrl-W Ctrl-^ keys. This will open the specified buffer in a new window.
:let on the other hand can do almost everything that :set can do, plus more. It can assign a value to. a variable, e.g. let vi = 'vim' an option, e.g. let &tw = 40. a register, e.g. let @a = $HOME .
Assuming the default backslash leader key, you can also press \bd to close (delete) the buffer in the current window (same as :Bclose ).
Pressing Alt-F12 opens a window listing the buffers, and you can press Enter on a buffer name to go to that buffer. Or, press F12 (next) or Shift-F12 (previous) to cycle through the buffers.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With