124 votes
Accepted

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

EDIT: Suggest nicely symmetric mappings for the vertical split case, since Vim by default has two mappings for the horizontal split case. There are several ways to edit the "file under cursor", and ...
  • 3,329
29 votes
Accepted

Go to last file in vim

You can use :last. See :help :last for more details. You might be interested in the other commands around it for managing files in :args as well.
  • 27.3k
27 votes
Accepted

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

Here are the relevant parts of my setup: enable the wildmenu, set wildmenu make filename-completion skip these files and directories, set wildignore+=*.swp,*.bak set wildignore+=*.pyc,*.class,*....
  • 36k
23 votes
Accepted

How to show search results for all open buffers

You can use :vimgrep /pattern/ {files} to populate the quickfix list with matching patterns. The problem is that :vimgrep files option doesn't directly allow for buffers. You can use: % Is replaced ...
  • 2,570
23 votes

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

If you are already in Vim, you can use the :argdo or :bufdo commands to execute a command on every item in the argument list or buffer list, respectively. e.g. to run a : command on every file in the ...
  • 30.1k
23 votes
Accepted

How do I reorder open tabs?

You can use the tabmove command. (:help tabmove will tell you all you need to know) The command takes two kind of parameters: A sign (+ or -) followed by a number: :tabmove +2 will move your tab of ...
  • 48.1k
18 votes

Renumbering buffer list

"the buffer numbers get crazy" Tell me about it! By the end of the day I'm easy over 100 buffers. But luckily, as you can see in this animation, you have tab completion for buffer names. So, even ...
15 votes
Accepted

How do I break a file into two?

Move the cursor to the last line of Part 1. Type Vgg to select the first part, and :w Part1.md<cr> to save that section to the first file. Press `>j, which will move the cursor to the first ...
  • 14.4k
14 votes
Accepted

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

You can use the -c argument to run a command on startup, from vim(1): -c {command} {command} will be executed after the first file has been read. {command} is ...
13 votes

How to show search results for all open buffers

Searching in only opened buffers is nice, but there may come a time where you want to search across an entire project. It can be faster and easier than you think! Searching across a project grep is ...
13 votes
Accepted

How to open multiple files matching a wildcard expression?

You can use :args {glob}. In your glob, ** will traverse directories recursively. This will populate the argument list, which is the same list that gets populated when you start Vim with one or more ...
  • 7,420
13 votes
Accepted

Navigating multiple files

The most relevant help topic is :ls, also known as :files or :buffers. In your vim debug.log* example, if you gave the :ls command, you would see: :ls 1 %a "debug.log" line ...
  • 9,119
13 votes

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

You can use bindings for this: opening in a new window (split): nnoremap gf <C-W>f vnoremap gf <C-W>f opening in a new tab: nnoremap gf <C-W>gf vnoremap gf <C-W>gf also you ...
13 votes
Accepted

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

I don't think this can be done using a single command. You'll have to use a combination of commands: As statox suggested, delete the current buffer and open a new one: :bd | e filename Or rename ...
  • 24.4k
13 votes

Open multiple files in tabs from Explore mode

From :h netrw-t: BROWSING WITH A NEW TAB netrw-t Normally one enters a file or directory using the <cr>. The "t" map allows one to open a new window holding the new directory ...
  • 48.1k
13 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 ...
  • 268
11 votes
Accepted

Why vim cannot expand wildcards from the external command?

You were close. Enclose the path pattern in single quotes instead of double quotes for the find command like so: args `find . -type f -not -path '*/\.*'` By the way, a handy way to ignore hidden ...
  • 6,156
10 votes

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

Here's a relatively simple solution: :saveas bar This solves problems #1 and #2. It doesn't address problem #3, however. Note that this still leaves the old file open in another buffer. For example,...
  • 14.4k
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
  • 3,949
9 votes
Accepted

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

I wrote a little function to repeatedly hit CTRL-O for me, until the buffer changes. You can find it here. I mapped it to CTRL-U but you could override CTRL-O if you wanted to. function! ...
  • 3,542
9 votes
Accepted

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

This function is not thoroughly tested but it should provide a good enough bootstrap for your own experiments. In ~/.vim/after/ftplugin/markdown.vim: function! s:MDGoToSection() let raw_filename ...
  • 36k
8 votes

Renumbering buffer list

According to the documentation, the buffer numbers never change Each buffer has a unique number. That number will not change, so you can always go to a specific buffer with ":buffer N" or ...
  • 1,777
8 votes

Renumbering buffer list

You can use vim-airline. This plugin has a behavior that maybe fix you problem: See line 470-479 in airline.txt This will not change the buffer numbers, but you can select a buffer from left to ...
  • 91
8 votes
Accepted

How can I search and replace within multiple files?

Let's say that you decided that you want to update the text use 5.008 to use 5.010 in multiple Perl script and Perl modules. :arg *.pl :argadd *.pm :argdo %s/use 5\.008/use 5\.010/ge | update ...
8 votes

Moving a visual range to a new tabpage?

Persisted If you intend to persist the selected lines under a new filename (and it's complete lines), you can do: :'<,'>w new-name | '<,'>delete _ | tabedit # The '<,'> range is ...
  • 17.3k
8 votes
Accepted

How to set manually the alternate file

The alternate file is stored in a register, "#. Change you line to: let @#='/path/to/alternate/file' For more help see: :h registers :h quote# :h :let-@
8 votes
Accepted

Spread already open files into split view

Here are a bunch of helpful commands for you: To open every buffer in a horizontal split: :sball To open every buffer in a vertical split: :vert sball You can do the same thing with tabs, e.g, to ...
  • 17.1k
8 votes
Accepted

Open multiple files in custom split layout

You could try it like this: vim -c "lefta vsplit file2.txt|split file1.txt" file3.txt With the option -c you can specify commands that should be executed after the first file was loaded. So ...
  • 8,927
7 votes

How to show search results for all open buffers

My GrepCommands plugin defines variants of the built-in :vimgrep command which target all arguments, listed buffers, windows in the current tab page or all tab pages for its search. Basically, a ...
  • 17.3k

Only top scored, non community-wiki answers of a minimum length are eligible