How to autosave all files periodicatlly in Vim? - vim

I was using gedit for a while and now I am using vim . There was a nice option of autosave in gedit . I want to know if there is an option of autosaving in vim. I want to save my codes which I am writing after every 1 minute because of the disruption of electricity.

You can use the vim-auto-save script to save files every time their buffers are modified.

Related

How to track Vim open and close time?

I want to keep a track of when I open or close Vim. Does Vim store its start time anywhere? Or tracking Vim start time from bash_history is a better approach? For example, if I open five times a day, I want to save the different times at which I have opened vim.
Thanks
If you just want to track time using for a Vim session, the simple solution is using GNU time, i.e time vim some_file.txt.
Or a more flexible way is using Vim script. For example, add this line in your .vimrc
let g:start_time = strftime('%c')
and then in a vim session
:echo g:start_time

How to open automatically specific file in Vim when I open any other file?

Because I do not use Vim intensively every day, I tend to forget some of the useful Vim tips I found here and there (mostly on SO).
So I decided to store them in a .txt file. Cheatsheet, sort of.
But now I would like to have this file loaded (in tab 2), whenever I open any other file (in tab 1), in order to peek for a solution, if needed.
I know how to launch 2 specific files together, but not a specific file automatically with an undetermined one.
How should I proceed ?
You could use an autocommand:
autocmd BufNewFile,BufRead * tabf ~/Cheatsheet.txt
This will open ~/Cheatsheet.txt every time you open a file in vim

Sync vim and a regular text editor

I usually prefer to write my website's paragraphs in LibreOffice. After finishing, I have to copy and paste the text to vim. I would prefer to keep "connected" this two editors, so what I write in LibreOffice is also in vim.
Is there any way to sync contents?
Solutions using Latex are also welcomed, since it is more hackable..
Add set autoread in your .vimrc. Then open the file both in vim and libreoffice, and vim will automatically reload the file if it detects changes.
BTW, if you are missing automatic line filling in vim, look at the formatoptions variable.

How do I cancel a paste operation in Vim?

I had rather a lot of text on my clipboard whenever I accidentally right clicked inside Putty (with Vim open), and Vim has initiated a paste operation which has been going for around ten minutes now.
I don't want to lose my unsaved work, is there a way to instruct Vim to stop pasting text?
If you're in normal mode, Ctrl-C aborts the current command in progress. Then press u to undo anything that changed before you stopped it.
Depending os your vim configuration, there's chances that you have a swap file (backup) in .nameOfTheOpenedFile.swp (substitute nameOfTheOpenedFile with the name for your file).
To recover the file :
vim -r .nameOfTheOpenedFile.swp
I know this is really old but the top answer is not right and I was clearly having a similar issue to OP. (accidentally pasted like a million lines of json into vim)
Keep in mind this may not allow you to save your work (but you can probably salvage something from the .swp file)
All you need to do is open a new terminal window and enter pkill vim into the command line.

How to save the files opened in all windows and tabs in Vim?

I’d like to save the files opened in all vertical/horizontal windows? Is it possible without going to each window and executing the :w! command?
To save only those buffers that opened in the current tab page and not
those that are hidden, run the :write command for every open window:
:windo w!
In order to save all open buffers regardless of the corresponding
windows’ locations, run the :wall command:
:wa!
There is also a similar command
:bufdo w!
but it does not behave in quite the same fashion. Both commands affect
hidden buffers, but :wall does not attempt to write the buffers
that do not have a file name set.
Yes, you can do this with :wa.
Use :wall
It writes all changed buffers (but it will also save the hidden one).

Resources