Please tell me a good way to restore unsaved buffers next time, such as ATOM and Notepad++ in vim.

Asked 2 years ago, Updated 2 years ago, 55 views

Atom, Notepad++, and others have the ability to automatically open tabs (only for file buffers) from the last time you finished.

Please let me know if there is any easy way to achieve this behavior with vim.
*Actually, it's okay only for specific folders and startup methods.
 It's a topic of conversation where you want to write your work memo easily, so

I am thinking about not being able to do well with auto-save, session, etc., so I would appreciate it if you could let me know if there are any people who use it like that.

Thank you for your cooperation.

vim

2022-09-30 21:18

1 Answers

If you want to do it with Vim standard features, you can use session for that very purpose.
:mksession {file} can save the current state to a session file.
The actual state of the saved file is Vim script, which can be restored when loaded. You can start Vim while restoring the state by starting Vim, such as vim-S {file}.
The 's sessionoptions' option allows you to customize which states you want to save to the session.See :help 'sessionoptions' for more information.

If you want to save and load automatically, you can do it by writing the autocmd setting in vimrc.The following is an example of a simple configuration:(I didn't check the operation, sorry if it doesn't work well)

auto-session
  Autocmd!
  autocmd VimEnter* if argc() == 0 | source to /.session.vim | endif
  autocmd VimLeavePre*mksession~/.session.vim
group END

If you want to do something a little more elaborate, there are many plug-ins that can help you manage your session, so you might want to look for them.I think there are things like saving/loading automatically.

This is a postscript.
Sorry, I missed the title part.
You cannot restore an unsaved buffer because the session is a feature that allows you to reopen open files.
If you do something similar with Vim, I think it's better to have a memo file somewhere.In the end, you will need a real file, but I think you can't see the function of ATOM, so you can save it somewhere in a similar way.
There is also a plug-in that handles temporary notes, so you can combine them.


2022-09-30 21:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.