Hot answers tagged

51 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,284
36 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,706
20 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
  • 25.3k
15 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
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
  • 31.3k
9 votes

Is there a trick to set 'ignorecase' locally

You can always prefix your search expression with \c to enforce case insensitivity (and \C for case sensitivity). From :h ignorecase: /\c /\C ...
muru's user avatar
  • 24.7k
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,710
8 votes

Is there a vim command line option to edit last edited file?

For this purpose, I have definde the following alias in my shell: alias lvim="vim -c \"normal '0\"" (l meaning last)
Christian Brabandt's user avatar
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
  • 915
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.7k
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

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
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
6 votes
Accepted

Is there a trick to set 'ignorecase' locally

I guess the usual trick is to set ignorecase and smartcase and depending on what you need, search using only lower case (which means to ignore the case for that particular search) or search using ...
Christian Brabandt's user avatar
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
  • 13.9k
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.4k
5 votes
Accepted

Is there a vim command line option to edit last edited file?

An heavy solution: the sessions Another possible option is to use the sessions mechanism: First your vim version has to be compiled with the +mksession option. (Use :echo has('mksession') to check ...
statox's user avatar
  • 49.3k
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,738
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.4k
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
  • 25.3k
4 votes

Is there a vim command line option to edit last edited file?

The last file should be at the top of the jumplist, which you can visit with CTRL-O. Another way around your bash issue, related to muru's comment, is with the reverse-search-history CTRL-R.
Steve's user avatar
  • 446
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,118
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,710

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