Skip to main content
Just browsing Stack Overflow? Help us improve your experience. Sign up for research
Filter by
Sorted by
Tagged with
5427 votes
13 answers
3.1m views

How do I exit Vim?

I am stuck and cannot escape. It says: type :quit<Enter> to quit VIM But when I type that it simply appears in the object body.
jclancy's user avatar
  • 52.2k
3432 votes
35 answers
1.5m views

How do I make git use the editor of my choice for editing commit messages?

How do I globally configure git to use a particular editor (e.g. vim) for commit messages?
brasskazoo's user avatar
  • 78.6k
2459 votes
12 answers
1.1m views

How to replace a character by a newline in Vim

I'm trying to replace each , in the current file by a new line: :%s/,/\n/g But it inserts what looks like a ^@ instead of an actual newline. The file is not in DOS mode or anything. What should I ...
Vinko Vrsalovic's user avatar
2439 votes
34 answers
1.0m views

Indent multiple lines quickly in vi

It should be trivial, and it might even be in the help, but I can't figure out how to navigate it. How do I indent multiple lines quickly in vi?
Allain Lalonde's user avatar
2396 votes
35 answers
756k views

Vim clear last search highlighting

After doing a search in Vim, I get all the occurrences highlighted. How can I disable that? I now do another search for something gibberish that can't be found. Is there a way to just temporarily ...
Gabriel Solomon's user avatar
2101 votes
16 answers
719k views

How to do case insensitive search in Vim

I'd like to search for an upper case word, for example COPYRIGHT in a file. I tried performing a search like: /copyright/i # Doesn't work but it doesn't work. I know that in Perl, if I give the ...
Haiyuan Zhang's user avatar
2061 votes
23 answers
1.0m views

How to duplicate a whole line in Vim?

How do I duplicate a whole line in Vim in a similar way to Ctrl+D in IntelliJ IDEA/ Resharper or Ctrl+Alt+↑/↓ in Eclipse?
sumek's user avatar
  • 28k
1748 votes
11 answers
571k views

How does the vim "write with sudo" trick work?

Many of you have probably seen the command that allows you to write on a file that needs root permission, even when you forgot to open vim with sudo: :w !sudo tee % The thing is that I don't get ...
Doppelganger's user avatar
  • 20.7k
1647 votes
55 answers
1.6m views

What's a quick way to comment/uncomment lines in Vim?

I have a Ruby code file open in vi, there are lines commented out with #: class Search < ActiveRecord::Migration def self.up # create_table :searches do |t| # t.integer :user_id # ...
Ethan's user avatar
  • 60k
1545 votes
27 answers
665k views

Turning off auto indent when pasting text into vim

I am making the effort to learn Vim. When I paste code into my document from the clipboard, I get extra spaces at the start of each new line: line line line I know you can turn off auto ...
Rimian's user avatar
  • 38.3k
1460 votes
4 answers
355k views

What is the difference between the remap, noremap, nnoremap and vnoremap mapping commands in Vim?

What is the difference between the remap, noremap, nnoremap and vnoremap mapping commands in Vim?
Chetan's user avatar
  • 47.9k
1443 votes
12 answers
1.1m views

Tab key == 4 spaces and auto-indent after curly braces in Vim

How do I make vi-Vim never use tabs (converting spaces to tabs, bad!), makes the tab key == 4 spaces, and automatically indent code after curly brace blocks like Emacs does? Also, how do I save these ...
mmcdole's user avatar
  • 92.7k
1439 votes
16 answers
1.0m views

How do I move to end of line in Vim?

I know how to generally move around in command mode, specifically, jumping to lines, etc. But what is the command to jump to the end of the line that I am currently on?
salt.racer's user avatar
  • 22.3k
1370 votes
15 answers
1.1m views

Redefine tab as 4 spaces

My current setting assumes 8 spaces; how could I redefine it?
Ricky's user avatar
  • 35.8k
1357 votes
5 answers
551k views

What is the <leader> in a .vimrc file?

I see <leader> in many .vimrc files, and I am wondering what does it mean? What is it used for? Just a general overview of the purpose and usage would be great.
Bob Martens's user avatar
  • 13.9k
1250 votes
29 answers
732k views

How to effectively work with multiple files in Vim

I've started using Vim to develop Perl scripts and am starting to find it very powerful. One thing I like is to be able to open multiple files at once with: vi main.pl maintenance.pl and then hop ...
Edward Tanguay's user avatar
1156 votes
40 answers
1.0m views

How to copy to clipboard in Vim?

Is it possible to copy to clipboard directly from Vim? yy only copies stuff to Vim's internal buffer. I want to copy to the OS's clipboard. Is there any such command in Vim or you can only yank stuff ...
Hari Menon's user avatar
  • 35.2k
1144 votes
38 answers
1.2m views

How can I make Vim paste from (and copy to) the system's clipboard?

Unlike other editors, Vim stores copied text in its own clipboard. So, it's very hard for me to copy some text from a webpage and paste it into the current working file. It so happens I have to either ...
Santosh Kumar's user avatar
1122 votes
50 answers
1.0m views

What is your most productive shortcut with Vim?

I've heard a lot about Vim, both pros and cons. It really seems you should be (as a developer) faster with Vim than with any other editor. I'm using Vim to do some basic stuff and I'm at best 10 times ...
1120 votes
17 answers
385k views

How do I use vim registers?

I only know of one instance using registers is via CtrlR* whereby I paste text from a clipboard. What are other uses of registers? How to use them? Everything you know about VI registers (let's ...
928 votes
6 answers
445k views

What is Vim recording and how can it be disabled?

I keep seeing the recording message at the bottom of my gVim 7.2 window. What is it and how do I turn it off?
vehomzzz's user avatar
  • 44.5k
910 votes
23 answers
835k views

Make Vim show ALL white spaces as a character

I can't find a way to make Vim show all white spaces as a character. All I found was about tabs, trailing spaces etc.
user avatar
840 votes
14 answers
248k views

How to move screen without moving cursor in Vim?

I recently discovered Ctrl+E and Ctrl+Y shortcuts for Vim that respectively move the screen up and down with a one line step, without moving the cursor. Do you know any command that leaves the cursor ...
ereOn's user avatar
  • 55.6k
837 votes
29 answers
716k views

Convert DOS/Windows line endings to Linux line endings in Vim

If I open files I created in Windows, the lines all end with ^M. How do I delete these characters all at once?
Bert Hekman's user avatar
  • 9,227
829 votes
70 answers
135k views

What are the dark corners of Vim your mom never told you about? [closed]

There are a plethora of questions where people talk about common tricks, notably "Vim+ctags tips and tricks". However, I don't refer to commonly used shortcuts that someone new to Vim would find cool....
807 votes
29 answers
1.4m views

Copy all the lines to clipboard

Is there any way to copy all lines from open file to clipboard in VI editor. I tried yG but it's not using clipboard to store those lines. So is it possible?
Xinus's user avatar
  • 30.4k
803 votes
30 answers
548k views

Differences between Emacs and Vim

What practical, objective differences are there between Emacs and Vim? For example, what can be done using one but not the other (or done more easily with one than the other)? What should I know in ...
800 votes
14 answers
449k views

Vim delete blank lines

What command can I run to remove blank lines in Vim?
nearly_lunchtime's user avatar
747 votes
10 answers
334k views

How do I do redo (i.e. "undo undo") in Vim?

In Vim, I did too much undo. How do I undo this (that is, redo)?
flybywire's user avatar
  • 272k
720 votes
16 answers
385k views

How do I fix the indentation of an entire file in Vi?

In Vim, what is the command to correct the indentation of all the lines? Often times I'll copy and paste code into a remote terminal and have the whole thing messed up. I want to fix this in one ...
mmcdole's user avatar
  • 92.7k
719 votes
12 answers
178k views

How to paste yanked text into the Vim command line

I'd like to paste yanked text into Vim's command line. Is it possible?
dan's user avatar
  • 45.5k
716 votes
9 answers
190k views

To switch from vertical split to horizontal split fast in Vim

How can you switch your current windows from horizontal split to vertical split and vice versa in Vim? I did that a moment ago by accident but I cannot find the key again.
Léo Léopold Hertz 준영's user avatar
690 votes
7 answers
504k views

"Find next" in Vim

To search forward in Vim for cake, I'd type /cake, but the cursor jumps to the first match when I press return. Is there a Vim command analogous to "find next"?
Yktula's user avatar
  • 14.7k
673 votes
15 answers
469k views

What does the ^M character mean in Vim?

I keep getting the ^M character in my .vimrc and it breaks my configuration.
Max's user avatar
  • 6,733
650 votes
3 answers
298k views

Changing case in Vim

Is there a command in Vim that changes the case of the selected text?
Amir Rachum's user avatar
  • 79.3k
641 votes
11 answers
677k views

Find and replace strings in vim on multiple lines

I can do :%s/<search_string>/<replace_string>/g for replacing a string across a file, or :s/<search_string>/<replace_string>/ to replace in current line. How can I select and ...
Anshul Goyal's user avatar
  • 76.5k
605 votes
23 answers
879k views

Where is my .vimrc file?

I have been using Vim, and I would really like to save my settings. The problem I am having is that I cannot find my .vimrc file, and it is not in the standard /home/user/.vimrc location. How might I ...
Eman's user avatar
  • 6,701
602 votes
10 answers
386k views

How do I close a single buffer (out of many) in Vim?

I open several files in Vim by, for example, running vim a/*.php which opens 23 files. I then make my edit and run the following twice :q which closes all my buffers. How can you close only one ...
Léo Léopold Hertz 준영's user avatar
593 votes
8 answers
169k views

How can I make my match non greedy in vim?

I have a big HTML file that has lots of markup that looks like this: <p class="MsoNormal" style="margin: 0in 0in 0pt;"> <span style="font-size: small; font-family: Times New Roman;">...
Mark Biek's user avatar
  • 150k
552 votes
31 answers
97k views

In Vim is there a way to delete without putting text in the register?

Using Vim I often want to replace a block of code with a block that I just yanked. But when I delete the block of code that is to be replaced, that block itself goes into the register which erases ...
Edward Tanguay's user avatar
525 votes
17 answers
828k views

Move cursor to end of file in vim

When I want the cursor to go to the end of the file (i.e. the end of the last line) in Vim, I have to type six keystrokes: <ESC>G$a - which translates to ESC + Shiftg + Shift4 + a on my ...
user avatar
524 votes
38 answers
434k views

Convert ^M (Windows) line breaks to normal line breaks

Vim shows ^M on every line ending. How do I replace this with a normal line break in a file opened in Vim?
ByteNirvana's user avatar
  • 5,690
524 votes
11 answers
412k views

How to get the list of all installed color schemes in Vim?

Is there a way to get a list of all installed color schemes in Vim? That would make very easy to select one without looking at the .vim directory.
tunnuz's user avatar
  • 23.9k
519 votes
15 answers
153k views

Using Caps Lock as Esc in Mac OS X

How do I make Caps Lock work like Esc in Mac OS X?
indentation's user avatar
  • 9,985
518 votes
15 answers
511k views

How to insert text at beginning of a multi-line selection in vi/Vim

In Vim, how do I insert characters at the beginning of each line in a selection? For instance, I want to comment out a block of code by prepending // at the beginning of each line assuming my ...
Jordan Parmer's user avatar
489 votes
16 answers
334k views

Vim: insert the same characters across multiple lines

Sometimes I want to edit a certain visual block of text across multiple lines. For example, I would take a text that looks like this: name comment phone email And make it look like this ...
hobbes3's user avatar
  • 30.1k
485 votes
23 answers
314k views

Renaming the current file in Vim

How should I rename my current file in Vim? For example: I am editing person.html_erb_spec.rb I would like it renamed to person.haml_spec.rb I would like to continue editing person.haml_spec.rb How ...
Sam Saffron's user avatar
485 votes
15 answers
325k views

Vim and Ctags tips and tricks [closed]

I have just installed Ctags (to help with C++ development) with my Vim (or rather gVim), and would like to find out your favorite commands, macros, shortcuts, tips that go along with it... Share your ...
user avatar
482 votes
4 answers
195k views

How to comment in Vim's config files: ".vimrc"?

How do I add a comment in Vim's configuration files, like .vimrc?
wyc's user avatar
  • 55.2k
473 votes
12 answers
478k views

Replace tabs with spaces in vim

I would like to convert tab to spaces in gVim. I added the following line to my _vimrc: set tabstop=2 It works to stop at two spaces but it still looks like one tab key is inserted (I tried to use ...
David.Chu.ca's user avatar
  • 38.6k

1
2 3 4 5
565