helix icon indicating copy to clipboard operation
helix copied to clipboard

Auto-save

Open onion108 opened this issue 3 years ago • 14 comments

So, hmm, I found that it's hard to write Rust on Helix, because the rust-analyzer won't give me the informations about borrow checking, ownership and many other things unless I save my file. In VSCode I can enable the auto-save so it's OK for me, but in helix I can't find a way to enable auto-save. It's really inconvenient to type <ESC> :w <Return> i after typing each line of the code. I think it's necessary for helix-editor to offer an option to enable/disable auto-save. Thanks a lot.

onion108 avatar Aug 15 '22 23:08 onion108

In the meantime, you could bind saving the file to a keybind while in insert mode. For example, you can use Ctrl-s to save while in insert mode using this binding in your config.toml (accessible via :config-open):

[keys.insert]
"C-s" = ":w"

Omnikar avatar Aug 16 '22 00:08 Omnikar

What would you want to trigger the auto-save? Some amount of idle time?

AceofSpades5757 avatar Aug 17 '22 01:08 AceofSpades5757

iirc rust-analyzer plans to add on the fly diagnostics (no idea when)

willparsons avatar Aug 17 '22 15:08 willparsons

https://github.com/helix-editor/helix/pull/3178

archseer avatar Aug 19 '22 01:08 archseer

In the meantime, you could bind saving the file to a keybind while in insert mode. For example, you can use Ctrl-s to save while in insert mode using this binding in your config.toml (accessible via :config-open):

[keys.insert]
"C-s" = ":w"

well, it looks not working for me

onion108 avatar Aug 23 '22 14:08 onion108

What would you want to trigger the auto-save? Some amount of idle time?

just like what vscode does

onion108 avatar Aug 23 '22 14:08 onion108

Some of us never used vscode so you'll have to elaborate.

archseer avatar Aug 23 '22 15:08 archseer

https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save

Looks like there are different auto save modes.

kirawi avatar Aug 23 '22 20:08 kirawi

https://code.visualstudio.com/docs/editor/codebasics#_save-auto-save

Looks like there are different auto save modes.

afterDelay, i mean

onion108 avatar Aug 24 '22 00:08 onion108

What would you want to trigger the auto-save? Some amount of idle time?

Something that worked well for me in nivm is on reentering normal mode. This means that it gets saved after basically every change.

EDIT: This also partially solves the issue of the IDE (or language server) screaming at me about an unfinished line of code while I'm writing it.

TobTobXX avatar Sep 01 '22 21:09 TobTobXX

In addition to what @TobTobXX suggested, which also was part of how I had nvim setup, I propose that also changing to a different split or buffer might be a good time to save the buffer that was moved away from.

I guess that maps closely to the vscode onFocusChange

AfoHT avatar Sep 22 '22 11:09 AfoHT

In the meantime, you could bind saving the file to a keybind while in insert mode. For example, you can use Ctrl-s to save while in insert mode using this binding in your config.toml (accessible via :config-open):

[keys.insert]
"C-s" = ":w"

well, it looks not working for me

For me, with helix 22.08.1 (66276ce6), this does work but it looks like it doesn't, because it doesn't clear the "modified" bit in the buffer list or the [+] in the status line.

However if you cat the file from another terminal you'll see your changes actually were saved.

This might be #2192.

sourcefrog avatar Nov 20 '22 18:11 sourcefrog

oh really? I'm going to have a try.

onion108 avatar Dec 01 '22 12:12 onion108

Something that worked well for me in nivm is on reentering normal mode. This means that it gets saved after basically every change.

This is problematic when using auto formatting. E.g. if you open and close a block, then enter normal mode to navigate and insert somewhere in the block, then the formatted will already have collapsed the entire block into {}.

At least a delay is necessary.

LeoniePhiline avatar Dec 07 '22 02:12 LeoniePhiline

Hurry up guys, I lost lots of records on a note about helix using helix within a broken down of a laptop.

6lj6 avatar Dec 24 '22 19:12 6lj6

Just FYI there is an autosave on focus lost setting you can turn on which will save the document when your cursor is outside the terminal(sorry if you already know about this)

[editor]
auto-save = true

gabydd avatar Dec 24 '22 19:12 gabydd

#5303 solves this

ChemicalXandco avatar Dec 31 '22 17:12 ChemicalXandco

This comment does it in a unique way: autosaving whenever pressing escape / exiting out of insert mode.

dessalines avatar Apr 13 '24 15:04 dessalines