All Questions

Filter by
Sorted by
Tagged with
51 votes
1 answer
16k 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?
thameera's user avatar
  • 17.6k
50 votes
4 answers
32k 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 ...
statox's user avatar
  • 50.2k
50 votes
2 answers
24k 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?
bronzehedwick's user avatar
49 votes
5 answers
23k 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 ...
Bhargav's user avatar
  • 1,103
49 votes
1 answer
31k 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. ...
Jezen Thomas's user avatar
48 votes
3 answers
81k 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 ...
Chris Jefferson's user avatar
48 votes
1 answer
29k 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 ...
Feffe's user avatar
  • 1,771
47 votes
6 answers
23k views

Can I justify text in Vim?

The only reason why I'd ever edit a text file in Pico or Nano, and not in Vim was its "Justify" command ^J. It would reformat a paragraph of text, creating line breaks at word breaks so that the text ...
SF.'s user avatar
  • 2,139
46 votes
8 answers
18k views

Why is using arrow keys in normal mode considered bad practice?

I have read it in many articles (e.g.) that it's a bad practice to use arrow keys in normal mode. Could somebody explain why is it considered a wrong practice, if at all?
Ankit Jain's user avatar
46 votes
4 answers
31k 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 ...
Mateon1's user avatar
  • 563
46 votes
7 answers
18k views

Re-indenting badly indented code

I like the smart-indent feature of Vim, it allows me to create well-indented code blocks. I regularly copy/paste code in to buffers, but that code is often poorly formatted. What would be ideal is ...
rolfl's user avatar
  • 697
45 votes
4 answers
22k views

How can I easily create and maintain tables?

Here is (part of) a table I use in some documentation: +---------------+------------------------+---------------------------------------+ | TASK NAME | WHEN | DESCRIPTION ...
Martin Tournoij's user avatar
45 votes
7 answers
12k views

What is the easiest way to insert en dash in Vim?

To insert an en dash, I use ^v u 2014 which is seven keypresses. Is there an easier way? (I was looking at digraphs and didn't find en dash there.)
Tomas Tomecek's user avatar
45 votes
2 answers
12k views

How can I add line numbers to Vim?

I'd like to see line numbers, starting with 1 at the top, on the left side of Vim. Ideally it would look like this: 1 | foo = Foo.new 2 | bar = Bar.new 3 | baz = foo.baz(bar) ... 10| test = ...
user avatar
45 votes
10 answers
20k 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 ...
thameera's user avatar
  • 17.6k
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 ...
DeltaLima's user avatar
  • 1,155
45 votes
1 answer
15k views

Setting a vim option from the command line?

How does one set a vim option when launching from bash or another shell?
leeand00's user avatar
  • 3,621
44 votes
1 answer
21k views

Is there any way to change the popup menu color?

Is there any way to change the background color of the popup menu in gvim? The default background color is pink, which is a little weird to me.
Searene's user avatar
  • 543
44 votes
3 answers
15k 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 ...
Martin Tournoij's user avatar
44 votes
1 answer
26k 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 ...
Caleb's user avatar
  • 2,245
43 votes
8 answers
35k 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 ...
k0pernikus's user avatar
  • 2,997
43 votes
1 answer
31k views

How can I jump to the next "paragraph"?

Right now I'm working with some blocks of text that are over 1000 lines long. Is there a simple way to move to the beginning of the next paragraph? My workaround for now is searching for two ...
Christopher Bottoms's user avatar
43 votes
3 answers
26k views

When to use the after/ directory?

I understand it's the place to put things that should have the final say and not be overridden by another source, but I'm unclear on how to decide when to put something in, say, ~/.vim/after/ftplugin/ ...
ivan's user avatar
  • 1,470
42 votes
10 answers
109k 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.
Enrique GF's user avatar
42 votes
9 answers
19k 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?
firedev's user avatar
  • 2,432
42 votes
5 answers
9k 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 ...
bdesham's user avatar
  • 3,003
42 votes
5 answers
57k views

Fully disable mouse in console Vim

I saw completely disable mouse in console Vim on Stack Overflow. It sounded like exactly what I wanted, but there the problem was related to Cygwin, so the title was a misnomer. I want to know how to ...
James M. Lay's user avatar
42 votes
3 answers
23k 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.
iProgram's user avatar
  • 1,599
42 votes
2 answers
9k 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 ...
Wildcard's user avatar
  • 4,429
41 votes
14 answers
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 ...
Wildcard's user avatar
  • 4,429
41 votes
12 answers
9k 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 ...
JHK's user avatar
  • 775
41 votes
4 answers
47k 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 ...
KFL's user avatar
  • 595
41 votes
6 answers
9k 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. ...
void-pointer's user avatar
41 votes
5 answers
5k 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 ...
200_success's user avatar
  • 9,599
41 votes
2 answers
5k 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,...
John O'M.'s user avatar
  • 8,612
40 votes
1 answer
14k 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 ...
B Layer's user avatar
  • 20k
40 votes
2 answers
15k 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 ==...
Feffe's user avatar
  • 1,771
40 votes
3 answers
20k 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/, ...
oarfish's user avatar
  • 1,297
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 ...
Martin Tournoij's user avatar
40 votes
2 answers
6k 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?
Frames Catherine White's user avatar
39 votes
5 answers
8k 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 ...
200_success's user avatar
  • 9,599
39 votes
2 answers
49k 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 ...
poseid's user avatar
  • 493
39 votes
2 answers
15k 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 ...
Anthony's user avatar
  • 501
39 votes
4 answers
14k 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-...
Nikos Alexandris's user avatar
39 votes
1 answer
16k views

What are the differences between the map, noremap, abbrev and noreabbrev commands?

These commands transform one set of keystrokes to another in some way, but I am somewhat fuzzy on which one is most appropriate for some situation. In addition, there are the ! variants of them as ...
muru's user avatar
  • 25k
39 votes
6 answers
8k 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&...
Bhargav's user avatar
  • 1,103
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 ...
falstro's user avatar
  • 483
38 votes
4 answers
3k 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 ...
Enuy's user avatar
  • 481
37 votes
12 answers
35k 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 ...
DJMcMayhem's user avatar
  • 17.7k
37 votes
3 answers
24k 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 ...
Mike's user avatar
  • 485

15 30 50 per page