2

I have the following files in directory:

" ============================================================================
" Netrw Directory Listing                                        (netrw v149) 
"   /home/.../content
"   Sorted by      name
"   Sort sequence: [\/]$,\<core\%(\.\d\+\)\=\>,\.h$,\.c$,\.cpp$,\~\=\*$,*,\.o$...
"   Quick Help: <F1>:help  -:go up dir  D:delete  R:rename  s:sort-by  x:exec
" ============================================================================
../
./
.swo
1
10-1
10-2
10-3
10-4
10-5
10-6
2
3
4
5
6
7
8-1
8-2
8-3
9-1
9-2
9-3
9-4
9-5

Having 10-2 buffer opened, how can I open for editing the next file (10-3)?

What about going back?

Right now I do :Ex and then go to the next file.

Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • Your question looks similar to please check this link - http://stackoverflow.com/questions/1708623/opening-files-in-the-same-folder-as-the-current-file-in-vim – mbaxi Sep 03 '14 at 06:27
  • Open all files: `vim *`. Then, use `:n` to go to the next file, and `:N` to go to the previous file. – Flux Mar 30 '21 at 14:45

4 Answers4

5
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
3

You can load all the files:

:args *

Then use :bn and :bp to switch.

EDIT: Okay, macro time... use these mappings:

nmap <leader>[ :Ex<CR>k<CR>
nmap <leader>] :Ex<CR>j<CR>

Note that this kind of depends on <CR> mapping from netrw, so you can't use nnoremap.

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • I only have one opened file for edit at the time. Having a lot of files loaded it not the best thing in my case. – Ionică Bizău Sep 03 '14 at 06:29
  • Unless you're doing `:bd` after each file, I assure you that is not true. :) But yeah, if you have too many files, that's probably not the best idea. – Amadan Sep 03 '14 at 06:38
  • Well, I meant that *I want to only have one opened buffer at the time*. :-) So, is there any workaround? Maybe a macro? – Ionică Bizău Sep 03 '14 at 06:41
  • Can you explain that's the meaning of ``? Actually, I know that the default is `\`, but how can I find what its value in my case? Also, what keys am I supposed to press to go to next/previous file? – Ionică Bizău Sep 04 '14 at 07:57
  • `` is a key that is commonly used to prefix custom keybindings. See [here](http://stackoverflow.com/questions/1764263/what-is-the-leader-in-a-vimrc-file) for more info. If you haven't changed your mapleader, with these keybindings, two keys: `\[` for previous and `\]` for next. But there is nothing stopping you from changing those bindings to whatever you want. – Amadan Sep 04 '14 at 08:21
  • Now the image is clearer and understand what these shortcuts do, but when I do `:Ex`, the cursor goes to the first file (not on the file that I was editing). How can I solve that? – Ionică Bizău Sep 04 '14 at 08:52
  • Hmm, not in my Vim... And I tested on multiple systems, including those with no `.vimrc`. – Amadan Sep 04 '14 at 09:25
3

You can try this mapping:

nnoremap <key> :setlocal bufhidden=wipe<CR>:edit<Space>

Action shot (the mapping is less polished but it does the same thing):

enter image description here

romainl
  • 186,200
  • 21
  • 280
  • 313
2

I think the straight forward way to go about this is to put all files that you will need while working on your project in a buffer and move to the next or the previous buffer as you see fit. For example: if you need three files at this time in your project:

file1.txt
file2.txt
file3.txt

Put all three files in the vim buffer with the following command:

vim file1.txt file2.txt file3.txt

And open each buffer as you need with :bn to get the next buffer and :bp to get the previous buffer

:bn
:bp

(Optional) You can also open a new file in a buffer while you are editing a file in vim. The command is:

:e <name of the new file>

And then you can use :bn or :bp to get to the next or previous buffer

Heapify
  • 2,581
  • 17
  • 17