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.

2
  • Your question looks similar to please check this link - stackoverflow.com/questions/1708623/… Commented Sep 3, 2014 at 6:27
  • 1
    Open all files: vim *. Then, use :n to go to the next file, and :N to go to the previous file. Commented Mar 30, 2021 at 14:45

4 Answers 4

5
Sign up to request clarification or add additional context in comments.

2 Comments

Can I install it using Bundle?
@IonicăBizău: The GitHub repo for my plugin is github.com/vim-scripts/EditSimilar
4

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.

7 Comments

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.
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.
Well, I meant that I want to only have one opened buffer at the time. :-) So, is there any workaround? Maybe a macro?
Can you explain that's the meaning of <leader>? 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?
<leader> is a key that is commonly used to prefix custom keybindings. See here 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.
|
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

2 Comments

+1, but I only need simple shortcuts for doing that.
Which is exactly what I gave to you.
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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.