Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

35
votes
2answers
19k 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 ...
35
votes
5answers
5k 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 ...
30
votes
4answers
29k 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.
28
votes
7answers
7k 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 ...
26
votes
2answers
2k 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 ...
15
votes
2answers
486 views

Don't touch file upon write if the file was not changed

Occasionally I absentmindedly type :w when I'm reading something. This causes the modification time of the file to change and sometimes causes my build system to unnecessarily rebuild a substantial ...
15
votes
3answers
8k 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 ...
13
votes
2answers
2k views

Does Vim autosave?

From :help swap-file: Updating the swapfile The swap file is updated after typing 200 characters or when you have not typed anything for four seconds. This only happens if the buffer was ...
12
votes
4answers
6k views

How do I edit crontab files with Vim (I get the error: 'temp file must be edited in place')

How do I edit crontab files in FreeBSD? $ crontab -e # ... I do my thing in vim & :wq "crontab.9ZcXiFaawt" 6L, 203C written crontab: temp file must be edited in place Exit 1 Using EDITOR=nvi ...
11
votes
2answers
359 views

How to make sure no changes are made to a file

Is there anyway I could make sure a file is locked so that I cant make any changes to it. Is there a command for locking / unlocking a file in vim. Some times i would like a file to be in readonly ...
11
votes
1answer
2k views

Why does the cursor move to the start of the line after <Esc>?

I've noticed while editing along a line in a .txt file in insert mode the cursor will move to the start of the line following a write using key sequence: <esc>:w I'd like to change this ...
11
votes
2answers
642 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. ...
10
votes
4answers
165 views

How do you save the file that you're working on as a new file?

There are times when I want to test changes to a file before I overwrite the original. Is there any way I can save a file being edited to a new file?
10
votes
1answer
418 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(...
9
votes
3answers
4k 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?
9
votes
1answer
359 views

Is there a way to write out the results of “:ls” to a file?

I have a bunch of splits up right now, and it took me a while to find these files (basically I'm chasing down a bug through 50 interconnected files). Is there a command like :ls > /tmp/filelist ...
9
votes
2answers
557 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 ...
8
votes
6answers
3k views

How do I save a read-only file in Vim for Windows?

I have looked for this a lot already and every answer is about Vim in Linux. Is there a way to save a read-only file right from Vim in Windows?
8
votes
3answers
347 views

Preserve creation time stamp after modification

I want to modify files with vim without changing the creation time stamps. The docs doesn't seem to mention anything about such possibility. I'd like to achieve this without turning off the swap/...
7
votes
2answers
681 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 ...
7
votes
3answers
600 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 ...
6
votes
1answer
470 views

Run bash command on writing a file with a particular extension?

I want to run a bash command on writing a .less file, saving it and generating the corresponding .css file with the same name and in the same directory. I do have the bash command which generates the ....
6
votes
2answers
611 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: ...
6
votes
2answers
470 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 ...
5
votes
2answers
570 views

How to write a file automatically after every change?

Something that helps in text editing and proofreading is that for Insert mode, I have set an IMAP: :imap zz ^[:w^M and when I type zz I return to command mode and also write the current buffer. This ...
5
votes
2answers
312 views

How can I copy the current file and start editing the copy instead of the current file?

Say I'm editing file foo. I want to copy/write what I have in the buffer to bar and change the buffer to be editing bar instead of foo. I can achieve this with: :w bar :e bar But that has a few ...
5
votes
2answers
36 views

Show time after saving a file

After saving a file in Vim, I get the message at the bottom of the screen "fileName" 92L, 3554C written. Is there a way to show the time in this message?
5
votes
1answer
1k views

Vim Error for Git Commit Message

When using vim as my default editor, I (occasionally) accidentally pull up search (e.g. via /wq instead of :wq). Once I do, I escape out of search, and then exit correctly via :wq. However, when that ...
5
votes
1answer
467 views

Why can't I execute write command on all buffers with :bufdo?

I have multiple buffers open, some currently visible, some not. I know I can write all of them with :wa. However, I am curious, why :bufdo w does not work. When I try it in a buffer with unsaved ...
5
votes
1answer
2k views

Why is vim save so slow?

When I save a file in Vim using :update or :w, Vim's entire UI blocks for about a second while it does something mysterious that (as a side effect) writes the buffer being edited to disk. This takes ...
4
votes
1answer
542 views

How to write each line into separate file?

I'd like to write content of the file into separate files each for each line. For example: Lorem ipsum dolor sit amet consectetur adipiscing elit I'd like to write 1st line into line1.txt, 2nd ...
4
votes
1answer
547 views

How to auto save file when moving between split?

I'd like to automatically save buffer after moving into another split. If you're interested why I'm interested in that read section below. I've started using vim and then neovim not so long ago, so ...
4
votes
1answer
193 views

Save/Quit Unprivileged File With Sudo

I found the following command, which saves the current file with sudo, meaning you can open a file you don't have write access to (as long as you do have read access), in the amazing Ultimate vimrc by ...
4
votes
1answer
337 views

MacVim doesn't redraw screen properly [closed]

Sometimes when I do something like saving, opening another file or another tab, the screen isn't changing states properly. At first I thought it was just my computer being slow, but then I noticed ...
3
votes
2answers
535 views

How to force quit if input was stdin?

I have q mapped to :qenter Q mapped to <esc>:qa!enter which means quit, unless something needs to be saved just quit My meanings for these keys clashes with vim's idea that stdin needs to be ...
3
votes
2answers
100 views

How to save a specific file in a different buffer?

Suppose I have several files open each in a different active buffer. Is there a way to save a specific file in a different buffer without first switching to it? An example of this occurring is if I ...
3
votes
2answers
348 views

Is there a simple way to require clean syntax before saving?

I currently use Ricardo Signes's plugin to allow me to use a single command to both check my Perl syntax and save my code only if it is syntactically correct. However, isn't there a simpler way to do ...
3
votes
1answer
185 views

How do I cut a single large file into manageable chunks by regex?

I currently have a single file that has nearly 10000 lines of text in it. Each section that I want is broken up like so - Chapter 1: Chapter 1 TEXT GOES HERE Chapter 2: Chapter 2 TEXT GOES HERE ...
3
votes
1answer
259 views

How can I open a temporary file so that I don't get E37: No write since last change?

I have a script which performs some action and then pipes the stdout to Neovim so that I can look at it with syntax highlighting and do all the other nice things I can do with vim. However, as this ...
3
votes
1answer
212 views

Suppress/bypass “file has changed” errors when editing cifs/Samba files

I have really two questions, sides of the same coin: 1) How exactly does vim evaluate whether the buffer is different from a file in order to determine the error WARNING: The file has been changed ...
3
votes
2answers
2k 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 ...
3
votes
1answer
914 views

Why does `set nocompatible` result in vim saving extra, all-numeric temporary files?

I've narrowed down a bug in a program I'm working on to (surprisingly) some vim behavior! The program contains a file watcher. When I write a file with vim -u NONE and all the default settings, the ...
3
votes
0answers
40 views

How to create intermediate directories with :w automatically? [duplicate]

It happens that you want to save a file in a subdirectory that does not exist yet, as in :w ~/customers/one-met-today/note.txt when the directory one-met-today/ does not exist. In the shell, that ...
2
votes
3answers
648 views

How to show all unsaved files opened in vim?

I'm not sure if I should ask this problem on vim or on Linux/Ubuntu forum. The thing is, I opened multiple terminals on my desktop, and several of them opened various of *.txt files. Not all of them ...
2
votes
2answers
956 views

How to map a shortcut for saving the file

Can I set something like ctrl+s to save the file? I don't want to use :w every time.
2
votes
1answer
63 views

How to make :wa overwrite externally-changed files?

I've noticed that when I have several files open in Vim, and one of the files has been changed by an external program, :wa doesn't actually try to write into that file. OTOH, going to that file and ...
2
votes
1answer
24 views

Automatically save a file that has been previously saved

I am new to vim and was wondering if there is a way for files that have already been manually saved to be automatically saved (every few seconds). I currently make a lot of new files (for testing ...
2
votes
1answer
784 views

set backupcopy=yes doesn't still writes the file twice

I'm trying to understand and eventually fix the following behavior: when I save a file using VIM, it triggers the change/write event twice. I'm using Ubuntu 16.10, and I created an empty .vimrc file ...
2
votes
0answers
33 views

Why does renaming with :saveas not open the new named file in the current buffer? [closed]

When editing a file named oldFile, with the command :saveas newFileName I expected vim to save the current buffer under the new named file (i.e. newFileName) and set the filename of the current buffer ...
2
votes
0answers
48 views

How long can a file be non-existent when I'm saving it in vim

When I'm using vim to edit files in a django application that is running in developer mode I sometimes encounter this crash coming from the auto-reload utility: File "/home/zefciu/.virtualenvs/15five/...