1

I'm used to use Pycharm, which I do like for lots of features which makes it very productive especially for beginners. As I'm growing older, I use specialised tools for more and more tasks so I don't need these features anymore. At the same time I'm do like lots of features of Vim so I'm about to switch.

I'm ok with every aspect of the change except I'm missing one feature and that's writing directly to disk without the need of a save action such as keyboard shortcut, or any kind of command. If I need to save something I use git of course. I don't want to perform redundant actions when I want to save a state of something (I commit often. It's a habit. And I don't think it's a bad one).

Am I missing something?

There is already answered question here: Save file after each edit in vim but it seems to go the way of autosave-like direction.

nanoook
  • 21
  • 1
  • 6
  • 4
    If you want to write to disk (save) without any interactions (additional keyboard input) isn't that somehow *autosave*? – Jan Zeiseweis Sep 13 '17 at 11:10
  • 2
    Why the answers to the linked [question](https://stackoverflow.com/questions/9709178/save-file-after-each-edit-in-vim) don't satisfy you? In other words, why an "autosave"-like feature is not enough? (please edit your question to explain) – Basile Starynkevitch Sep 13 '17 at 11:12
  • 4
    Doesn't "saving" a file literally mean "writing to disk"? I don't quite understand what you expect to be the difference. – mkrieger1 Sep 13 '17 at 11:12
  • It seems like there is something triggered on the application level every now and then (ideally every character) rather than on filesystem level, which feels weird and brittle. But maybe it's the just feeling I should ignore. – nanoook Sep 13 '17 at 11:53

2 Answers2

0

One option that I enable in ~/.vimrc is

set autowriteall

This automatically writes to disk without explicitly saving it. Explantation at :help awa

dlmeetei
  • 9,905
  • 3
  • 31
  • 38
  • That's the 'event based' approach to it. ("on each :next, :rewind, :last, :first, :previous, :stop, :suspend, :tag, :!, :make ... " as the help says. What would be cool is I can commit immediately after edit as I do now. Without considering whether it was written to file system or not -- as I do now. – nanoook Sep 13 '17 at 13:01
  • It also does for ":edit", ":enew", ":quit", ":qall", ":exit", ":xit", ":recover" and closing the Vim window. Do you keep vim open when you commit? and how you test your code – dlmeetei Sep 13 '17 at 13:09
  • Might seem strange but I have usually about 3+ tabs of terminal opened. At least one is blocked by some running stuff with output I need to see (like docker containers or dev servers), one is for ad hoc commands like testing, and one for vim for example. (this can be done by 'screen' utility as well, but I use tabs since these are more visual and I don't forget them) – nanoook Sep 13 '17 at 13:30
  • I think there is no way without the autosave. You might like using git from within vim `vim-fugitive` – dlmeetei Sep 14 '17 at 05:18
0

My AutoSave plugin allows to designate certain buffers for automatic persistence when GVIM (and Vim in terminals that support the FocusLost event) lose focus, or optionally also when plugin passes without a keypress in Vim.

With that, you can just make your edits, switch to another application, and the changes will have been saved to the file, regardless of whether that file was currently active inside Vim.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324