All Questions
13,697
questions
75
votes
4
answers
26k
views
How to save window, split, and buffer layout?
I have several tasks I am working on in one repository. I would like to create "workspaces" for working on them.
One "workspace" or "buffer layout" would have all files I need to work on open in the ...
74
votes
1
answer
45k
views
What is the difference between `filetype plugin indent on` and `filetype indent on`?
I see one of these two lines in .vimrc files. This one seems to be most common:
filetype plugin indent on
But how does it differ from this line:
filetype indent on
I've found documentation for the ...
73
votes
7
answers
112k
views
Is it possible to have vim auto-complete function names, variables, etc. when using it to program?
Many IDEs automatically complete function names, variables, method names, etc. as the user types. The best ones complete the names based both on the language's built-in library as well as what has ...
72
votes
2
answers
82k
views
How to indent as spaces instead of tab?
I am coding some html templates in JADE files. I want to auto indent code with spaces instead of tab. I tried shiftwidth=2, tabstop=2, but no matter what, it's still indents using tabs instead of ...
72
votes
3
answers
27k
views
Why should I use augroup?
I understand how auto commands work, and how to use them, but I'm somewhat unsure of what augroup is for. I read in :help augroup
*:aug* *:augroup*
:...
71
votes
6
answers
24k
views
Detect OS in Vimscript
Can I retrieve the current operating system (Windows, Linux, OS X, ..) using pure Vimscript (no Python or Perl)?
I want to enable different settings in my (synchronized) .vimrc for different types of ...
69
votes
6
answers
69k
views
How to add indentation guides/lines?
In Sublime Text 2, you get vertical guides where your indentation is, like this:
but Vim doesn't:
Is there a way to show lines like that in Vim?
By the way, my indentation is 2 spaces.
:set tabstop=...
69
votes
4
answers
23k
views
How to jump between matching HTML/XML tags?
How to jump between matching tags (such as <div>, <span>, etc.) when editing HTML/XHTML/XML documents similarly as % is used to jump between matching parentheses?
69
votes
6
answers
102k
views
How can I rename the file I'm editing?
Is it possible to rename the file I'm editing from within Vim? Currently what I do is exit Vim, rename the file and open from Vim again.
68
votes
3
answers
23k
views
Why does vim use hjkl for cursor keys?
Why use the keys hjkl on the same line instead of keys in a triangle like wasd for moving on video games?
Why not something equivalent with right hand, like ijkl or pl;'?
67
votes
13
answers
130k
views
How to insert a newline without leaving normal mode
I wonder if I can insert a new line without leaving normal mode. For example, I have two lines:
this is line one
this is line two
And the cursor is on line one. Now I want a new line between line ...
67
votes
5
answers
50k
views
How can I integrate gdb with Vim?
Instead of gdbtui or ctrl+x under gdb which shows source code on top of the screen I would like to see this in my Vim editor that would jump between tabs, and buffers accordingly.
How can I do this?
66
votes
1
answer
125k
views
Setting TAB to 2 spaces
I've looked through various answers which imply that setting the following in .vimrc would be appropriate to force tab insertions to become spaces.
filetype plugin indent on
" On pressing tab, ...
65
votes
3
answers
46k
views
How can I get a newer version of Vim on Ubuntu?
Ubuntu's packages can be pretty old, but for some desktop programs (like Vim) I'd much rather have the latest version, as newer versions often fix various bugs.
How can I get a reasonably recent Vim ...
65
votes
3
answers
24k
views
How can I get vim to stop putting comments in front of new lines?
I'm editing my .vimrc file, and I am including comments. When I have a comment like this:
" example comment
And then hit enter at the end of the line after finishing the comment, the next line is ...
64
votes
5
answers
48k
views
How can I open very large files with good performance?
I have server log files that are several gigabytes in size (on Ubuntu). When I attempt to open them, the terminal locks up for a minute or so while the file is loaded into Vim. Is there a way to ...
63
votes
2
answers
53k
views
What are the differences between :wq<cr> :x<cr> and ZZ when exiting vim?
Vi and Vim, as all of you know, have many synonyms. There are three ways I know of to save the file and exit Vim and Vi. These are :wq <cr>, :x <cr> and ZZ. I have heard that these are ...
62
votes
16
answers
23k
views
How to "full screen" browse Vim help?
I know I can browse Vim help with :help, but this opens a split. Sometimes, I just like to study documentation. How read documentation in a "full screen" mode?
62
votes
7
answers
50k
views
How to show only matching lines?
Is there a way to hide all lines that did not match, while going through the list of result lines?
In a long file, I would like to search for a pattern that will match roughly 200 lines or so. The ...
62
votes
3
answers
23k
views
How to make regex matchers non-greedy?
I am trying to use a regex for replacing text in a file (replace a full url with just protocol/domain/):
:%s/\(https\?:\/\/.*?\/\).*/\1/gc
Unfortunately .*? does not match the string, even trying to ...
62
votes
5
answers
99k
views
How can I change the indent size?
I just discovered I could indent and un-indent easily in Vi with : << and >>
By default it adds a tab character. Now I'm wondering, could this be to a number of spaces via a configuration in my ...
62
votes
2
answers
22k
views
How to run bash command over current file and replace buffer with result? [duplicate]
I currently deal with lots of json files and am quite fond of the bash comand jq, e.g. if I want to format the file I do
jq . ugly.json > formated.json
Now, I don't want to leave vim, but run it ...
61
votes
1
answer
7k
views
How much money has been raised for needy children in Uganda from Vim? [closed]
As it says under :help iccf…
Vim is Charityware. You can use and copy it as much as you like, but
you are encouraged to make a donation for needy children in Uganda.
Please see kcc below or ...
60
votes
1
answer
18k
views
How to fold text in a JSON file?
I have a large JSON file. It is not easy to work on all file at a time.
I want to fold some content so that I can work on a section of JSON file.
E.g.:
{
obj: {+}, // folded section
obj:{
...
59
votes
2
answers
17k
views
Close all split files, except the one currently focused?
Sometimes when I'm working on a file, I'll open up multiple files just to get an idea of the current flow of the code up to a point. However this sometimes leads to multiple files being open at a time ...
58
votes
4
answers
34k
views
How do I customize vimdiff colors?
I am trying to use vimdiff as my git merge tool, but the colors used are making it unbearable (at least on Windows/Mingw): the background color and the foreground color is the same for some of the ...
58
votes
3
answers
10k
views
How do I reload my vimrc without leaving Vim?
When I do a change in my .vimrc, I usually exit Vim and open it again. Is there an easier way to reload the new .vimrc changes?
58
votes
2
answers
17k
views
How can I view and edit my recording (i.e. recorded macro)?
I'm using complex repeats to record my operations (qq to record, some operations, q to stop) and I did a mistake.
It is possible to see what I've recorded and correct the mistake, instead of doing it ...
57
votes
4
answers
97k
views
What does :set background=dark do?
I didn't put color xxx in my .vimrc. So I see this when I first open my .vimrc.
:color gives me default here.
Then I type :color darcula. And it changes to this.
:color gives me darcula here (...
56
votes
5
answers
46k
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 ...
56
votes
3
answers
16k
views
How do I open a file from another git branch?
I'd like to open a file from another branch in the current git repository. I have seen this SO question, but the suggestions for combining it with Vim are cumbersome (pipe to Vim, open stdin, set ...
56
votes
1
answer
14k
views
See the Unicode code point of the current character
How can I see the Unicode code point of the character where the cursor is? For example, if my cursor is on a ⌘ character, I'd like Vim to tell me that it is U+2318.
Alternative information, such as ...
56
votes
1
answer
47k
views
What is the difference between autoindent and smartindent in vimrc?
I read the wiki entry on vim source code indentation
I still can't understand the difference between autoindent and smartindent
It seems they do the same thing, copy the indentation level to next ...
55
votes
3
answers
19k
views
How can I reload all buffers at once?
When working on a feature branch in git, I frequently need to stash my changes to commit a bug fix to the main branch. When I'm done working on the changes, I git stash pop, which updates the ...
55
votes
1
answer
7k
views
Expand a visual selection in the other direction
Sometimes I have selected a visual selection with, for example, Vjjjjj, only to realize later that I should have started the selection one line higher. However, pressing k simply decreases the lower ...
55
votes
6
answers
22k
views
How do I save a file in a directory that does not yet exist?
Suppose I start Vim to edit a new file in a directory that is not yet created:
vim nonExisitingDirectory/newFile.txt
Vim will happily show me an empty buffer and I can start writing my new file. But ...
55
votes
4
answers
22k
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 ...
55
votes
1
answer
19k
views
How can I use the undofile?
The last news item on vim.org talks about using the 'undofile' to save your history and undo changes even after a reboot:
A feature I enjoy using myself is not known to many users, as I found out ...
55
votes
2
answers
12k
views
How do I make Vim adapt to the current indenting style of the file I'm editing?
I work on a range of JavaScript projects. In most of these projects, the indentation of JavaScript files is 2 spaces, so I've set my default indentation width to that. However it becomes 1 or 4 in ...
55
votes
2
answers
19k
views
What are the differences between LaTeX plugins?
There are a number of Tex plugins for vim (vim-latex, AutomaticLatexPlugin to say a couple).
What are the differences in the provided functionalities between these (the ones I named and possibly ...
53
votes
5
answers
23k
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.
53
votes
5
answers
21k
views
Can Vim interpret terminal color escape codes?
Many CLI programs output nicely-highlighted text. While most of them check if the output is going to a file, some include the terminal escape codes. I like the output with the escape codes, but ...
53
votes
3
answers
160k
views
Find and replace using regular expressions
I have a file with a bunch of user defaults in. I want to change some of the text, but I'm struggling coming up with a matcher and replacer. Using the following example:
##############################...
51
votes
5
answers
15k
views
How to make a vimscript function with optional arguments?
I want to make a function that has optional arguments.
In python I would do something like this:
def functionName(arg1,arg2=false,arg3=false):
if arg2:
#Do stuff with arguments
else:
...
51
votes
6
answers
9k
views
Can I delete an entire line, except the line break?
A fairly common operation for me in vim, since I am compulsive-obsessive and like to keep my files free of whitespace, is to delete the contents of an entire line, but not the line itself (i.e. not ...
51
votes
5
answers
32k
views
How to diff and merge two directories?
I know that Vim's diff mode (vimdiff) allows us to compare the contents of two (or more) files.
But it is possible to compare content of multiple files across directories in order to merge two ...
49
votes
5
answers
16k
views
How to yank a line with a certain line number?
Say that I am on line 20 and I would like to yank line 4, how can I do that?
And similarly, how can I yank a line relative to my cursor position, say the one 3 lines up?
49
votes
5
answers
41k
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 ...
48
votes
6
answers
82k
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 ...
48
votes
4
answers
25k
views
How do I center the current line in the screen?
Is there a way to center the line I'm editing in the screen? This is sometimes needed to see a bit more context above and below the current line.