Questions tagged [save]

Writing files to a persistent storage medium (usually a hard drive or SSD). In Vi, this is done with the :write command.

Filter by
Sorted by
Tagged with
7 votes
2 answers
1k views

How do I run a command on creation of a new file?

I'm aiming to make scripts I write in a certain directory (or of a certain extension) automatically executable on creation. I can do this whenever a file is written to, using the following autocmd: ...
muru's user avatar
  • 24.7k
10 votes
2 answers
767 views

Is there a way to alias `:w'` to `:w`, to avoid creating files named '?

Occasionally, my pinky will graze the ' key while reaching for enter, resulting in :w'<Enter>. I've tried: cabbrev w' :w cabbrev w\' :w cabbrev "w'" :w None of them work. Is there a way to ...
mwcz's user avatar
  • 245
59 votes
7 answers
25k views

How do I save a file in a directory that does not yet exist?

Suppose I start Vim to edit a new file in a directory that is not yet created: vim nonExisitingDirectory/newFile.txt Vim will happily show me an empty buffer and I can start writing my new file. But ...
DeltaLima's user avatar
  • 1,145
27 votes
2 answers
5k views

How to save a file for which I have no write permissions?

Sometimes it happens that I open a file and make some modifications as my own user, without noticing or "forgetting" to noticing the [read-only] warning in the status line (ie. some random /etc config ...
guido's user avatar
  • 1,747
13 votes
2 answers
982 views

Is there any vim plugin that implement hot exit feature from sublime text

Hot exit is one of killer features of Sublime Text editor. It allows to close editor at any point of time without worrying about modifications in opened files - it just closes without any question. ...
LazyS's user avatar
  • 133
8 votes
3 answers
2k views

How can I have vim automatically notify me when a file that I am editing changes?

I have a situation where sometimes my friend and I are working in the same file at the same time. Vim will tell me if the file has changed when I try to overwrite it. Can I have vim notify me as ...
Questionmark's user avatar
71 votes
6 answers
106k views

How can I rename the file I'm editing?

Is it possible to rename the file I'm editing from within Vim? Currently what I do is exit Vim, rename the file and open from Vim again.
thameera's user avatar
  • 17k
66 votes
2 answers
56k views

What are the differences between :wq<cr> :x<cr> and ZZ when exiting vim?

Vi and Vim, as all of you know, have many synonyms. There are three ways I know of to save the file and exit Vim and Vi. These are :wq <cr>, :x <cr> and ZZ. I have heard that these are ...
wefwefa3's user avatar
  • 1,143
45 votes
10 answers
20k views

Is it possible to make Vim auto-save files?

Some word processors and text editors auto-save the files we're editing from time to time, which is very convenient for surviving from nasty crashes, etc. Is there a way to make Vim auto-save our ...
thameera's user avatar
  • 17k
25 votes
4 answers
17k views

Don't add new line at the end of a file

Vim always adds a new line at the end of my files when saving, and it is causing errors in my PHP scripts. How can I make vim not add this new line on save?
Dan's user avatar
  • 485
22 votes
3 answers
20k views

How to make vim automatically add a newline to the end of a file?

Vim normally writes <EOL> for the last line only when there was one in the original file. How to make vim to write a new line at the end of a file all the time (when the file is not binary and ...
kenorb's user avatar
  • 18.2k
20 votes
3 answers
7k views

Write selected area to file

I'd like to write a visually selected area to a file. For example: prefix [sample text more text] suffix [] is the selected block which should be taken, resulting in a new file containing: sample ...
laktak's user avatar
  • 2,898
10 votes
1 answer
832 views

How can I stop Vim from writing a file without throwing an error?

I'm trying to improve the code from this answer to ask for confirmation before creating the missing directory, this is what I write: function! CreateDirectoryAskConfirmation(path) if !isdirectory(...
toro2k's user avatar
  • 4,822
9 votes
4 answers
7k views

How to bypass "The file has been changed since reading it"?

When I try to save a file I get the attached error almost every time. I haven't opened or modified the file in different editor. This is for Elixir files, and the code get compiled. Not sure if that ...
Mr H's user avatar
  • 237
6 votes
2 answers
827 views

No Vim, I don't want to save changes to a directory

I frequently use :e. to navigate folders and open files in gVim. But later, when I try to close the session with a :qall, I am asked by vim whether or not I want to save changes to the folder(s) I ...
Jeff's user avatar
  • 193
1 vote
1 answer
236 views

BufLeave: Auto save split file not working

I usually keep *.in files open in split and edit them. I would like vim to autosave the *.in files whenever I switch between splits. Searching other answers I found BufLeave that suits my case. I ...
mtk's user avatar
  • 233
1 vote
1 answer
1k views

How to avoid "file has changed" warning when writing buffer?

I am using system() to change a buffer's file. I apply the same change to the buffer itself. I can't just reload the buffer because there are other unsaved changes. When I come to write the buffer, ...
Andy Stewart's user avatar
  • 1,319
1 vote
1 answer
369 views

Autosave and Nerdtree conflicts

I was trying to setup NeoVim to autosave each time a change is made. I used this command, which I wrote in ~/.config/nvim/init.vim: autocmd TextChanged, TextChangedI * silent write It works perfectly ...
deomanu01's user avatar
  • 119