Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [filesystem]

For questions regarding searching and navigating the filesystem.

Filter by
Sorted by
Tagged with
69 votes
2 answers
58k 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 ...
wefwefa3's user avatar
  • 1,173
52 votes
5 answers
35k 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 ...
kenorb's user avatar
  • 18.6k
40 votes
6 answers
4k views

Applying settings to a directory tree only

At my work we use a standard ts of 2; my personal preference is 4, which is what I use for my hobby projects, and this other project we inherited has the convention of ts=8. There are also some other ...
Martin Tournoij's user avatar
38 votes
4 answers
9k views

How can I make Vim autoread a file while it doesn't have focus?

I'm using VIm for all kinds of things (or gVim in this case), including monitoring output written to a file; I use autoread to make Vim reread the file, which it does whenever I switch the keyboard ...
falstro's user avatar
  • 483
21 votes
3 answers
23k views

How do I copy a file in netrw?

The current working directory is ./A/B/. An empty document is opened when I type vim, and the netrw is opened with command :e. The window is split by vs., and I can navigate to the upper level ...
user3813057's user avatar
  • 1,471
18 votes
1 answer
1k views

Filename Completion for Remote Files

My friend showed me a cool trick on Emacs some days ago where he could just open a file on a remote server and I instantly thought "there should be a way to do that in vim too" and it was true. I ...
m.ajallooeian's user avatar
14 votes
2 answers
954 views

Can I search through 'oldfiles' with a specific name or extension?

I use the oldfiles and browse oldfiles commands all the time. I find them extremely useful, because it's easier to hit my leader mapping, scan through the files really quickly, and hit q<number>...
DJMcMayhem's user avatar
  • 17.6k
12 votes
2 answers
2k views

How can I make ctrlp do better filename matching?

My project has these files: $ find . -type f -and -name 'peop*' ./app/assets/stylesheets/admin/sections/people.css.sass ./app/controllers/admin/people_controller.rb As I got tired of typing :e app/...
Martin Tournoij's user avatar
10 votes
5 answers
3k views

How do I make vim look in a set of directories for a file, if it doesn't exist in the current directory?

When I want to edit my zshrc, I just type: vim .zshrc Without specifying the full path (~/.zshrc), if I am in a different directory, this will instead start a new file. This is very annoying, since ...
muru's user avatar
  • 24.9k
9 votes
4 answers
181 views

Can I use some file-tree selector which exists on graphical IDEs?

It is normally on the left side, and it enables a fast switching between files in a complex directory hierarchy.
peterh's user avatar
  • 1,161
9 votes
1 answer
264 views

How do I open a file using `gf` in case-insensitive manner?

I want to open Test.txt file when I put the cursor on the word test.txt and type gf. Is it possible?
npcode's user avatar
  • 191
8 votes
3 answers
3k views

Make :edit {file} use current directory during :Explore

I often use :Ex or :Sex to explore the filesystem from an opened file directory, or just invoke vim passing a directory to start exploring the filesystem and then opening a file. In any case, while ...
guido's user avatar
  • 1,757
8 votes
3 answers
1k views

How to pass current file name with a different path to the command line

Is there any way to make the special symbol % work with path names on the command line? For instance, I'd like to do: :diffsplit Path\to\other\directory\% So that I can do a @: to quickly compare ...
Tumbler41's user avatar
  • 7,756
8 votes
1 answer
901 views

Open a file at the given line using the colon notation

I'm often using grep to search for patterns and then opening the file with vim. For example I've the following result in my shell: interactions/BlockInteraction.js:38: .concat(...
krampstudio's user avatar
  • 1,255
7 votes
3 answers
5k views

Read file from vimscript variable

I can run this snippit of code within a vimscript block: 0read /home/user/.vim/bundle/vim-lorum/lorums/lorum.js As expected, it puts the contents of "lorum.js" into the current buffer But, I need ...
Jonathan.Brink's user avatar
7 votes
4 answers
1k views

What workflow to use when editing large multifile projects

Lately I've been shifting more nad more of my work from IntelliJ to vim. With a handful of plugins and setting tweaks, I don't miss the IDE much. One thing I do miss is the ease of navigating a large ...
Jones's user avatar
  • 171
7 votes
2 answers
1k views

Convert absolute path to one relative to another absolute one

Context I’m working on an 'omnifunc' function for Markdown editing. It’s supposed to help me link to other Markdown files while I’m typing a link – based on file content though, not file name. Suppose ...
scy won't contribute anymore's user avatar
7 votes
2 answers
1k views

Creating tags between markdown files similar to :h

One of the first things you learn in vimtutor is to follow links in the vim help files with Ctrl-]. I'm interested in creating my own tags/linking system in arbitrary files. For the sake of this ...
davidlowryduda's user avatar
6 votes
2 answers
175 views

How do I get filename completion to ignore a leading `=`?

Occasionally, when writing shell scripts and such, I have entries of the form: foo=/bar/baz To get filename completion (<C-x> <C-f>) to work, I have to put a space after the =, and then ...
muru's user avatar
  • 24.9k
6 votes
3 answers
861 views

Is it possible to open a new file that starts with '+'?

I cannot figure out how to open a file that starts with +, e.g. +models/File.m. This is a naming convention for packages in Matlab. I've tried escaping \+models/File.m. This doesn't work because the ...
diestl's user avatar
  • 163
6 votes
1 answer
2k views

How do I open a file that starts with an exclamation mark using filename completion?

In gVim, I want to open a file that starts with an exclamationmark, say, for example, !this_is_my_file_whose_name_is_rather_long.txt. So, I type :e !this followed by pressing the tabulator. gVim ...
René Nyffenegger's user avatar
6 votes
1 answer
86 views

Tab to complete filenames with :find at an arbitrary depth

Notes: I have set path=$PWD/** in my .vimrc I am using Vim 7.3 Often times, I am sitting with Vim open at the root of my project and I enter :find somef<Tab> to find and open a file at an ...
user avatar
5 votes
2 answers
114 views

How can I go into a directory in filename completion?

Consider a directory structure like this: topdir/ file1 file2 foo/ bar1 bar2 Say I want to open some file in foo/ in a new tab. I would first write :tabe topdir/, and then keep hitting ...
wchargin's user avatar
  • 2,727
5 votes
3 answers
2k views

How do I open file under cursor, when the filename has a trailing dot?

There is a file with name ./folderA/folderB/file.. And there is text: ./folderA/folderB/file.:abcdefg When I move the cursor on letter B and type <c-w>f, it says E447: Can't find file "./...
user3813057's user avatar
  • 1,471
5 votes
1 answer
2k views

How to insert a file path with tab- or autocompletion relative to the current file's dir?

I am in vim in the .gitignore file. I now want to add a file path that already exists on the current dir, e.g. ./app/poit/narf/auth.json I don't want to type it though, I want to navigate to that ...
k0pernikus's user avatar
  • 2,997
5 votes
1 answer
3k views

How to write a value or variable into a file using only vimscript?

This question is very basic, but somehow absurdly difficult to find an answer for, because everything you find explains how to save the buffer, and I'm not interested in making new buffers or saving ...
Steven Lu's user avatar
  • 2,271
5 votes
2 answers
2k views

Gvim how to open several files in different buffers from MS Windows explorer

On MS Windows using gVim, is it possible to select several files from the explorer and open them in the same instance of gVim in different buffers? At the moment if I select 3 different files on ...
statox's user avatar
  • 50k
4 votes
1 answer
10k views

How to do :Sex but with a vertical split?

When viewing a file /tmp/vim_split_demo/test.txt, the parent directory can be opened in a horizontal split screen using the command :Sex, as shown in these screenshots: What command gives same ...
user1717828's user avatar
4 votes
1 answer
3k views

Find project root relative to the active buffer

I can use the finddir function to find a parent folder that contains a .git folder (project root), like this: let dir = finddir('.git/..', ';') However, this only finds project roots that are parent ...
Foobar's user avatar
  • 273
4 votes
1 answer
4k views

Is there an elegant way to determine if a file exists in/under runtimepath?

I wonder if there is an elegant way to determine if a specific file exists in/under one of the entries of &rtp. Currently, I use the following construct: let s:found_ = 0 for s:dir_ in split(&...
René Nyffenegger's user avatar
4 votes
1 answer
176 views

How do I copy the directory structure into the text of a file?

This might be more of a bash question than vim, but I thought I should start here. Frequently when editing code, it would be "nice" to copy and paste the directory structure into a text editor. For ...
ericbakes's user avatar
4 votes
1 answer
79 views

What does number+enter do in Explore?

as we know that we can use Vim to browse a directory. My question is what does number + Enter do on a file list? I thought it equivalent to number + j + Enter, however, after I enter into a file, ...
user3813057's user avatar
  • 1,471
4 votes
2 answers
279 views

Can the path include negative entries (exceptions to a wildcard)?

Is there a way to exclude specific files and directories from Vim's path? I was hoping a syntax like this would work: set path+=./**,!./ignoredirectory,!./ignoredirectory2,!./ignorefile.txt I would ...
user avatar
4 votes
0 answers
537 views

vimscript - copy a file from one path to another

How do I rewrite this line of code call system("cp /tmp/foo.txt /tmp/bar.txt") into a vim command which is more portable and OS-independent? I've been looking around but checking for "...
ColinKennedy's user avatar
4 votes
1 answer
3k views

Open files with "whitespace names" from within Vim with gx

I have a file, e.g. ~/abc def.mp3 that I want to open from within a Vim buffer that already contains these lines. If there were no whitespaces in the filename, I could simply open the file with the ...
cbaumhardt's user avatar
  • 2,139
3 votes
2 answers
247 views

Creating a list of files contained in a buffer

Let's say I have the following buffer: foo.txt bar buzz.txt fizz/foo.txt fizz/fuzz/fozz.txt Representing an arborescence that I need to create. How can I easily create it from Vim? I.e. How can I ...
statox's user avatar
  • 50k
3 votes
2 answers
2k views

A side pane file explorer that can list files by modification dates?

I am looking for a way to be able to open a side pane listing the files in the current directories where the listing is sorted by modification dates. I want to be able to open the files from the ...
Y. Pei's user avatar
  • 263
3 votes
3 answers
2k views

How to `cd` / explore the directory containing the current file?

Sometimes I gf to a file in a totally different directory and want to check out that new directory. Is there a way to quickly exit vim and cd into the directory containing the current buffer?
ChocolateOverflow's user avatar
3 votes
1 answer
8k views

What is the correct way to escape UNC paths?

Let's say there is a file \\server-42\tmp\dir\test.txt. When my plugin tries to execute this command via system() it triggers an error: cd "\\server-42\tmp\dir" && git ls-files --error-...
Andy Stewart's user avatar
  • 1,359
3 votes
3 answers
1k views

Easily add/open a file in the same folder as the current file/buffer

I feel my current VIM setup is pretty sweet, but there is one thing that annoys me time and time again: how can I open a file or add a file to the same directory as the current file I am editing? If ...
oligofren's user avatar
  • 1,103
3 votes
1 answer
136 views

How do I open the last n files I was working on in vim?

I know that the :oldfiles command will show you a history of the files you last had open; but how do I open the last n files in one command...for instance, say I want to open files 0-n in the :...
leeand00's user avatar
  • 3,589
3 votes
1 answer
68 views

Ask if file extension is missing when opening new file

I use auto completion in my shell (zsh) and I'm often a bit sloppy. Scenario: Imagine I have the files sourcecode.c and sourcecode.h in the current directory. I type vim sour<TAB><ENTER> ...
Jounathaen's user avatar
3 votes
2 answers
1k views

How to setup vim for working in a very large directory?

I am trying to setup my development environment using vim and some plugins. My workspace root is a directory with very large number of sub-directories and files. I am going to be working on files ...
Punit Soni's user avatar
3 votes
1 answer
316 views

gf: can I get next file that matches?

I use gf to open "filename.h" from line like: #include "filename.h" in some C\C++ file. Sometimes there is more than one "filename.h" that gf command can find in path. But gf gets me to the first ...
Neaţu Ovidiu Gabriel's user avatar
3 votes
1 answer
1k views

How can I get vim to include suffixes in <cfile>?

In part of a plugin I'm slowly building, I use <cfile> to get the file pointed by the word under the cursor and then do something if it points to a directory, or open the file pointed to ...
Dalker's user avatar
  • 455
3 votes
1 answer
675 views

Vim undofile does not work when file is too long

I use a vim persistent undo setup as follows, which have worked all that way here. set undofile set undodir=~/.vim/undodir However now I'm facing a problem when the undofile became too long, notice ...
intmarinoreturn0's user avatar
3 votes
1 answer
671 views

How can I securely restrict vim access to a single file?

So first, I realize that this question is slightly out of the ordinary for this site. I will explain the backstory to avoid the XY problem. Over on Programming Puzzles and Code Golf, lots of users (...
DJMcMayhem's user avatar
  • 17.6k
3 votes
0 answers
1k views

What is the file structure of Neovim?

It seems like Neovim has files in many places. The binary is in /usr/bin/nvim. Inside ~/.config/nvim is init.vim, for declaring plugins, and also directories in ~/.config for storing Neovim plugins, ...
Julius Hamilton's user avatar
3 votes
0 answers
235 views

While copying a file in netrw, why should I be in the directory where the file is located?

In netrw, I want to copy a file /dir/subdir1/file.txt to /dir/subdir2. For that, I do the following: I mark the file /dir/subdir1/file.txt I navigate up directory and mark /dir/subdir2/ as target ...
E. Anikin's user avatar
  • 131
3 votes
0 answers
339 views

Netrw problem - 'mt' open new tab instead of marking as target folder

I was playing with netrw and was amazed by the possibility. I'd like to mark some files with 'mf' and move it to a folder using 'mt'. However, when I press 't', vim seems to interprets it as "open a ...
raoul59's user avatar
  • 31