All Questions

Filter by
Sorted by
Tagged with
42
votes
3answers
66k views

How to get intelligent C++ auto-completion

Some editors (such as visual studio on windows) do C++ autocompletion which understand C++. For example, given: #include <vector> int main(void) { std::vector<int> v; v.i In visual ...
42
votes
1answer
22k views

Use conditional operators AND or OR in an IF statement?

This is probably an incredibly simple question, but I did not find any answer so far (I must lack the right sources, and I don't know where to search in vim's help). I have a condition and I would ...
41
votes
5answers
14k views

How to replace only within visual selection?

How does one get vim to replace a character within the visual selection only and not elsewhere on the line? Example: Line: int arr[] = { 00 01 02 03 04 05 05 /* ... lots more like this*/}; Visual ...
41
votes
4answers
13k 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 ...
41
votes
4answers
14k views

How can I get Vim to ignore all user configuration, as if it were freshly installed?

In order to ensure that behaviour is not affected by my personal config, I want to start Vim in a way that ignores all my user-installed config files, as if Vim had just been freshly installed for the ...
41
votes
1answer
23k 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 ...
40
votes
5answers
5k views

How can I generate a list of sequential numbers, one per line?

Starting from a blank slate, how can I obtain a document that contains 1 2 3 4 5 6 7 8 9 10 … 100 To be clear, I don't want these numbers displayed in the margin; I want them inserted into the ...
40
votes
5answers
31k views

How can I insert text at the end of a group of lines?

Let's say I had a block of text... Lorem ipsum Lorem ipsum dolor Lorem ipsum dolor sit Lorem ipsum dolor sit amet ...and I wanted to insert a . at the end of each line. What would the best approach ...
40
votes
9answers
16k views

Is it possible to make Vim auto-save files?

Some word processors and text editors auto-save the files we're editing from time to time, which is very convenient for surviving from nasty crashes, etc. Is there a way to make Vim auto-save our ...
40
votes
5answers
15k views

Dump the output of internal vim command into buffer

How do I dump an internal vim command (not shell command) into a new buffer? For example, I want to dump a listing of all plugins into :enew from :scriptnames so that I can search it.
40
votes
2answers
18k views

Can I open a new vim split from an existing buffer?

I know it's possible to open a new file in a split, with :split or :vsplit, but is it possible to open a new split with an existing buffer, potentially leveraging autocomplete?
40
votes
3answers
17k views

How do I get the name and extension of the current file?

Is there a way to get the name and extension of a file using vimscript? If so I would like the name and extension separately.
40
votes
5answers
4k views

Terminal borked after invoking Vim with xargs

I've sometimes tried invoking Vim using xargs, like this: find . -name '*.java' | xargs vim … which kind of works: As Vim launches, I see the following warning flash briefly: Vim: Warning: Input ...
39
votes
14answers
6k views

How can I inspire others to use vi/Vim? [closed]

I was extremely impressed with the power of vi from the first half hour that I used it. I then found out that in some work environments, there are many people (technicians, and even system ...
39
votes
5answers
31k views

Navigation in insert mode

I finally decided to ditch the arrow keys for navigation in favor of hjkl. I used the Vim hardmode plugin to disable the arrow keys. I got used to navigation pretty fast, but it turns out that ...
39
votes
4answers
8k views

How do you “chomp” a string in Vim?

Suppose you run the following piece of vimscript: let @z = system("date") This will put a string version of the current date into the z register, but the string will end with a newline that I don’t ...
38
votes
11answers
5k 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 ...
38
votes
5answers
23k views

How to disable arrow keys in vim?

I want to teach myself to prefer hjkl more over the arrow keys in order to stay on the home row. (I am very aware that one should not use hjkl as the main navigation keys as there are more powerful ...
38
votes
6answers
61k views

How do I open and close NERDTree (toggle NERDTree view) using a single keystroke?

Sometimes in my workflow, I might want to open or search for a file on the go. I'd like to map a single key (say F6) to open and close NERDTree (i.e., I want to toggle the NERDTree view). Also, I'd ...
38
votes
1answer
21k views

Call a Vim function silently

I wrote a little Vim function that moves the cursor to the first character of the current line. If the cursor was already on the first character, then the cursor is moved to the first column instead. ...
38
votes
2answers
5k views

What is <Leader>?

I see <Leader> quite often in other people's vimrc files. Like this one. What is it? What does it do?
38
votes
3answers
2k views

How to disable horizontal scrolling?

I have some concealed characters in the buffer and horizontal scrolling kills the alignment big time. Is there any way how to disable it? I could not find any relevant options. Edit: Demo added. You ...
37
votes
4answers
21k views

How can I work with splits in Vim without Ctrl-W?

My terminal doesn't allow me to type Ctrl+W, because that's a shortcut for closing a terminal tab. I like working with splits, but I can't find any way to do so without using C-W. This forced me to ...
37
votes
4answers
17k views

How can I easily create and maintain tables?

Here is (part of) a table I use in some documentation: +---------------+------------------------+---------------------------------------+ | TASK NAME | WHEN | DESCRIPTION ...
37
votes
5answers
7k views

Renumbering buffer list

After I've been working on a project for a while, I start to see large gaps between consecutive buffer numbers. This is because the buffers in between them were wiped out for various reasons. ...
37
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 ...
36
votes
2answers
11k 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 ...
36
votes
3answers
13k views

Can I use a non-monospaced font in either Vim or gVim?

Is there any way to use a non-monospace font in either vim or gvim? I tried changing the font for gVim with: :set guifont=Dejavu\ Serif\ 12 But this gives me some rather ugly results: I get the ...
36
votes
2answers
5k views

Why is Y a synonym for yy instead of y$?

Is there a specific historical reason for this? Background — (you can skip this part if you already understand the question.) As intermediate/advanced vi users will know, y is the "yank" command—it ...
35
votes
1answer
11k views

Setting a vim option from the command line?

How does one set a vim option when launching from bash or another shell?
35
votes
2answers
3k 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,...
34
votes
10answers
81k views

How to enable +python feature in vim

I want to install a vim plugin, this plugin needs a +python feature, so when I open vim and type :version it displays -python. How can I make it enable?. Thanks.
34
votes
3answers
67k views

How do I stop recording while in command line?

When I am recording a macro with q and I am done, I can type: q to stop recording if I am in normal or visual mode. <c-o>q to stop recording if I am in insert mode. .. How do I stop recording ...
34
votes
1answer
8k views

How can I move the cursor to the top or bottom of the screen?

I know that gg and G can move the cursor to the top and bottom of the file. But is there a way to jump to the top or bottom of the visible window?
34
votes
5answers
6k views

How to undo/revert making current window the only window (":only" / "<C-W> o")?

Consider a case with multiple splits in a window. vim allows quickly "maximizing" the current split to take up the whole window via <C-W> o. Is there a way get vim to "remember&...
34
votes
4answers
7k 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 ...
33
votes
5answers
2k views

Is there a text object for the entire buffer?

I often find myself typing commands like gg"+yG or ggdG and would like a more efficient way to do this without having to move the cursor twice. Is there any command that I can use e.g. y[movement] to ...
33
votes
5answers
10k views

What is the easiest way to insert Unicode characters into a document?

When writing documents occasionally I want to insert Unicode characters into the text. Sometimes I know the character code and sometimes I look it up on the web. Currently I go to insert mode and ...
33
votes
3answers
17k views

In Vimdiff, how do I switch the left and right panes?

When I do vimdiff file2 file1, file2 naturally goes on the left and file1 on the right. Sometimes I find that I put them the wrong way round, so I'd like to be able to switch them round without ...
33
votes
2answers
33k views

How to block replace code in visual mode?

I have a list of items where I want to replace the first two characters: a) item 1 b) item 2 c) item 3 What is the fastest way to make this: * item 1 * item 2 * item 3 I have an approach with ...
33
votes
2answers
12k views

Extract the result of a shell command to a variable in a .vimrc file?

In my .vimrc file, I would like to store in a variable the result of an external command, in my case: $ echo $LANG So that my .vimrc file would have : let language = output(!echo $LANG) if language ==...
33
votes
5answers
2k 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 ...
33
votes
3answers
15k views

How do I tell vim that some file extensions are synonymous?

I edit C++ code in .cpp files, while template code goes into .tcc files. When I open such a file, no syntax highlighting is available. I tried set syntax=cpp in a a tpp.vim file in ~/.vim/ftplugin/, ...
33
votes
8answers
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 ...
32
votes
10answers
27k views

How to automatically turn off "hlsearch" after I'm done searching?

I love the "hlsearch" setting, but after I'm done searching, I find it obnoxious. Especially if I search for something that has a lot of matches. I know that I can turn this off with :set nohlsearch ...
32
votes
8answers
13k views

How do I prevent vim from hiding symbols in markdown and json?

This drives me crazy, I do :set ft=text To see something, otherwise all the links disappear in markdown and quotes in JSON. How do disable this once and for all?
32
votes
5answers
25k views

Biggest differences between Vim and vi

Today, I decided to try vi instead of Vim; I wanted to see how different it is. I didn't notice much differences at all. The biggest thing I noticed was how vi didn't say -- INSERT -- when I went ...
32
votes
1answer
8k views

What are the new "popup windows" in Vim 8.2?

The latest version of Vim, 8.2, has a new feature called "popups" or "popup windows". They sound interesting but I'm not quite sure what they're good for. Can you enlighten me...preferably with some ...
32
votes
4answers
10k 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-...
32
votes
4answers
31k 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 ...

15 30 50 per page