Questions tagged [vim]
Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor.
3,730
questions
600
votes
5
answers
287k
views
How do you reload your .vimrc file without restarting vim?
Can you edit your .vimrc file and reload it without having to restart Vim?
487
votes
5
answers
496k
views
How to open files in vertically/horizontal split windows in Vim from the command line
There must be a way, something like this:
vim -[option] <file-list>
to open files from command prompt and not from within Vim.
split windows vertically or/and horizontally
in separate tabs
293
votes
7
answers
242k
views
How to show the current column in the statusbar in vim?
I would like to show the current column in the statusbar, as is common in many other text editors. E.g. it's good to know if you are around column 80 or above.
How to show the current column in the ...
275
votes
9
answers
318k
views
In vim, how can I quickly switch between tabs?
In gnome-terminal, I can just press Alt + (1, 2, 3, etc.) to switch to specific tabs. I can also use Ctrl + (PgUp / PgDn) to cycle through tabs (admittedly less convenient, but it can be remapped).
...
237
votes
3
answers
128k
views
How to delete all lines that do NOT contain a certain word in Vim?
In vim I can delete all lines that contain the word "price" with this
:g /price/d
How can I delete all lines that do NOT contain the word "price"?
216
votes
5
answers
45k
views
How do you reuse a visual mode selection?
Often when editing code, I'll select a block in visual mode and do a search and replace over the block. After I make the changes, however, it leaves visual mode. How do you do a new find and replace ...
184
votes
5
answers
184k
views
How to run Unix commands from within Vim?
How can I run Unix commands while I'm inside vim?
167
votes
6
answers
30k
views
Invoking vi through find | xargs breaks my terminal. Why?
When invoking vim through find | xargs, like this:
find . -name "*.txt" | xargs vim
you get a warning about
Input is not from a terminal
and a terminal with pretty much broken behaviour afterwards....
160
votes
3
answers
88k
views
Git on Mac: How to set Nano as the default text editor?
When I'm using Git on Mac and need to do a rebase, the Vim editor kicks in by default. I would prefer Nano – could someone please explain how to reconfigure Git to make it use Nano for rebase?
151
votes
6
answers
44k
views
How do I reverse selected lines order in Vim?
For example, if I have four lines as follows:
the first line
the second line
the third line
the fourth line
I want to reverse them to
the fourth line
the third line
the second ...
148
votes
14
answers
67k
views
Why arrow keys are not recommended in Vim
"Never use arrow keys in Vim!"
I heard this from a random speaker, but didn't have the chance to ask him why. Also, if you don't use the arrow keys, how can you move the cursor in the Insert mode?
142
votes
3
answers
41k
views
vim freezes inside tmux
I’m using split panes in tmux – one being vim, the other being a shell.
Sometimes, around once a day, vim freezes. I can move between panes, perform any tmux commands, just vim doesn’t react to ...
141
votes
4
answers
83k
views
How do I open a blank new file in a split in Vim?
Must be something super obvious, but I can't figure out, and Google is not helping out either.
140
votes
14
answers
397k
views
What's the easiest way to delete Vim swapfiles I've already recovered from?
Sometimes Vim crashes and leaves me a swapfile. That's awesome. Then I open the file I was editing and Vim asks me if I want to recover. I do, thanks. When it's done, Vim tells me,
You may want ...
131
votes
4
answers
130k
views
How does one switch between windows on VIM?
I'm using both Vim and MacVim (or well, trying to). I installed the Tagbar plugin but find it impossible to switch to the actual Tagbar window to make my selection.
I've been reading loads about ...
129
votes
4
answers
145k
views
How to setup a line length marker in vim/gvim?
Some GUI text editors have a vertical line which serves as line length marker (it helps keeping lines shorter than 80 chars in source code files).
Is is possible to have something similar in vim/gvim?...
125
votes
2
answers
69k
views
How to start vim without executing /etc/vimrc?
On my Linux server at work, the admins did not install cscope, and I installed it from source in my home directory and added it to the $PATH. The trouble is, the /etc/vimrc has a reference to /usr/...
123
votes
4
answers
84k
views
Reload .vimrc in Vim without restart
It bothers me when I wrote something into .vimrc and I have to close it first and open to get my changes be applied.
Is there a way of reload .vimrc in Vim without closing it?
E.g. I've added set nu ...
121
votes
4
answers
60k
views
How to get vim to open multiple files into tabs at once
Is it possible to get vim to open multiple files into tabs, similar to the way the args <path> command will open multiple files into buffers?
Doing something like :tabe ./* results in the error ...
120
votes
8
answers
73k
views
How to search for selected text in Vim?
I'm aware that I can use / followed by a regex to search something. And I can use ? to search backwards. And I can use n and N to repeat the search forward and backward.
There are also two nice ...
119
votes
11
answers
78k
views
How do I open the directory of the current open file?
If I open a file with vim dir/to/my/file.c how can I easily open the directory dir/to/my in vim's filebrowser?
119
votes
4
answers
112k
views
How to add a command in vim editor?
If suppose my source code file name is "foo.c".
While editing and debugging i always execute this command:-
:!gcc -g foo.c -o foo;gdb foo
Can I add a custom command to Vim such that If i type ":...
117
votes
5
answers
145k
views
Selecting text in Tmux copy mode
I run Tmux in Vi mode. Vi-like navigation in copy mode works fine. However, I can't select any text. Neither v nor V switches to Vi-like text selecting mode.
What am I missing?
By the way, is it ...
113
votes
6
answers
169k
views
How can I recover the original file from a .swp file?
I tried opening the .swp file using vi and cat but it displays junk.
112
votes
1
answer
31k
views
How to make Vim spellcheck remember a new word
I'm using gVim for LaTeX editing. I write lots of scientific documents with words that the vim dictionary does not know. When running through spell checking I come across words that I know are ...
108
votes
8
answers
77k
views
256 color support for vim background in tmux
while using vim within tmux I can see that 256 color support is enabled. with $tput colors
However changing the colorscheme in vim while in tmux will change the colorscheme on a per line basis but ...
106
votes
3
answers
109k
views
How do I find the encoding of the current buffer in vim?
Say I am editing some file with vim (or gvim). I have no idea about the file's encoding and I want to know whether it is in UTF-8 or ISO-8859-1 or whatever? Can I somehow tell vim to show me what ...
104
votes
9
answers
63k
views
The best way to make MacVim's vim (console, not mvim) the default instead of Mac OS X's vim?
I installed MacVim using homebrew. (brew install macvim). If I call mvim from cmd, it opens the GUI MacVim.
I would like to make vim call the MacVim's Vim (/Users/user/Applications/MacVim.app/...
102
votes
9
answers
88k
views
How can I get (g)Vim to display the character count of the current file?
I like to write tutorials and articles for a programming forum I frequent. This forum has a character limit per post. I've used Notepad++ in the past to write posts and it keeps a live character ...
101
votes
9
answers
72k
views
Can I disable continuation of comments to the next line in Vim?
In Vim, if I'm typing a comment in a code file, and I hit Enter, it automatically makes the newline a comment, too.
For instance, in a Ruby file:
# I manually typed the pound at the start of this ...
96
votes
11
answers
64k
views
brew upgrade broke Vim on OS X (dyld: Library not loaded)
I've not run brew update && brew upgrade for a long time.
I just did a massive upgrade which turned out to broke my Vim.
This is what I got after running vim:
dyld: Library not loaded: /usr/...
94
votes
6
answers
139k
views
Vim Stuck In Insert Mode
I've been using Vim for several months now via my web host (they allow putty access). All of a sudden, the escape key has become unresponsive. I cannot exist insert or any other mode by simply hitting ...
93
votes
13
answers
42k
views
How do I replace-paste yanked text in vim without yanking the deleted lines?
So I usually find myself copying text from one point to another while overwriting old text where the new is pasted:
blah1
newtext
blah2
wrong1
blah3
wrong2
blah4
Suppose I visual-mark newtext and ...
88
votes
2
answers
43k
views
vim cut and paste history
When I'm 'cutting' in vim, I believe there are registers that keep a history of all the recent things I've cut. How do I access those registers?
For example, let's say I cut each one of these words ...
87
votes
2
answers
40k
views
How to get back to insert mode in VIM when you accidentally hit C-x C-s
Given this vim session:
% vim test-file.txt
iHello there!C-x C-s
How do I get back to insert/command mode again?
(C-x C-s means Control-x Control-s, not sure if it's normal vi terminology for ...
86
votes
11
answers
78k
views
How can I open a file read-only from command line with emacs/vi/vim
Is there a way to tell emacs/vi/vim (from the command line) that I want to view the file in view-mode or read-only.
I know how to open a file as read only if emacs/vi/vim is already running.
85
votes
4
answers
35k
views
How do I change until the next underscore in VIm?
If I have this text in vim, and my cursor is at the first character:
www.foo.com
I know that I can do:
cw to change up to the first period, because a word (lowercase w) ends at any punctuation OR ...
85
votes
7
answers
52k
views
Mac OS X Terminal: mouse support?
Is there a native option (ie. without installing extra soft/package/plugins) to enable mouse support in the Terminal app?
Actually, I'm using a lot vim with the option set mouse=a (activating mouse ...
85
votes
4
answers
219k
views
Using vim to force edit a file when you opened without permissions
I use vim to edit a file. Sometimes, I forget to have the appropriate permissions. I run vim and the file as a read only file. I can make changes, but I can't actually write the changes. Every once in ...
84
votes
4
answers
33k
views
How do I tell what syntax file is being used?
Vim is syntax highlighting my file in a funny way, and I want to know what syntax file is responsible for this behaviour. How do I find out what syntax files vim has loaded?
84
votes
1
answer
81k
views
Pressing "Ctrl + S" by mistake while using Vim
If you press Ctrl + s while using vim would result with vim to look like as if it is being locked/stuck without you being able to make more changes unless you press Ctrl + q.
Could someone explain ...
83
votes
11
answers
58k
views
Vim: How to synchronize NERDTree with current opened tab file path?
When I open a new tab with different path from the previous file in VIM, NERDTree will still remains the same directory hierarchy of the previous file.
Is there a sync shortcut to change the current ...
79
votes
5
answers
25k
views
Slight delay when switching modes in vim using tmux or screen
Switching to and from insert mode in Vim is no longer instantaneous since I use tmux. After pressing Esc in insert mode, it takes a noticeable amount of time to actually get out of insert mode. After ...
77
votes
5
answers
28k
views
Where does VIM (gvim/macvim) keep swap files for unsaved/unnamed buffers?
Where does VIM (gvim/macvim) keep swap files for unsaved/unnamed buffers? (If it does so at all).
Background:
Throughout a semi intense seminar I was taking notes in an unnamed/unsaved MacVim buffer ...
74
votes
10
answers
94k
views
How to remove this symbol "^@" with vim?
I have some files that are corrupted with this symbol:
^@
It's not part of the string; it's not searchable. How do I substitute this symbol with nothing, or how do I delete this symbol?
Here is ...
74
votes
13
answers
61k
views
Windows Subsystem Linux - Make VIM use the clipboard?
To get this off the table now and avoid any confusion ... This is for Linux running in Windows 10(ubunutu), also known as WSL. Its not the same as cygwin and windows or stand alone linux. It is it's ...
72
votes
7
answers
38k
views
How do I edit an existing buffer in a new tab in vim?
Suppose I have started vim like this:
vim foo bar
Now I decide that I want each of those files in its own tab. Is there a way to do that without exiting vim and adding the -p option to my command ...
69
votes
8
answers
37k
views
Move cursor to beginning of non-whitespace characters in a line in Vim
In Vim, is there a way to move the cursor to the beginning of non-whitespace characters in a line? For instance, how can I move the cursor to the "S" in the second line below?
First line
Second ...
65
votes
8
answers
63k
views
tmux copy mode - select text block
I'm using tmux with vi keys, and copy/paste works fine as long as you're selecting one line of text, or if you have only one window. When I want to select a block of text (multiple lines, but not full ...
65
votes
5
answers
192k
views
How to use vimtutor?
Someone recommended me that I should use vimtutor to learn the basics of vim. But I have no idea how to use it. Is it an application? A website?
This is the only link that was given during the ...