48
votes
Accepted
What are the differences between :wq<cr> :x<cr> and ZZ when exiting vim?
From Vim's documentation, :x and ZZ are equivalent; they only save the file if it has been modified, then quit Vim:
Write current file, if modified, and quit (same as ":x").
(Note: If there are ...
41
votes
Accepted
How to diff and merge two directories?
There is DirDiff.vim plugin to diff and merge two directories recursively.
It performs a recursive diff on two directories and generate a diff
"window". Based on that window you can perform ...
25
votes
Accepted
Applying settings to a directory tree only
There are a few lightweight ways to do this.
Check for a file of given name and source it
if filereadable(".vimscript_file")
so .vimscript_file
endif
The file is hidden in the example but that'...
25
votes
Accepted
How do I copy a file in netrw?
You cannot use y, p etc., to copy files in netrw - it comes with its own commands. See :h netrw-mc:
MARKED FILES: COPYING netrw-mc {{{2
(See ...
23
votes
What are the differences between :wq<cr> :x<cr> and ZZ when exiting vim?
As akshay pointed out, Vim's documentation explains, that :x and ZZ are equivalent and only save a file if the associated buffer has been changed.
Whereas :wq saves the buffer to the corresponding ...
21
votes
Accepted
How can I make Vim autoread a file while it doesn't have focus?
:help 'autoread' doesn't have a lot of information on how it works, but Vim checks if an open file is modified in certain events (it always does this), and will reload it automatically if autoread is ...
18
votes
Accepted
Can I search through 'oldfiles' with a specific name or extension?
Assuming you have Vim 8 you can use :filter
:browse filter /pattern/ oldfiles
For more help see:
:h :browse
:h :filter
:h oldfiles
:h new-items-8
15
votes
Applying settings to a directory tree only
I use localvimrc for this purpose.
Put a .lvimrc with your project settings inside your project and these settings will override settings in .vimrc.
By default, you will be asked if you want to ...
12
votes
Accepted
How do I get filename completion to ignore a leading `=`?
The list of valid filename characters is given by the isfname variable. From :he 'isfname':
'isfname' 'isf' string (default for MS-DOS, Win32 and OS/2:
"@,48-57,/,\,.,-,...
12
votes
Accepted
How to do :Sex but with a vertical split?
What you're looking for is :Vexplore.
From your question, it sounds like you started off knowing only about :Sexplore and understandably thought that that was the basic command for bringing up the ...
10
votes
How do I copy a file in netrw?
I would do this from the command line mode:
Select the file you need in netrw
Open command the line and type - :!mv <C-R><C-F> ../<C-R><C-F>
Here <C-R><C-F> ...
10
votes
How to pass current file name with a different path to the command line
Special characters (see :h cmdline-special) and filename modifiers (see :h filename-modifiers) are expanded on the command line, so:
:diffsplit Path/to/other/directory/%:t
10
votes
Accepted
Is there an elegant way to determine if a file exists in/under runtimepath?
You're looking for globpath(). If it returns a non empty string, then there is at least a match.
if !empty((globpath(&rtp, '/autoload/FooBarBaz.vim'))
You may also want to check filereadable() ...
9
votes
Accepted
Open a file at the given line using the colon notation
You can use the relatively popular file-line plugin. Note that this plugin seems relatively unmaintained, and there exists several forks. I have a personal fork where I've made some minor updates and ...
9
votes
Accepted
Read file from vimscript variable
This is because vim does not evaluate variable names or functions with most commands. In your case, vim thinks you literally want to read the contents of a file called g:filePath into the buffer. ...
8
votes
Accepted
Can I use some file-tree selector which exists on graphical IDEs?
Vim comes with a built-in file explorer called netrw. If you have a reasonaby recent Vim, the following command will give you the kind of feature you are missing:
:Lexplore
See :help netrw.
8
votes
How can I go into a directory in filename completion?
I prefer to type / because extra/////slashes///are//ignored.
Also, the arrow keys are poison. :)
8
votes
Accepted
8
votes
How to insert a file path with tab- or autocompletion relative to the current file's dir?
You can use vim's file name completion feature for this. To use it, press CTRL-xCTRL-f in insert mode. For more on this, see :help compl-filename. Do note that it isn't recursive, so you must ...
8
votes
How to write a value or variable into a file using only vimscript?
writefile() is the ticket, but has some quirks you have to account for, such as splitting on newlines.
An example:
call writefile(split(varname, "\n", 1), glob('/path/to/file'), 'b')
8
votes
Find project root relative to the active buffer
After following dedowsdi's instructions, it turns out you just need to do:
let dir = finddir('.git/..', expand('%:p:h').';')
expand(%) expands into the path of the current file (excluding the ...
7
votes
Make :edit {file} use current directory during :Explore
I set the following two options to ensure that Vim's current working directory is always the same as the current buffer's.
set autochdir " Changes the cwd to the directory of the ...
7
votes
Make :edit {file} use current directory during :Explore
Yes, vim has a :cd command, which either prints the current directory or changes the current directory. In the help is this - note the last lines:
:cd[!] {path} Change the current ...
7
votes
How can I make ctrlp do better filename matching?
A similar question was just asked on the Vim reddit here. I started using ctrlp-cmatcher myself quite awhile ago which I find to be much more intelligent at matching the right file. Note that it does ...
7
votes
How do I open file under cursor, when the filename has a trailing dot?
From :help gf:
Trailing punctuation characters ".,:;!" are ignored.
So I suppose the dot at the end is not considered as part of the filename but as punctuation.
I don't know if it can be done with ...
7
votes
Accepted
Is there a quick way to open a file anywhere within a directory hierarchy?
You can do this by setting the 'path' option to include **, and then using the :find command:
:set path=.,,**
:find filename.cpp
The section on File Searching in the documentation describes how the *...
6
votes
Accepted
How do I make vim look in a set of directories for a file, if it doesn't exist in the current directory?
Vim's 'path' option allows you to specify directories which commands like gf and :find will search for a file.
If you only want this functionality to trigger for a specific set of files, then you ...
6
votes
Filename Completion for Remote Files
Yes, but currently(2015) not out-of-the-box, because the built-in file-manager of vim doesn't natively support remote browsing. .
Update Q3@2016:
There are several work-arounds, with varying degrees ...
6
votes
Read file from vimscript variable
The solution to this type of problem is the :execute command:
:execute '0read' g:filepath
See
:help :execute
6
votes
Read file from vimscript variable
Commands like read don't evaluate your variables, it takes the argument to be a literal (a file named g:filePath). The execute command, however, takes string arguments, concatenates them and executes ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
filesystem × 85netrw × 12
vimscript × 11
multiple-files × 8
autocompletion × 7
command-line × 4
microsoft-windows × 4
external-command × 4
save × 4
vimrc × 3
cut-copy-paste × 3
plugin-nerdtree × 3
working-directory × 3
plugin-ctrlp × 3
load × 3
key-bindings × 2
neovim × 2
gvim × 2
buffers × 2
autocmd × 2
substitute × 2
normal-mode × 2
split × 2
linux × 2
undo-redo × 2