53
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 ...
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.
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 ...
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(...
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 ...
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 ...
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 ...
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 ...
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....
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 ...
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 ...
6
votes
Accepted
What are the benefits and use cases of relativenumber?
TL;DR
relative numbers are just another tool in the toolbox
they can be effective in terms of locality when a text-object doesn't cut it
(and for the lazy-minded among us)
they pair nicely with ...
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 ...
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 ...
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 ...
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#...
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 ...
5
votes
How do I turn off spell checking?
As with all boolean options, you can :set nospell, or :set spell! to toggle. See :help options for more details.
I’m pretty sure the spell option is either buffer or window local, so I’d be inclined ...
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 ...
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 ...
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 ...
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 ...
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 '...
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:, '...
4
votes
Accepted
what is the purpose of the view folder in the .vim folder?
~/.vim/view is a default value (under *nix) for :h 'viewdir' option, which, in turn, is used by the :h :mkview and :h :loadview commands.
:mkview is a rarely used :mksession-like command which saves ...
4
votes
Is there a 'let' equivalent for setting an option only local to a buffer/window?
Sorry, but I very quickly answered my own question, hadn't read far enough down in the docs! let &l:option='value' will set the local value, with let &g:option='value' explicitly setting the ...
4
votes
Accepted
Is there a 'let' equivalent for setting an option only local to a buffer/window?
Yes.
For a local buffer/window option, you can use:
let &l:option = 'complex value'
And you can also be explicit about a global option, with:
let &g:option = 'complex value'
See :help :...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
options × 182vimrc × 40
vimscript × 18
neovim × 10
command-line × 7
statusline × 7
buffers × 6
vim-windows × 6
variables × 6
key-bindings × 5
indentation × 5
folding × 5
filetype × 4
gvim × 3
autocmd × 3
autocompletion × 3
formatting × 3
line-numbers × 3
startup × 3
tab-characters × 3
string-manipulation × 3
history-of × 3
lua × 3
default-settings × 3
ftplugin × 3