Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 611
chtenb Avatar asked Jan 24 '13 14:01

chtenb


People also ask

How do I use buffers in Vim?

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.

What is let in Vim?

: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 .

How do I close current buffer in Vim?

Assuming the default backslash leader key, you can also press \bd to close (delete) the buffer in the current window (same as :Bclose ).

How do I switch between buffers in Vim?

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.


1 Answers

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).

like image 113
Nikita Kouevda Avatar answered Oct 05 '22 01:10

Nikita Kouevda