56

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 while you certainly can remap gf to edit in a new tabpage as @alexander-myshov mentions, that means you have two ways to edit it in a new tabpage, but no way to ...


24

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.


23

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,*.sln,*.Master,*.csproj,*.csproj.user,*.cache,*.dll,*.pdb,*.min.* set wildignore+=*/.git/**/*,*/.hg/**/*,*/.svn/**/* set wildignore+=*/min/* set wildignore+=tags,...


18

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 argument list: :argdo StripWhitespace Or to invoke a function from every file in the buffer list: :bufdo call StripWhitespace() Or to run macro q on every ...


18

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 2 places to the right :tabmove -2 will do the same to the left. You can also use the command with a simple number to set the position of the tab: :tabmove 0 ...


15

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 with the current file name. *:_%* *c_%* # Is replaced with the alternate file name. *:_#* *c_#* #n (where n is a number) is replaced with *:...


14

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 line of Part 2. Type VG to select the second part, and :w Part2.md<cr> to save that section to the second file.


14

"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 though you can't renumber the buffers, you can still jump around easily. I don't know if it's clear from the animation but, the "tab completion" is unlike command ...


13

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 1 2 "debug.log.1" line 0 3 "debug.log.2" line 0 Press ENTER or type command to continue … indicating that the ...


10

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 files is to use :args **. But this will include folders too. I'm not completely sure why you need to enclose it in single quotes, I believe that Vim will evaluate ...


10

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


9

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 vim file explorer (which is called netrw). However, the basic command is just :Explore, and :SExplore is actually just a variant of that. The basic :Explore ...


8

Just 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 check this: :help CTRL-W_gf


8

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 the Unix standard search tool. Worth mentioning due to its ubiquity. Already integrated into Vim via :grep command. e.g. :grep -r 'foo'. See :h :grep. Ack is ...


8

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 interpreted as an Ex command. If the {command} contains spaces it must be enclosed in double quotes (this depends on the ...


8

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 note that you need to escape '.', since it it's the wildcard for one character. :arg *.pl fills the argument list with all of the files ending in .pl in the ...


8

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 inserted automatically when you enter command-line mode from visual mode. :write can take a range, and afterwards, the filename is accessible via the alternate ...


8

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 the current file and edit it: :file filename | e Use :w | bd | e filename or :w | file filename | e to save the current file and start on a new one. You can, ...


7

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 filenames as arguments. Once your argument list is populated, you can navigate through it using :next and :previous. You can also jump to the first and last ...


7

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 right by the row number in the tabline. This is my setting for airline in .vimrc: "set airline let g:airline#extensions#tabline#enabled = 1 let g:airline#...


7

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 = expand('<cfile>') let arg = substitute(raw_filename, '\([^#]*\)\(#\{1,6\}\)\([^#]*\)', '+\/\2\\\\s\3 \1', 'g') execute "edit" arg endfunction ...


7

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 open every buffer into its own tab: :bufdo tab split If you would like more control over how they get split, you can do this individually. First, list every ...


7

if all your files have a similar extension (.txt, .c, .py), place them in a folder and cd then vim *.text, vim *.c, vim *.py All the files will get added to args list, open the list by :args to see the added files. These files can be navigated using :n for next file and :N for previous. This could then be mapped to F7,F8 as so map <F7> :N<CR>,...


7

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 listing or file in a new tab. So in the netrw window simply press t when your cursor is on the file or on the directory you want to open in the new tab. To do ...


6

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 robust plugin implementation of @jecxjo's answer.


6

Vim's -o and -O options will open the files while splitting them horizontally or vertically respectively. Taken from Vim's help page :help -o and :help -O: *-o* -o[N] Open N windows, split horizontally. If [N] is not given, one window is opened for every file given as argument. If there is not enough room,...


6

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 "N CTRL-^", where N is the buffer number. The only way I can think to renumber the buffers is to restart vim.


6

In addition to the raw vim functionality mentioned by 200_success, Vim's ecosystem is full of plugins to provide extra functionality, such as: FuzzyFinder (my plugin of choice) LustyExplorer ctrlp.vim Command-T Many others, a bunch of which were mentioned in a Stack Overflow question However, before you go and start using plugins, it's best to fully ...


6

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, :w foo<cr>:saveas bar<cr>:ls<cr> will list two buffers, foo and bar.


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