Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to navigate the opened files in vim?

Tags:

linux

vim

I opened a files in vim using

gf

command.which opened a file that the current cursor position.

I used

ctrl + ^

is used to toggle between the last two opened files. But, How can i go forward and backward opened the files?

like image 540
sat Avatar asked Oct 26 '25 17:10

sat


2 Answers

:bn & :bp to cycle buffers

To cycle windows I use ctrl+w+w

To cycle opened file :next & :prev

To list opened buffers: :ls

from good old vi :e# reopens previous file ^^ (not using it since ages... well since VIM comes to my systems ^^)

EDIT: a quick test on gvim in windows (set nocp)

map <C-tab> ^[:bn^M

in order to enter escape (^[) and enter (^M) you have to press ctrl+v and then the special char

EDIT 2: a cleaner way to do this is putting this in .vimrc

map <C-tab> <esc>:bn<cr>

but just remember that using mnemonics for the keys depends on some other options (I cannot remember which one).

The best way is IMHO to write a VIM function saving the actual mode, performing switch and then restoring it, then mapping it to in every mode (:[xxx]map commands)

like image 147
BigMike Avatar answered Oct 28 '25 07:10

BigMike


:next to next file :prev to previous file

like image 28
Jayan Avatar answered Oct 28 '25 07:10

Jayan