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,392
questions
11
votes
1answer
2k views
Why does the order of :set bg=dark and :set bg=light matter?
While trying to match up my terminal's colour palette and GVim's I noticed this:
When I open GVim and Vim, I see:
(That's the same file, my vimrc.)
If I do :set t_Co=256, nothing happens in GVim (...
11
votes
2answers
322 views
Is it possible to use vim's clientserver functionality to keep settings synchronized?
I usually have multiple instances of vim running on the same machine. When I make a change to my vimrc I can just :source ~/.vimrc (with an easy mapping or an autocmd). But in order to have all ...
10
votes
5answers
3k views
set formatoptions in vimrc is being ignored
Vim automatically continues a comment when I press Enter in Insert mode, which I find helpful.
However, I do not want the comment continued after pressing 'o' from normal mode to insert a new line ...
10
votes
2answers
6k views
vundle “filetype plugin indent on” messes with tabwidth
I installed vundle yesterday and since I did, the tabwidth I configured in my vimrc is ignored and set back to 4 instead of 2.
I found out that the following line after the vundle paragraph is ...
10
votes
1answer
2k views
Echo message on startup without prompting
I'd like to echo a custom message upon startup, based on whether or not certain startup functions were successful. I tried this in my .vimrc
echo 'test'
"All my settings
...
I'd like vim to echo a ...
10
votes
1answer
5k views
Why is set exrc dangerous?
I've seen set exrc mentioned in various places for using per-directory .vimrc files, but every time it's been mentioned it's been with strong admonition not to actually use it because it's dangerous. ...
10
votes
1answer
2k views
How can I highlight matching “%” names (e.g. if/end, for/end) defined by matchit.vim on selection?
Currently my Vim highlights matching parentheses, brackets, quotes, etc. with Cyan background and white foreground -- the cursor can be moved between these with %. Thanks to my matchit.vim, I can also ...
10
votes
2answers
783 views
Is it possible to remove an entry from the undo history?
I have these lines in my .vimrc to help with indentation:
autocmd BufReadPost * set noexpandtab | retab! 4
autocmd BufWritePre * set expandtab | retab! 4
autocmd BufWritePost * set noexpandtab | ...
10
votes
1answer
7k views
Why doesn't YouCompleteMe complete function paramters?
I'd like to use YouCompleteMe with C++ semantic completion, but after hours of trying, I can't find why it doesn't work as expected.
Everything seems to be working but I can't complete function ...
9
votes
6answers
6k views
How can I copy/paste new text without auto-indentation at every new line?
How I paste now:
Right-click/Copy or simply highlight.
Right-click/Paste or Middle Click or CTRL+SHFT+V
Indents appear at increasing intervals: 0, 2, 4, 6, +
Question at hand:
From prior research, ...
9
votes
5answers
9k views
How can put .vimrc and viminfo into .vim directory?
All the vim related files installed on /usr/share/vim/vim74.
cd /home/debian8/
ls .vim*
.viminfo .vimrc
To create .vim directory to install some plugin for customization.
mkdir .vim
mkdir ....
9
votes
2answers
3k views
Why won't vim source my .vimrc file
Today, I found my .vimrc didn't take effect. It was ok just hours ago.
When I launched vim with $vim --plugin, :scriptnames echoed nothing: .vimrc file was not sourced. (Note: /etc/vimrc was removed ...
9
votes
2answers
3k views
How to write condition with regular expression?
I'm aware of the following comparison:
if @% == "/tmp/crontab.zi5NeVPGRc"
set nobackup
set nowritebackup
set noundofile
set noswapfile
endif
But how can I use regular expression? For example ...
9
votes
4answers
12k views
Environment Variable for Personal Runtime Path? (~/.vim on *nix, ~/vimfiles on win32)
I'm trying to move my .viminfo file into my .vim/ folder for cleaner syncing across multiple machines. (I have my .vim stored on Dropbox, and then create symlinks to it from my home directory.)
So ...
9
votes
1answer
1k views
Current line number aligned to the left with number and relativenumber
I use relative line numbers along with an absolute line number for the current line:
set number
set relativenumber
The absolute current line number is always aligned to the left, and the help pages (...
9
votes
1answer
6k views
What is the difference of using `au BufNewFile,BufRead *.py` and `au Filetype python` in .vimrc?
As I am setting .vimrc, I found these two code blocks have the same functionality.
au Filetype python set
\ tabstop=4
\ softtabstop=4
\ shiftwidth=4
\ textwidth=79
and
au ...
9
votes
1answer
524 views
How can I edit my Vim configuration whilst working in Vim?
I am new to Vim and I want to be able to edit scripts with my keyboard bindings and other Vim settings while still working in Vim.
For instance I would like all most of my set xx commands to be in ...
9
votes
3answers
3k views
How do I add skeleton text to new vim files?
I use Vim for writing C++, and I have quite a few #include<> statements, comments, etc. that I must include in each new file I create. I've added
autocmd BufNewFile *.cpp r C:\(full file path ...
9
votes
1answer
7k views
I can't switch to | cursor in insert mode
I want to change cursors to a | character in insert mode, and then back to a block in normal mode. I am using urxvt as my terminal, and neovim.
To switch cursors in my terminal, I run the following ...
9
votes
1answer
12k views
Where do I put my “vimrc” file for Neovim on Windows?
:help nvim-from-vim says:
create ~/.config/nvim/init.vim with these contents:
set runtimepath+=~/.vim,~/.vim/after
set packpath+=~/.vim
source ~/.vimrc
and:
If your system sets $...
9
votes
2answers
1k views
How do I prevent Vim from unindenting empty lines?
Vim keeps unindenting the lines I want to keep indented if I don't write anything on them... I'll give an example, where the | is the caret.
Caret is indented and I press enter
if expression:
...
9
votes
1answer
4k views
Override cursorline background color by syntax highlighting
I've set the background color of the current line to light gray like this:
hi CursorLine cterm=NONE ctermbg=253
(Note that my color scheme is black-on-white.)
However, this way any background ...
9
votes
1answer
162 views
Use backspace to modify the current command in normal mode?
Sometimes when entering a command in normal mode you may make a typo, for example if I intend to type 10dk, I might accidentally start typing 19d.
Since the command has not been completed/committed ...
8
votes
3answers
648 views
Convert a search to a command in Vim
Often I will do a search to find things in Vim, such as:
/-some-regex-here
And after seeing what if grabs and iterating through a few of the results, I want to do a find-replace. Is there a way to ...
8
votes
7answers
2k views
How to quickly type a C expression where the assigned-to variable is repeated?
I sometimes want to type an expression like this:
table[row][col] = std::max(table[row][col], other_table[row+1][col+1])
(this is C++ code. Unfortunately there's no way in C++ to eliminate the ...
8
votes
7answers
7k views
How to refer to “~/vimfiles” on Windows and “~/.vim” on Linux?
Consider an answer to How do I install a plugin in Vim/vi?:
call plug#begin('~/.vim/plugged')
" For MS Windows, this is probably better:
"call plug#begin('~/vimfiles/plugged')
And more generally, ...
8
votes
2answers
16k views
How do I change the Airline theme?
I'm using airline with its default theme (relying from my theme gruvbox).
I use :AirlineTheme base16 while I have already opened my vim to change my airline theme to base16.
But I want to change the ...
8
votes
2answers
741 views
How safe is it to use an unknown `_vimrc` or `vimscript` file?
I do not know if this question should be asked here or not. In almost every language, malware exists. Is the same also applicable for vimscript?
Suppose vim is running with high system privileges. Is ...
8
votes
2answers
2k views
How to jump to buffer from ls?
Is there any way to jump to a buffer by entering buffer number right from :ls?
I mean, why this command expect me to Press ENTER or type command to continue, if pressing for example 2, wouldn't do ...
8
votes
1answer
306 views
How to color comments after a defined column
I once was given these materials to enable this helper for vim to show kind of a vertical line in order to help enforce PEP8 rules on line length limit at column 80:
" Long lines highlighting.
...
8
votes
1answer
288 views
How do I configure vim to show a character when a line is too long to be displayed?
I want to be notified when a line is too long to fit in the window.
Right now I have this in ~/.vimrc:
set wrap
let &showbreak = ' +++ '
I'd like to change that to:
set nowrap
let &...
8
votes
2answers
6k views
How to make vimrc settings applicable for a directory tree only [duplicate]
Is there a way to make certain vimrc configuration valid only for files under a defined directory tree? Or alternatively, is there a way to have a .vimrc file in a directory, and make its setting ...
8
votes
3answers
493 views
Is it possible to get the rule (cinoptions) that govern the indentation for a specific line in vim
I have the following code:
namespace
{
template<typename T>
struct One // This is the odd line
{
// impl details
}
template<typename T>
struct Two
{
// impl details
}
}...
8
votes
1answer
1k views
What is the relevance of has(“autocmd”) today?
Context
I have been using Vim for more than 6 years and have compiled it from source a couple of times during that period. Over the years my vimrc did grow. Now, I am trying to clean my vimrc and I ...
8
votes
2answers
1k views
How do I make Vim wait indefinitely after leader key has been pressed?
I'm trying to make Vim wait after the leader key indefinitely without messing with the timeoutlen of other keys.
Currently I have this lines in my vimrc:
let mapleader=" "
set timeoutlen=2000 ...
8
votes
2answers
805 views
What is fileencoding of .vimrc?
I've upgraded vim and now it's unhappy about some UTF-8 values in my .vimrc.
This lead me to the question -- when vim reads .vimrc, what encoding does it assume the file has? I.e. what's fileencoding ...
8
votes
1answer
1k views
Visual scrolling/visual <C-e> and <C-y> across wrapped lines?
This has been asked on stackoverflow before, but it seems it still has no solution. Perhaps that has changed with Vim 8.0.
I'd like to be able to scroll (i.e. scroll-wheel, or <C-y>/<C-e> ...
8
votes
2answers
2k views
Why is key mapping nnoremap <S-C-k> :w<CR> not working?
I'm trying to make it so I can write a buffer to disk with one keystroke.
(Side note: ideally, I'd like this to work in all modes, but for the moment as a start I'm just trying to get it to work in ...
8
votes
1answer
2k views
How to change the value of timeout for one key command?
What I want
To temporarily change the timeout value for certain key commands
Where I've looked
From :help 'timeout' I have :
The timeout only happens when the 'timeout' and 'ttimeout' options
tell so. ...
7
votes
2answers
2k views
Are there any comprehensive docs for vimrc?
I'm trying to find complete documentation for the possible contents of .vimrc.
Here's what I've tried:
Google search. Plenty of examples, no docs.
Official docs
man vim
:help vimrc
Searching this ...
7
votes
2answers
2k views
Advice to add `set nocompatible` as first line of .vimrc
I recall (perhaps in the early 2000's) having set nocompatible as the first line of my vimrc and most Vim guides and tutorials recommending that practice.
Some examples I could easily find online:
...
7
votes
2answers
1k views
How to jump back to the cursor position before I entered insert mode?
I'm trying to set up normal mode mappings to make it easy to add white space around the cursor:
<C-h> will add one space to the right of the cursor;
<C-j> will add a newline below;
<C-...
7
votes
2answers
2k views
Is the ~/.vim directory used for anything other than plugins?
What is the ~/.vim file used for, if anything, other than plugins? Is it part of Vim, or was it "invented" by plugin managers like Vundle?
7
votes
2answers
688 views
How can I increase floating number with ctrl-a without deleting zeros?
When I'm trying to increase numbers with CtrlA it removes the leading and the trailing zeros.
For example:
1.009500
1.09500
1.0009500
Results after pressing CtrlA:
1.009500 -> 1.9501
1.09500 ...
7
votes
2answers
169 views
a highlight command resets previously declared highlights
I'm trying to tune the highlighting in my vim and I'm trying to set some syntax groups via the match command and highlight them in my vimrc file, because those groups are generic and do not belong to ...
7
votes
1answer
727 views
How to break a long mapping line into several short lines in vimrc mapping
I have a very long vimrc mapping to deal with for example
nnoremap <space>e :exe "!tmux send-keys -t.- 'cd $TEST' Enter"<Cr> :exe "!tmux send-keys -t.- 'source $TEST_NT/bin/activate' ...
7
votes
1answer
803 views
How to have endless vim history?
According to h: help:
Use the 'history' option to set the number of lines that are remembered
(default: 20)
I know I can set the number of lines higher, yet is there an "endless" option that ...
7
votes
1answer
12k views
How to enter tilde (~), back tick (`) and special chars with a non-US keyboard?
I usually use Vim with an Italian keyboard (I'm from Italy),
(mainly in an Ubuntu Linux Virtualbox guest from a Windows host).
I have problems when I have to enter some frequently used characters (...
7
votes
3answers
640 views
How to make horizontal scrolling easier when the cursor is not ideally located?
For easy horizontal scrolling in long lines, I use these mappings that work well for me:
map <m-[> 20zh
map <m-]> 20zl
Something that has always annoyed me is when the following use case ...
7
votes
2answers
3k views
key mapping best practices
I found that I frequently needed a command in INSERT mode to open a line above the cursor (what O does in NORMAL mode)
I put this in my .vimrc
inoremap ao <esc>O
It works well. I chose the ...