Questions tagged [vimrc]
Vim reads initialization commands from a file called vimrc on startup. This can be used to set settings, define functions, execute autocommands, and more.
1,372
questions
92
votes
1answer
58k views
What is the purpose of swap files?
When I edit files, Vim tends to create files named .filename.swp, which I find annoying. From vim -h, I see that the -n option suppresses the creation of swap files.
Is there a vimrc directive that ...
88
votes
7answers
22k views
How do I debug my vimrc file?
I have a problem in Vim, and I think it may be in my vimrc file (or have been told it could be my vimrc file).
How do I verify this? If it is my vimrc file, how do I know where exactly the problem ...
61
votes
7answers
34k views
Fastest way to switch to a buffer in vim?
One way to select a buffer in vim could be to browse the buffers list, using standard commands as :ls, or with some external plugin / vimscript code to browse a list in a window.
Let's say I want to ...
52
votes
3answers
6k views
How do I reload my vimrc without leaving Vim?
When I do a change in my .vimrc, I usually exit Vim and open it again. Is there an easier way to reload the new .vimrc changes?
47
votes
5answers
42k views
How to share config between vim and Neovim
I started using neovim and moved my .vimrc to .config/nvim/init.vim and other stuff is located in .local/share/nvim.
What is the best way to share configs or even plugins between vim and Neovim?
...
40
votes
1answer
22k views
Why do I need both a vimrc and a gvimrc?
There seems to be two ways to store preferences specific to gvim:
Keep an .vimrc file for vim and a .gvimrc file for gvim specific additions.
Keep all settings in .vimrc and wrap gvim specific ...
35
votes
2answers
9k views
What's the difference between let and set?
I don't know much of the theory behind Vim. It looks as if we set some variables, and let other variables. What's the difference, and when is one required over the other?
Also, the solarized vim ...
34
votes
6answers
3k views
Applying settings to a directory tree only
At my work we use a standard ts of 2; my personal preference is 4, which is what I use for my hobby projects, and this other project we inherited has the convention of ts=8.
There are also some other ...
29
votes
4answers
8k views
Is it possible and useful to split vimrc?
As per the title, is it possible to split the vimrc file in several sub-files? Keep separate files for groups of settings that concern one thing? This thing might be anything, any kind of user-...
26
votes
4answers
26k views
What is `softtabstop` used for?
I've been aware of these tab related settings in Vim:
ts
sw
expandtab
smarttab
sts
My normal setting is set ts=4 sw=4 expandtab smarttab.
But according to sts documentation, if expandtab is not ...
25
votes
2answers
7k views
How can I redefine plugin key mappings?
I have installed a plugin that doesn't provide a mechanism to disable the key mappings it defines. I want to redefine one of the mappings (<leader>cc) defined by the plugin for my own pursope, I'...
24
votes
8answers
6k views
Is there a best practice to fold a vimrc file
I recently realized that my vimrc is now more than 400 lines long (which IMO is too much I'll try to reduce that) and to make it easier to navigate, read and edit it I decided to investigate the ...
24
votes
1answer
51k views
How do I configure the Vim airline plugin to look like its own project screenshot?
I am trying to get the vim-airline up and running.
I have required it via vundle in my ~./vimrc:
Plugin 'bling/vim-airline'
I have installed it and expected my Vim to look like the screenshot on ...
23
votes
5answers
1k views
GitHub for .vimrc and plugins
I know many people store their .vimrc on GitHub to make it easier to get right to work on new machines, and that makes complete sense to me. Including plugins, however, is problematic, because the ...
21
votes
5answers
9k views
Settings and plugins when root (`sudo vim`)?
It's really frustrating when I need to edit a file as root and use sudo vim somefile.conf and I can't use any of my keybindings and settings and plugins.
Is there a way to get all my customizations ...
20
votes
2answers
1k views
The simplest way to start Vim in private mode
I want to be able to easily start Vim in a private mode. Let's define a private mode as one that utilizes this set of commands:
set history=0
set nobackup
set nomodeline
set noshelltemp
set ...
19
votes
2answers
2k views
What is the difference between set and :set (commands with or without a leading colon)?
I was looking at Tim Pope's vim-sensible plugin and I noticed this in the README...
See the source for the authoritative list of features. (Don't worry, it's mostly :set calls.)
When I looked at ...
19
votes
4answers
3k views
How can I suppress the “reading from STDIN” message from within Vim?
When using Vim to read from stdin, it prints a informative message:
$ echo foo | vim -
Vim: Reading from stdin...
$
This is just an example. The actual use doesn't allow shell constructs. vim <(...
19
votes
1answer
3k views
How to define a custom popup / menu in vimrc
Assigning every useful function to a key works well for frequently used tools, but there are some operations I use so rarely, that I would prefer to assign them to some popup menu defined in my vimrc.
...
18
votes
5answers
2k views
After copying a visual selection to keyboard, return to original location
My cursor is in the middle of a paragraph when I decide suddenly I need to copy that paragraph:
So I type vip to select the paragraph visually:
Now I hit cmd+C to copy to clipboard (this may vary on ...
18
votes
3answers
13k views
How to make vim automatically add a newline to the end of a file?
Vim normally writes <EOL> for the last line only when there was one in the original file.
How to make vim to write a new line at the end of a file all the time (when the file is not binary and ...
17
votes
2answers
839 views
How do I make Vim use a default filename when not given any filenames?
I rarely, if ever, just open vim without filenames. Often enough, I want to test something out, usually a quick throwaway script, and I usually name them test.sh (or some variant thereof, like test.py)...
16
votes
3answers
25k views
Remap Esc key in Vim
Is it possible to remap the Esc key to another key in Vim? When I'm using Vim in a full screen VMware vSphere web client console window and I press the Esc key to exit edit mode, it also takes me out ...
15
votes
4answers
1k views
Why does this <Esc> normal mode mapping affect startup?
I'm experiencing a weird problem with a normal mode mapping of Esc.
If you create the file escmapvimrc with the contents:
set nocompatible
set showcmd " Doesn't affect the problem: just makes it ...
15
votes
3answers
2k views
How to label tmux tabs with the name of the file edited in vim?
Whenever I open a tmux session in terminal, all of the tabs containing vim sessions are labelled vim.
My question is: How to configure it to label tmux tabs with the name of the edited file or ...
15
votes
2answers
9k views
How do I insert a comment into my vimrc fie?
What is the syntax for inserting a comment or comments into the vimrc file?
Having trouble finding this on vim documentation online.
14
votes
2answers
2k views
How do you find where a variable was last assigned?
I am trying to set g:netrw_list_hide and it doesn't seem to work. No matter what I set it to in my .vimrc it always has the value ,^\.\.\=/\=$. Only if I source my vimrc file again, then it holds the ...
14
votes
4answers
4k views
Includes in vimrc?
Is it possible to include external files to be sourced in the vimrc file?
Is it as simple a matter as just adding source somefile?
14
votes
1answer
17k views
How can I change the colour of the line highlighted with the 'cursorline' option?
I can highlight the current line like this :set cursorline, which underlines the current line.
However I would like to highlight the entire line in a lighter color. How can I achieve this look?
14
votes
1answer
6k views
How to enable spell check for certain file types?
I flip between Ruby and Markdown files a lot. Is there a way that I can have set spell automatically set when I open a *.md file, but not when I open a *.rb one?
13
votes
4answers
1k views
Same vimrc, customized per machine [duplicate]
I use the same versioned .vimrc on several machines.
Is there a way of customise that file to enable/disable a plugin based on machine name or something like that?
As example, I have something like ...
13
votes
3answers
2k views
What's the difference between the '\zs' and '\@<=' atoms in Vim regex?
This is what I get from the documentation: \zs "starts the highlighted part" after matching the preceding regex, and \@<= "starts the highlighted part" after matching the preceding atom. But I don'...
13
votes
9answers
28k views
Colorscheme's background not correct in terminal
I imported the solarized colorscheme and palette. My terminal has the correct colors and background, gvim has the correct colors and background, but vim has an incorrectly colored background. The text ...
13
votes
1answer
894 views
Why is it called a “vimrc” file?
Where did the name vimrc come from? Is the rc part an acronym? Are there historical reasons for picking this name? Where did the practice of using rc for configuration files first come from?
For what ...
13
votes
1answer
9k views
How can I add additional syntax highlighting rules in my local vimrc?
I installed gvim on both Fedora and Win7. I found that both vim and gvim on Fedora didn't highlight the function name in c code while gvim on win7 did highlight it.
I found that on win7, vim73/...
13
votes
0answers
228 views
Using <C-,> causes “<80>ü^D,” to flash in the showcmd area?
I've mapped <C-,> as well as some other special keys (<C-Enter>, <C-S-Space>, ...) in my vimrc like,
:set <F13>=^[[44;5u
:map <F13> <C-,>
:map! <F13> <C-...
12
votes
3answers
382 views
UI to personalize a vimrc without writing one from scratch
Vim is so infinitely configurable. However, devising a vimrc is a daunting task for novices and intermediate users. Basically, you're expected to develop one from a blank slate by reading the ...
12
votes
1answer
469 views
How to use sensitive data in .vimrc?
I want to have my .vimrc synced through github so it has to be public file, but at the same time i have to put some sensitive data (for example db passwords/hosts for dbext.vim) in it, without giving ...
12
votes
2answers
5k views
How to deal with string containing spaces in Vim script?
I have the following command in my vimrc:
execute "set path+=".getcwd()."/**"
It works well if current working directory is like /home/tamlok/my_work/. However, if the directory contains spaces, ...
12
votes
3answers
8k views
How can I make highlighting commands in .vimrc take effect immediately with Vim 7.4?
I have several highlight commands in my .vimrc file. In VimĀ 7.3, these took effect immediately after Vim had started. After updating to VimĀ 7.4, this is not the case anymore. Vim uses its default ...
12
votes
1answer
3k views
How can I run an autocmd when starting Vim with no file, a non-existing file, or a blank file (but not when starting with an existing file)?
I would like to run an autocmd in the following scenarios when I start Vim:
With no filename specified.
When the file is new.
When the file exists but is completely blank.
In all of the above three ...
12
votes
1answer
240 views
Prevent Vim from recording events for certain filetypes
To add to this stackoverflow question, what should one put in their .vimrc to ensure 'private editing' of certain file extensions (e.g. .gpg files).
Without compromising the effectiveness of the ...
12
votes
1answer
1k views
How to record my keyboard input to do statistics on it?
I would like to find out what are the most common patterns i'm using during coding. So I'm looking for a way to record all my keyboard input while i'm in vim, preferably with timestamps. Then I could ...
12
votes
2answers
8k views
Display CR and LF rather than “EOL” in ':set list'
Rather than choosing one character to be displayed as the EOL character, I'd like one to display for both CR and LF separately and regardless of if the file is unix or dos. Is this possible?
11
votes
2answers
2k views
How do I differentiate between vim and vimdiff from within vimrc?
I have a function in vim which will open all buffers as tabs. However after I add this function, vimdiff too opens the files to be compared as different tabs and hence doesn't show the differences. Is ...
11
votes
2answers
9k views
How do I run a specific vim command when opening a file with a given extension?
I want all of my files ending in .tex to have line length 80. So whenever I open a .tex file in vim I type :set tw=79. What would I put in my .vimrc to automate this?
What if I wanted it to work with ...
11
votes
1answer
5k views
What is command! -bang -nargs=* in a vimrc file?
I read a document about vim and the author suggest a line of code that should be put in .vimrc but I totally have no idea what it is.
command! -bang -nargs=* Find call fzf#vim#grep('rg --column --...
11
votes
1answer
2k views
How should the option 'switchbuf' work?
I recently discovered the option switchbuf and tried to use it but I can't say if I don't understand how it should work or if it actually doesn't work on my Vim.
About the different possible values, ...
11
votes
1answer
954 views
Is it possible to create custom “set” commands in my rc file and call them from a modeline?
I recently asked a question in which I learned that it is not possible to pass anything except parameters to :set in vim modelines. I understand the security concerns, but I'm wondering if there isn't ...
11
votes
2answers
4k views
How can I modify Vim to work with a different keyboard layout?
I type with a non-QWERTY keyboard layout. Many of the keys Vim uses are now on the home row, but some key bindings just don't work, the most obvious one being the hjkl keys.
How and where can I ...