File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff line change @@ -124,21 +124,21 @@ function M.gitBlameOpenCommitFileURL()
124124end
125125
126126-- alternate-file or last edited file
127- -- `CTRL-^` for alternate-file
128- -- `'0` for last edited file
129- -- BUG: sometimes does not work when opening last edited file
130127function M .altFileOrOldFile ()
131128 local status_ok , _ = pcall (vim .cmd , ' e#' )
132129 if not status_ok then
133- vim .cmd ([[ norm '0]] )
134- local current_buf_name = vim .api .nvim_buf_get_name (0 )
135- vim .cmd (' bp' )
136- local prev_current_buf_name = vim .api .nvim_buf_get_name (0 )
137- if prev_current_buf_name == ' ' then
138- vim .cmd (' bd' )
139- elseif current_buf_name == prev_current_buf_name then
140- vim .cmd (' e#<2' )
130+ -- No alternate file, try oldfiles
131+ local oldfiles = vim .v .oldfiles
132+ local current_file = vim .api .nvim_buf_get_name (0 )
133+ -- Find first oldfile that's not the current file
134+ for _ , old_file in ipairs (oldfiles ) do
135+ if old_file ~= current_file and vim .fn .filereadable (old_file ) == 1 then
136+ vim .cmd (' edit ' .. vim .fn .fnameescape (old_file ))
137+ return
138+ end
141139 end
140+ -- If no oldfile found, just notify
141+ vim .notify (' No previous file to open' , vim .log .levels .INFO )
142142 end
143143end
144144
You can’t perform that action at this time.
0 commit comments