tags:

views:

355

answers:

3

I'm losing all previous buffers when by mistake I'm trying to switch behind the last buffer [n:].

If for example I open couple of files in editor

:ls
  1 #    "/etc/moduli"                  line 1
  2 %a   "/etc/motd"                    line 1

:n
E163: There is only one file to edit

:p
E163: There is only one file to edit

now i can navigate between tabs just using :b [number]

Please advice how to fix this behavior. How can I prevent buffers from closing in this case?

+4  A: 

I think you're confusing something there. A buffer is something like an open file. When you switch to the next file in the argument list using :n you close the current buffer and open the next one, so the changes must either be saved or discarded at this point.

Additionally the default behaviour of vim is to display an error message if you try to go beyond the last file in your argument list, so losing anything is not very easy in vim.

Maybe describing your actions (pressed keys) could help here, if this does not answer your question.

[edit]

Ok, now I know what the problem is: There is a difference between a buffer and the list of files to edit that you supply when starting vim. If you start vim with

vim a.txt b.txt

there are 2 files to edit. This does not mean, there are multiple buffers. You can navigate using :n and :p (meaning n(ext) file and p(revious) file). If you have the global flag :hidden set, this means that every buffer you close will become a hidden buffer. The file is still being edited, but it is not shown in any window. This value is possibly set upon startup of vim in your system. Try adding :se nohidden to your .vimrc and try the following:

:help buffer-hidden

[/edit]

soulmerge
+2  A: 

:n and :p doesn't switch between buffers :)

try :bufnext and :bufprev

maybe you'll like:

nmap <LEADER>k :bnext<CR>:redraw<CR>
nmap <LEADER>j :bprevious<CR>:redraw<CR>
nmap <LEADER>d :bd<CR>
nnoremap <LEADER>b :buffers<CR>:buffer<space>

Press ,j for the previous buffer, ,k for the next buffer, ,d to close the current buffer and ,b to list your buffers and select one with number keys.

tiax
+2  A: 
:bn

will display the next file in your buffer (in your case "/etc/moduli")

:bp

will display the previous file in your buffer (also "/etc/moduli" because it does a permutation)

One thing that you'll notice is that the file you're editing is marked with

%a

whereas

#

means it's the last file you displayed. Hope it helps you.

Taurus Olson