Questions tagged [vim]
Vim is a free and open-source modal text editor available for most major platforms. It allows high efficiency in many text editing tasks but has a steep learning curve. To learn the basics, run ":help vimtutor". For non-programming questions please use https://vi.stackexchange.com/ instead.
28,182
questions
5327
votes
13
answers
3.0m
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.
3354
votes
35
answers
1.4m
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?
2423
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 ...
2413
votes
34
answers
982k
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?
2359
votes
34
answers
722k
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 ...
2055
votes
16
answers
684k
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 ...
2017
votes
22
answers
952k
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?
1726
votes
11
answers
542k
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 ...
1579
votes
55
answers
1.4m
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
# ...
1506
votes
27
answers
631k
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 ...
1437
votes
5
answers
336k
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?
1434
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 ...
1422
votes
16
answers
999k
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?
1342
votes
5
answers
525k
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.
1335
votes
14
answers
1.1m
views
Redefine tab as 4 spaces
My current setting assumes 8 spaces; how could I redefine it?
1235
votes
29
answers
701k
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 ...
1124
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 ...
1112
votes
40
answers
939k
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 ...
1104
votes
38
answers
1.1m
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 ...
1098
votes
17
answers
357k
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 ...
917
votes
6
answers
421k
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?
899
votes
23
answers
812k
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.
831
votes
29
answers
698k
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?
830
votes
70
answers
134k
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....
824
votes
14
answers
231k
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 ...
797
votes
30
answers
531k
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 ...
790
votes
28
answers
1.3m
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?
771
votes
14
answers
426k
views
Vim delete blank lines
What command can I run to remove blank lines in Vim?
728
votes
10
answers
319k
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)?
713
votes
12
answers
171k
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?
712
votes
16
answers
369k
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 ...
707
votes
9
answers
183k
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.
664
votes
7
answers
454k
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"?
662
votes
15
answers
446k
views
What does the ^M character mean in Vim?
I keep getting the ^M character in my .vimrc and it breaks my
configuration.
612
votes
3
answers
271k
views
Changing case in Vim
Is there a command in Vim that changes the case of the selected text?
605
votes
11
answers
626k
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 ...
588
votes
22
answers
840k
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 ...
586
votes
10
answers
357k
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 ...
580
votes
8
answers
161k
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;">...
549
votes
30
answers
94k
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 ...
522
votes
38
answers
429k
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?
517
votes
15
answers
149k
views
Using Caps Lock as Esc in Mac OS X
How do I make Caps Lock work like Esc in Mac OS X?
514
votes
11
answers
394k
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.
513
votes
14
answers
487k
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 ...
507
votes
16
answers
786k
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 ...
485
votes
15
answers
319k
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 ...
473
votes
23
answers
292k
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 ...
468
votes
15
answers
303k
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
...
467
votes
4
answers
184k
views
How to comment in Vim's config files: ".vimrc"?
How do I add a comment in Vim's configuration files, like .vimrc?
465
votes
34
answers
276k
views
What are the benefits of learning Vim? [closed]
As a programmer I spend a lot of hours at the keyboard and I've been doing it for the last 12 years, more or less. If there's something I've never gotten used to during all this time, it's these ...