Questions tagged [multiple-files]

Questions about the use of vim for handling several files at the same time.

Filter by
Sorted by
Tagged with
70
votes
2answers
22k views

Open filename under cursor like gf, but in a new tab (or split)?

The normal mode command gf go to a file with the path the cursor currently is at. But it does so in the current window, replacing the current text. That means you need to navigate back explicitly ...
38
votes
5answers
6k views

Renumbering buffer list

After I've been working on a project for a while, I start to see large gaps between consecutive buffer numbers. This is because the buffers in between them were wiped out for various reasons. ...
22
votes
4answers
9k views

How to show search results for all open buffers

One thing I often do (but rely on the command line to do) is searching/grepping in multiple files. Is there a way to display search results for all the open buffers? Ideally, I'd like to have a new ...
20
votes
1answer
3k views

Go to last file in vim

Many text files can be opened at once using vim *txt I know I can use :<int>n to move forward <int> files, but I don't know how to get to the last opened file. So far I've tried :1000n ...
18
votes
1answer
2k views

How do I reorder open tabs?

Let's say I have four open files: file0.txt, file1.txt, file2.txt, and file3.txt. I open all of them in that order as tabs. So my tab ordering is this: file0.txt file1.txt file2.txt file3.txt Then ...
18
votes
4answers
5k views

Is there a way to reliably go back and forth in file history

I would like to go to the file I just edited last and next kind of like MRU plugins do. :bnext and :bprev works sometimes, but more often than not I just end up in some obscure file I don't remember ...
17
votes
2answers
5k views

How can I run a function or macro across a folder of files?

Let's say I have a function, named StripWhitespace. I can run it on a single file by opening the file and running :StripWhitespace. How can I automatically run that function against a folder of ...
13
votes
6answers
6k views

How to open multiple files matching a wildcard expression?

I want to edit several files matching a glob expression. For example, to edit all git config files in child directories, I can do this in the shell: vim */.git/config At the Vim : command line, I ...
12
votes
3answers
2k views

Efficient way to find & open files deep in a project tree?

Without plugins like ctrlp and NERDTree, what would be the most efficient way to find and open files deep in a project tree? Setting the path to **/* results in useless files in .git and other ...
11
votes
5answers
2k views

Navigating multiple files

If I open vim with multiple files on the command line, for example vim debug.log* which loads debug.log, debug.log.1 and debug.log.2, can I navigate between them, assign them to multiple windows (:...
9
votes
3answers
3k views

How to open a file from active buffer into a split window?

I have some files in my vim buffer. :ls shows the list of active buffer, I want to open a file from buffer into a vertically/horizontally split window. I know :vsp or :sp open split window in vim ...
9
votes
1answer
5k views

How to quit one file and simultaneously open another file in vim?

I am currently editing one file and, after finishing its edit, I want to close the current file and at the same time (i.e., without closing Vim) open another file for editing. How it can be achieved?...
8
votes
3answers
493 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 ...
8
votes
3answers
2k views

How can I copy the current file and start editing the copy instead of the current file?

Say I'm editing file foo. I want to copy/write what I have in the buffer to bar and change the buffer to be editing bar instead of foo. I can achieve this with: :w bar :e bar But that has a few ...
7
votes
3answers
6k views

Open multiple files in tabs from Explore mode

While navigating file system in :Explore mode, is it possible to select and open multiple files, each in a new tab? Edit: I ended up using a function proposed by Jair López, because it works pretty ...
7
votes
1answer
4k views

Why vim cannot expand wildcards from the external command?

The following command works as expected within vim: :args `find . -type f` as well as this one (with wildcard): :args `find . -name \*.inc` However when I run the following: :args `find . -type f -...
6
votes
3answers
7k views

How do I break a file into two?

I am writing some documentation (a user guide), in markdown in Vim. I now realise what I though should be one page, really should be 2. But I've already written alot of of both halves How can I split ...
6
votes
3answers
1k views

How can I open the next/previous file alphabetically?

Say I have a bunch of files, ordered alphabetically: 1.txt, 2.txt, 3.txt, etc. (In a typical situation, I have hundreds of these, ordered by date.) If I open file 2, is there a quick way for me to ...
6
votes
2answers
3k views

How to avoid "Avoid E173 (n more file(s) to edit)?"

So, when I open multiple files, but don't visit the all of them (or the last one), and I try to :quit neovim yells at me that I have to edit those files. No I don't! Stop giving me this error : ) It ...
6
votes
1answer
507 views

How to set manually the alternate file

Reading the documentation about alternate file, I thought I could manipulate # like a global variable, but it's not the case. I was thinking doing something like let &#='/path/to/alternate/file' ...
5
votes
1answer
835 views

Spread already open files into split view

Suppose I open multiple files in vim like this: vim a.cc b.cc x.cc vim will open all files, but show only one at a time, the rest being accessible using the :next command. After having these files ...
5
votes
2answers
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 ...
5
votes
0answers
3k views

How do I use wildmenu effectively?

I'd like to learn about using vim with multiple files without using external plugins. I read another answer that recommends putting the following in our .vimrc: set wildmenu set wildmode=longest:full,...
4
votes
2answers
345 views

Open multiple files in custom split layout

I want to open three files file1.txt file2.txt file3.txt in vertical and horizontal split combination, like this: +-------------------------------+ | | | | file1.txt | ...
4
votes
2answers
537 views

Open markdown filename under cursor like gf, and jump to the section?

I have the file /path/a.md which has many sections as follows: # abc this this the content of section abc # def this this the content of section abc ## defg this this the content of subsection defg ...
4
votes
1answer
1k views

How to get the names of all open buffers?

I can use % to get the name of the focused window for commands. How can I get a space-separated list of all buffers for use in a command? For example, I would like to call :!cat [all] where [all] ...
4
votes
2answers
566 views

How to search for a matching pattern only in the first line across multiple files?

How do I search in multiple files for 1st line of file matching a pattern? e.g. I want to search for files starting with ++ ++ Heading 1 and not + Heading 1 ++ Heading 2 Any pointers appreciated....
4
votes
3answers
335 views

edit many files in one buffer

I have enjoyed coding not too large projects in one single file. This way I can press * on an identifier and find it without having to hop across buffers. But naturally this doesn't scale and at some ...
4
votes
2answers
326 views

From one split, how can I get the filename of the file in another split?

I have two files open, each one is in a split. From file one, how can I get the filename of the file in split two ? In command mode, I can get the reference of the filename I'm currently editing by ...
4
votes
1answer
469 views

Using Vim gD on project with multiple folders

I am using Vim to edit Fortran 90 code. The code is structured in the following manner: ./srcs - contains main code file ./libs - contains some module file If I open the main file in Vim and then ...
3
votes
1answer
8k 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 ...
3
votes
2answers
721 views

"3 files to edit" after quit from editing multiple files in Vim

I open vim with three files: vim a.txt b.txt c.txt. Then: edit a.txt, save it by :w, switch to b.txt by :n. edit b.txt, save it by :w, switch to c.txt by :n. edit c.txt, save it by :w, and quit vim ...
3
votes
4answers
4k views

How can I overwrite a whole file with the content of another?

I have two tabs open, file1.txt and file2.txt, each with different content. How can I copy the whole content of file1.txt and overwrite file2.txt with it, resulting in both files having the same ...
3
votes
2answers
96 views

How can I easily open two similar files?

I'm trying to setup a simple environment which would allow me to work on a local file and it's remote counterpart. Both files are accessible on my filesystem. So let's say I have : File 1 : /home/...
3
votes
1answer
1k views

How can I search and replace within multiple files? [duplicate]

I have the same text that I want to replace in multiple files (say, I'm updating version numbers in multiple files). Even using the command history to reuse commands, it sure is tedious to open each ...
3
votes
1answer
101 views

How to open multiple files with cursor for all files being at the last line?

My experiments generate several log files, which I sometimes monitor manually. Some of the log files have an error message in the last line. I want to open all log files with the cursor located at ...
3
votes
1answer
61 views

Is it possible to open multiple files at the end or at the first occurrence of a string?

To open multiple files at a time I use this command (here using the vi tab feature): vim -p file1 file2 ... fileN If I want to open a file at the end or at the first occurrence of a text: vim + ...
2
votes
2answers
1k views

How to create multiple files?

While working on something like laravel, I end up creating the same view files index.blade.php, create.blade.php, show.blade.php within different folders like views/articles, views/comments, etc using ...
2
votes
1answer
1k views

Save current file and open another for editing

Is there a way to effectively combine :w and :e commands so that the current file is saved and a new one is opened for editing in one go? And to do so in a way that allows tab completion of path and ...
2
votes
1answer
653 views

Open multiple files in split mode from within Vim (not command-line)

From within an existing Vim session, I am looking for a technique to achieve the equivalent of -o file1 file2 file3. The :sp[lit] command just seems to create a single new split--it doesn't allow for ...
2
votes
1answer
52 views

Cycle between filenames

I have some files with names as below long-ordinary-filename-del-1.tex long-ordinary-filename-del-2.tex long-ordinary-filename-del-3.tex Is it possible to define a command to cycle between these ...
2
votes
1answer
578 views

Close one file during manipulate multiple files with vim

I make use of the builtins in spf13. Today when I open multiple files with vim and want to close one of them with q it closes all these files, how can I close only a few of them without closing them ...
2
votes
1answer
87 views

Open multiple files in new tabs as read only

I would like to open new tabs for each file matching an expression, each file in a new tab and as read only. I do not want to replace my current buffer, just append the new tabs. This comes very ...
2
votes
0answers
102 views

"Edit with existing Vim" - how does it work?

I have Vim 8.1.1 on Windows 7. I can click on the file with right mouse button, and there will be an option "Edit with Vim". Then, if I click another file, there will be two options: "Edit with Vim" ...
2
votes
1answer
211 views

Why does ':bufdo set fo=*' change window contents?

I have two files open, say File.h and File.m in separate tabs. ----------------------------------- | File.h | File.m | ----------------------------------- :ls reveals :ls 1 %a "...
1
vote
3answers
201 views

Can I open a file using the index shown by ":scriptnames"?

I am wondering how to open a file or load it into a buffer using the index shown by :scriptnames? 23: /usr/share/vim/vim80/plugin/tarPlugin.vim 24: /usr/share/vim/vim80/plugin/tohtml.vim 25: /usr/...
1
vote
1answer
4k views

How to split window directly from command line? [duplicate]

I'm using Ubuntu system. I have files: A.txt, B.txt, C.txt I can split window in the following way: vim A.txt :vs B.txt // after entering into vim :vs C.txt Is there any way to achieve the same ...
1
vote
3answers
735 views

Is it possible to edit the name of files by opening their root folder on Vim?

Let's say I have a folder located on ~/question with 4 files: $ ls _file1 _file2 _file3 _file4 I've realized that it's possible to open folders with Vim and it'll list the file names of all the ...
1
vote
1answer
41 views

Printing the name of all files inside the buffer inside a file

Let's say I have 10 files opened in buffer with vim *. One way of saving the name of all those files inside a new file would be using the command: :argdo !echo % >> filenames.txt This command ...
1
vote
1answer
32 views

Is there any way of editing multiple files in a buffer at once?

Let's say I have 10 files inside a folder and I open them all with vim *. All those files will be opened in the buffer. Many times when I want to edit all of them at once, I create a small macro that ...