All Questions
1,619
questions
110
votes
8
answers
34k
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 ...
111
votes
1
answer
30k
views
How to debug a mapping?
I see a lot of questions on here where a user has a mapping which doesn't work
and most of the time the reasons are pretty similar.
I suggest to make this question a reference for this kind of ...
507
votes
13
answers
663k
views
How can I copy text to the system clipboard from Vim?
Is there a way to copy a block of text to the system clipboard, so I can paste it in another program?
134
votes
3
answers
16k
views
How do I navigate to topics in Vim's documentation?
In Vim's built-in help system, how do I…
search for topics that I want help on?
follow hyperlinks?
browse around for related material?
12
votes
1
answer
3k
views
How do I use a variable or return value in option, command, or mapping?
I have a variable foo with let foo='value', and a function F like
function F()
return 'value'
endfunction
and I want to use them
in an option: :set option=foo, :set option=F(); or
in a command: :...
312
votes
10
answers
177k
views
What are the differences between the Vim plugin managers?
I have been looking at the different package managers for Vim, and the one I decided to use is vim-plug.
However, I have seen others like pathogen and vundle, and I honestly don't know what the ...
82
votes
8
answers
88k
views
How to map Alt key?
I'm trying to map Alt key in the following way:
:map <A-j> j
:map <A-k> k
but it doesn't work (bell is rang on Alt + j/Alt + k).
What am I missing?
I'm using Terminal on OSX, the same ...
27
votes
1
answer
7k
views
Can I map a Ctrl + upper-case letter separately from Ctrl + lower-case letter?
I am trying to figure out how to navigate windows little quicker, so I would like to map the following:
:nmap <silent> <C-F> :wincmd f<CR>
The problem is this remaps the ^f (lower-...
15
votes
1
answer
5k
views
Mapping Ctrl with equal sign
I am trying to map my Ctrl and plus sign together. This is what I am trying in my vimrc:
nnoremap <C-=> : echo "Hello" <CR>
However it seems like the mapping is not being triggered.
...
49
votes
4
answers
31k
views
What is the difference between the vim snippets plugins?
There is a great number of snippets plugins for vim: ultisnips, snipmate, xptemplate, neosnippet and a lot more.
They all have pros and cons and more or less dependencies. So far I've been using ...
143
votes
7
answers
196k
views
How do I install a plugin in Vim/vi?
How do I install a plugin in Vim?
Does it matter:
Whether I use vi or Vim?
Whether I use gVim?
Which version of Vim I'm using?
What my OS is?
76
votes
3
answers
30k
views
Why should I use augroup?
I understand how auto commands work, and how to use them, but I'm somewhat unsure of what augroup is for. I read in :help augroup
*:aug* *:augroup*
:...
29
votes
4
answers
23k
views
Multiple cursors at desired location
I'm using vim-multiple-cursors plugin.
I would like to put cursors exactly where I want. For example ([x] are the cursor positions):
Lorem ipsum dolor sit amet[1], consectetur adipiscing elit,
sed ...
28
votes
1
answer
4k
views
Disable <Esc> but keep <C-[>
For switching back from Insert mode I'm used to <Esc>. Now I'm looking to retrain myself to <C-[> instead of <Esc>. For that i need to disable <Esc> to help with the ...
77
votes
4
answers
27k
views
How to save window, split, and buffer layout?
I have several tasks I am working on in one repository. I would like to create "workspaces" for working on them.
One "workspace" or "buffer layout" would have all files I need to work on open in the ...
45
votes
4
answers
17k
views
How can I change the default indentation based on filetype?
I'd like to have different indentations based on the type of file I am working on. For example, working on a .c file I'd like my indentation be 4 spaces. In .html files I'd like to (have to) work with ...
28
votes
1
answer
14k
views
How to edit files non-interactively (e.g. in pipeline)?
I would like to edit files passed in pipeline input using vim in non-interactive way or edit files in-place (similar to sed).
Few examples using sed:
$ sed -i'.bak' s/foo/test/g file # Edit file ...
14
votes
1
answer
4k
views
Why do custom highlights in my vimrc get cleared or reset to default?
I would like to highlight (part of) my statusline with %1*, for example:
set statusline=%1*%f%0*
highlight User1 ctermbg=0 ctermfg=10 cterm=bold
However, this always shows up as "empty" (the default ...
41
votes
12
answers
8k
views
How to comment out a set of lines which are selected in visual mode?
How do I comment out multiple in visual mode selected lines? How do I make it language specific?
For example, if the first 4 lines are selected:
def foo(a,b):
for each in (a,b):
print ...
17
votes
5
answers
2k
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 ...
16
votes
5
answers
3k
views
How to run a substitute command on only a certain part of the line
I have the following line in my code:
INCORRECT_EMAIL_MOBILE_COMBINATION("incorrect_email_mobile_combination");
When I try to substitute the underscores with spaces in visual mode (using :'<,'>...
208
votes
6
answers
194k
views
What's the simplest way to strip trailing whitespace from all lines in a file?
It's pretty common when programming or opening text files to encounter files with trailing whitespace at the end of a line. vim has a way to show this by setting the trail option in the listchars ...
152
votes
4
answers
53k
views
What is the Vim8 package feature and how should I use it?
Vim 8 was released today and the release notes mentions a new "package" feature. What is it and how should I use it?
Most importantly, does it replace the good old plugin managers?
12
votes
3
answers
4k
views
Mapping Ctrl+s does not work
I am trying to map Ctrl+s to save my file however it does not work.
My mappings:
map <C-s> :w <CR> :echo "Saved" <CR>
imap <C-s> <Esc> :w <CR> :echo "Saved" <...
6
votes
1
answer
297
views
Mathematical expressions in TeX files are displayed in a human-readable way
When I type some mathematical expressions in Tex files using Vim, e.g. a_{2} = a_{1} + a_{0}, it is displayed in a human readable way like a2 = a1 + a0. (Actually the numbers are of a smaller font, ...
41
votes
2
answers
4k
views
Can I see the history of key presses in normal mode?
I know that Vim keeps history for ex commands, searches, jump locations, changes, and possibly others.
With showcmd set, Vim also shows you what keys you have entered so far for a normal mode command,...
40
votes
6
answers
4k
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 ...
34
votes
5
answers
3k
views
Performing certain operations without clearing register
Frequently, in configuration files I might copy and paste a block of lines, then I want to make small changes to that block. After pasting, I use x to delete characters that I want to remove, then ...
22
votes
1
answer
14k
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/...
9
votes
3
answers
10k
views
Vim doesn't use the correct indentation in Python files
I have encountered something that I have never seen before in Vim. While I was tentatively modifying some of the source code for software I've been planning to work on, I noticed vim was displaying ...
73
votes
6
answers
25k
views
Detect OS in Vimscript
Can I retrieve the current operating system (Windows, Linux, OS X, ..) using pure Vimscript (no Python or Perl)?
I want to enable different settings in my (synchronized) .vimrc for different types of ...
31
votes
4
answers
2k
views
Why can ci" be outside of quoted area and ci( only works inside parentheses?
When using ci" the cursor does not have to reside in the double quoted area.
|String somestring = "some text";
Assuming the pipe is the cursor position, ci" will make it jump to the quoted area.
...
31
votes
4
answers
7k
views
How do I deal with very long lines in text (500+ characters)?
For some text formats, line breaks matter.
For example, I often use Vim to write MediaWiki documents, where you can't just put a linebreak anywhere (unlike Markdown). So I'm forced to write lines ...
27
votes
1
answer
5k
views
How to make movements respect camelCase or snake_case?
It is common to use either camelCase or snake_case to separate multiple words which form an identifier. It would be nice if the "word" movements (b, w, e) would detect those inner-identifier ...
24
votes
3
answers
15k
views
How to use a variable in the expression of a 'normal' command?
How can one use a variable when executing something via normal! in vimscript?
Example:
function! MyFunction(someArg)
normal! (a:someArg)l
endfunction
This should move the cursor someArg steps ...
13
votes
3
answers
1k
views
Scrolling issues when the `wrap` option is set
I find myself dealing with this issue every time the wrap option is active (in my particular case whenever I'm working with markdown files).
What happens is that, while scrolling up and down the ...
86
votes
4
answers
101k
views
How do I fix the status bar symbols in the Airline plugin?
I installed the Airline plugin in order to have a custom status bar, as seen in the figure below:
However, my status bar is presenting the symbols <, >> and <. How do I fix this problem?
74
votes
13
answers
150k
views
How to insert a newline without leaving normal mode
I wonder if I can insert a new line without leaving normal mode. For example, I have two lines:
this is line one
this is line two
And the cursor is on line one. Now I want a new line between line ...
60
votes
3
answers
11k
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?
38
votes
4
answers
9k
views
How can I make Vim autoread a file while it doesn't have focus?
I'm using VIm for all kinds of things (or gVim in this case), including monitoring output written to a file; I use autoread to make Vim reread the file, which it does whenever I switch the keyboard ...
36
votes
8
answers
3k
views
How do I move vertically until reaching a non-whitespace character?
In a very long file with (accurately-) indented code, it may be helpful to move directly to a line of text above or below the cursor which delimits the indenting.
(One way of doing this could be via ...
30
votes
3
answers
10k
views
What is the order of WinEnter, BufEnter, BufRead, Syntax, FileType events?
I've gone through the autocmd.txt help, but the information about this is scattered and not always present (eg. with BufRead).
Could someone who understands this well list the order of these events -...
27
votes
3
answers
10k
views
What does `<Bar>` mean?
In answering a question just now, I mentioned using a normal mode key mapping that can be found at the Vim Tips Wiki. In the middle of explaining the key mapping, I realized that I had no idea what &...
18
votes
1
answer
2k
views
What does it mean to replace slashes (/) by exclamation marks (!) in a substitute command?
I recently saw a substitute command where the author had the / replaced by a ! like this: :s!abc!ABC!g
I tried to find some documentation on this usage but I couldn't find anything relevant. So I ...
17
votes
5
answers
4k
views
How can I open multiple tabs at once?
If I use:
:tabedit file1 file2
I get:
E172: Only one file name allowed
Is there any way to use :tabedit with multiple file names? Or another way to open multiple tabs at once?
11
votes
3
answers
5k
views
Bash not recognizing aliases when run from Vim [duplicate]
In Vim, when I run this command :!bash -c "ll", I get this error message bash: ll: command not found. ll is an alias in my ~/.bashrc file. If I just enter ll from bash it works. I created a ~/....
8
votes
1
answer
2k
views
Mapping control-H in insert mode doesn't work; it always works like backspace
I tried mapping control-H, J, K, and L respectively in insert mode to move around splits.
inoremap <C-h> <ESC><C-W><C-h>i
inoremap <C-l> <ESC><C-W><C-l&...
6
votes
3
answers
3k
views
Strange behavior of <ctrl-j> remapping
I want ctrl-h, ctrl-j, ctrl-k and ctrl-l in insert mode to behave like the arrow keys. I have this (among other things) in my .vimrc:
inoremap <C-j> <Down>
inoremap <C-k> <Up&...
231
votes
6
answers
165k
views
How do I change the current split's width and height?
I am working on split (using ^w+v, ^w+s) buffers, but sometimes I would like to widen a current split or change its height. How can I achieve that?
202
votes
11
answers
275k
views
How do I use Vim as a diff tool?
I use Vim as my primary editor.
I would also like to use vim to diff files and modify the files while doing the diff to fix easy changes (rather than most diff techniques which are a cycle of diff, ...