Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #1023 - Go to alternate file or next file if no alternate

Created: October 23, 2005 6:15 Complexity: intermediate Author: Yakov Lerner Version: 6.0 Karma: 2/2 Imported from: Tip#1023

" Ctrl-^ is very handy command in the normal mode. Ctrl-^

" switches to "alternate file". When there is no "alternate file",

" I wanted Ctrl-^ to jump to next file in the list.

" Insert following commands into your ~/.vimrc , then

" Ctrl-^ will be enhanced so that when there is no alternate file

" but there is next file, it will jump to the next file.


"  : next

else 
:exe "normal! \<c-^>" 
endif 

endfu

map <C-^> :call MySwitch()<cr>

" my remapping of <C-^>.

Comments

Fix: replace 'next' with 'silent! next' to suppress error message when there is only 1 file.

Change this line:

if expand('#')=="" | : next 

to this:

if expand('#')=="" | silent! next 

Yakov Lerner


jilerner--AT--yahoo.com , October 24, 2005 4:14


Advertisement