Restore latest open files per project.
Hi and thank you for this great effort.
I think it could be a good feature to open latest files when we switch between projects.
Imagine i have project A and opened a.txt, b.txt, c.txt from it. They are still open and i decided to switch to another project.
When i come back to project A, i want to see the last open files.
Use <C-r> for project's oldfiles.
@gegoune Sorry? i didn't get it :)
Anyway, seems someone asked the same question.
I wrote these two functions in the past that save/load sessions:
function! LoadSession()
let lists_of_dirs = split(getcwd(), '/')
let lenght_of_dirs = len(lists_of_dirs)
let parent_directory = get(lists_of_dirs, lenght_of_dirs - 2)
let directory = get(lists_of_dirs, lenght_of_dirs - 1)
let final = parent_directory . "_" . directory
let b:sessiondir = $HOME . "/.config/nvim/sessions/"
let b:sessionfile = b:sessiondir . final . ".vim"
if (filereadable(b:sessionfile))
exe 'source ' b:sessionfile
if filereadable(".nvimrc")
exe 'source .nvimrc'
endif
else
echo "No session loaded."
endif
endfunction
function! SaveSession(overwrite)
let lists_of_dirs = split(getcwd(), '/')
let lenght_of_dirs = len(lists_of_dirs)
let parent_directory = get(lists_of_dirs, lenght_of_dirs - 2)
let directory = get(lists_of_dirs, lenght_of_dirs - 1)
let final = parent_directory . "_" . directory
let b:sessiondir = $HOME . "/.config/nvim/sessions/"
if (filewritable(b:sessiondir) != 2)
exe 'silent !mkdir -p ' b:sessiondir
redraw!
endif
let b:filename = b:sessiondir . final . '.vim'
if a:overwrite == 0 && !empty(glob(b:filename))
return
endif
exe "mksession! " . b:filename
endfunction
But i dont' know how can i integrate it with project.nvim.
I want to call: :Telescope projects and after selecting the appropriate project, call LoadSession. (Don't want to see the Find Files)
Ah, you didn't mention sessions in original post. What I meant is that instead of hitting enter to see find_files for selected project you can hit <C-r> to see oldfiles for that project.
@gegoune Good point. thank you.
About my concern, we can add an option to configs and let user choose to restore session after selecting a project or not.
If there was a to run a command on project change (ie https://github.com/ahmedkhalf/project.nvim/issues/73), then it would be possible to integrate with a session manager plugin.