Skip to main content
52 votes
Accepted

When to use the after/ directory?

Generally, if you want to add your own plugin, or replace a standard plugin with your own, it would go into ~/.vim/plugin or ~/.vim/ftplugin. If instead you want to keep the functionality of an ...
garyjohn's user avatar
  • 6,329
37 votes
Accepted

How to apply a setting in all open tabs and windows?

Yes, there is! You can accomplish this with :tabdo and :windo. For your case specifically: :tabdo windo set number See :help :tabdo and :help :windo for more information.
Tumbler41's user avatar
  • 7,746
21 votes
Accepted

How do I use a variable or return value in option, command, or mapping?

The reason your example attempts don't work is that in many locations text is simply seen as a literal string, rather than VimScript. So functions, variables, and the like don't work. For example, if ...
D. Ben Knoble's user avatar
  • 26.2k
16 votes

`set` option with variables

You could use :exe, but this is extremely cumbersome to use and you'll need to escape a few things. I used to use my own path fixing function. It looked like: exe 'set rtp+='.lh#path#fix(...
Luc Hermitte's user avatar
  • 17.4k
11 votes

The simplest way to start Vim in private mode

Well, a bit belated but to respond to: Some magic (from a comment by Carpetsmoker in this thread) My general idea was that you always want to start "private mode" if you're using an ...
Martin Tournoij's user avatar
11 votes
Accepted

Can I set multiple 'options' with a single `:set` command spread over multiple lines?

I'd personally recommend against doing so, but you can use Vim's "line continuation" feature for this: set number \ showmatch \ hlsearch This will be interpreted by Vim as if the contents ...
Rich's user avatar
  • 32k
9 votes

`set` option with variables

You could use an environment variable defined within your current shell session. let $myvimdir = '/home/abc/vimfiles' That way you can use other variables to compose the path as well: let $myvimdir ...
iznav's user avatar
  • 91
9 votes

How to apply a setting in all open tabs and windows?

:tabdo windo set number gets the job done, but I don't really like it since it actually switches to each tab and window before running the command. After it finishes running, you'll end up on the ...
Tommy A's user avatar
  • 6,770
8 votes
Accepted

Are spaces OK in set statements?

From :help :set-args: White space between {option} and '=' is allowed and will be ignored. White space between '=' and {value} is not allowed. So: set history=1000 " is ok. set history =1000 ...
tokoyami's user avatar
  • 935
8 votes
Accepted

How do I exclude the → from file name characters?

:h gf says: If the file can't be found, 'includeexpr' is used to modify the name and another attempt is done. And for :h includeexpr: 'includeexpr' '...
muru's user avatar
  • 24.9k
7 votes
Accepted

How to list the available options of a plugin?

Vim doesn't provide any way to know all possible plugin options. As a plugin writer I can tell you this is quite complex as there are many different ways to proceed. For instance either we consider ...
Luc Hermitte's user avatar
  • 17.4k
7 votes

How to save and restore the result of the command 'set'?

1. :mkexrc The easiest way is to use :mkexrc command. With this command, we can save all changed options into a file. When you need to restore back all the saved options from the file, just:source it....
MS.Kim's user avatar
  • 281
7 votes
Accepted

What is the proper way to allow the user of a plugin to modify settings?

The simple way is if get(g:, 'myplugin_enable_feature', defaultvalue) do whatever you want endif Now when I need to check a setting in more than one place, I usually prefer to have a dedicated ...
Luc Hermitte's user avatar
  • 17.4k
6 votes
Accepted

Differ between 'softtabstop' and 'expandtab' options in function

No. sts and et options have distinct functions and are not mutually exclusive. With softtabstop and noexpandtab, vim will insert a mixture of tabs and spaces, to make it up to the sts value. How ...
Mass's user avatar
  • 14.1k
5 votes

Is there some way to echo from terminal into new vim buffer

You can do this from directly inside of vim with the :read command, which is abbreviated to :r The 'read' command is intended to allow you to read a file, e.g. :r foo.txt Will insert the contents ...
DJMcMayhem's user avatar
  • 17.6k
5 votes
Accepted

Vim prints options on quit

From your .vimrc: ... set cursorline set " <- HERE syntax on ... This set command must be causing it. Looks like during initialization Vim dumps output to terminal, but you don't ...
xaizek's user avatar
  • 1,788
5 votes
Accepted

how could I use different `.vimrc` with `-u` option

Vim will automatically set nocompatible when loading ~/.vimrc or ~/.vim/vimrc. But it's not set automatically when loading a file with the -u option, or using :source. The solution is to add set ...
Martin Tournoij's user avatar
5 votes
Accepted

How to copy the current value of a `set` option into the clipboard?

Just like this let @+ = &statusline Or like this call setreg("+", getbufvar("%", "&statusline")) Or even like this... if has("nvim") call provider#...
Matt's user avatar
  • 20.7k
5 votes
Accepted

remove from comma-separated option (listchars)?

The answer is at :help :set-=: :se[t] {option}-={value} *:set-=* Subtract the {value} from a number option, or remove the {value} from a string option, if it is ...
D. Ben Knoble's user avatar
  • 26.2k
4 votes
Accepted

When I view local options (i.e. :setlocal) - what do the "odd" prefixes (i.e. '--') mean?

From :h :setlocal: :setl :setlocal :setl[ocal] ... Like ":set" but set only the value local to the current ...
muru's user avatar
  • 24.9k
4 votes
Accepted

cpoptions and parenthesis text objects

This is a bug in vim that was patched in version 7.4.662, update and di( will work as desired.
rampion's user avatar
  • 201
4 votes
Accepted

How do I set an option only if there are multiple windows?

Maybe you could try the following autocmd: augroup cursorline autocmd! autocmd WinEnter * exe winnr('$')>1 ? "set cursorline" : "set nocursorline" augroup END Whenever you enter a window (...
user9433424's user avatar
  • 6,138
4 votes

How to save and restore the result of the command 'set'?

You can access a setting's value using let option_val = &option in a script. What I've seen done is using a dict to store the options that you want to change. You iterate over the dict to store ...
Tommy A's user avatar
  • 6,770
4 votes

Change the looks of the character limit ruler

Unfortunately not possible in vim; painting color on anything less than a full cell is not possible for (most?) terminals. There are several other options available, such as changing changing ...
Wolfie's user avatar
  • 667
4 votes

set formatprg dynamically based on textwidth?

That's when the OptionSet event comes in handy, but it doesn't work when it's triggered on startup so you need the VimEnter event too. If your workflow includes several files opened in different ...
Jair López's user avatar
  • 1,854
4 votes
Accepted

Help understanding options hidden and nostartofline

Perhaps examples will help you understand the features: 'hidden' Start a new instance of Vim in the terminal with the command vim -Nu NONE. This will start Vim with default configuration, and thus '...
Rich's user avatar
  • 32k
4 votes

What is the proper way to allow the user of a plugin to modify settings?

Usually it suffices to use get() function. Like that if get(g:, 'myplugin_enable_feature') " do something endif If the feature should be enabled by default you can change it to get(g:, '...
Matt's user avatar
  • 20.7k

Only top scored, non community-wiki answers of a minimum length are eligible