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.
126
questions
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.
66
votes
2
answers
55k
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 ...
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 ...
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 ...
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 ...
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?
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 ...
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 ...
18
votes
3
answers
8k
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.
18
votes
3
answers
6k
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 ...
16
votes
2
answers
3k
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 ...
15
votes
2
answers
542
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 ...
14
votes
4
answers
1k
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?
14
votes
1
answer
4k
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 ...
13
votes
4
answers
11k
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 ...
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. ...
12
votes
1
answer
6k
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 ...
11
votes
2
answers
449
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
2
answers
6k
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 ...
11
votes
3
answers
1k
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/...
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(...
10
votes
2
answers
764
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 ...
9
votes
1
answer
6k
views
How to clang-format the current buffer on save?
Whats the best way to clang-format a C/C++/GLSL a buffer on save, that does nothing in the case there is no clang-format file found for a project?
9
votes
1
answer
472
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
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 ...
8
votes
7
answers
9k
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
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 ...
8
votes
1
answer
1k
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 ...
8
votes
1
answer
2k
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 ...
7
votes
1
answer
3k
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 ....
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:
...
7
votes
2
answers
531
views
Possible to rename file and maintain undo?
Is there a way to rename/copy/move a file and maintain the vim persistent undo information?
If I do
:w new-file-name
and then
:e new-file-name
I can't hit u to undo. Already at oldest change :-(
6
votes
2
answers
1k
views
Why can't I write to a file in the home directory?
I want to write to a file in the home directory, so I tried the following command:
:call writefile(["foo"], "~/event.log", "a")
But I got an error:
E482: Can't create ...
6
votes
2
answers
894
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 ...
6
votes
1
answer
2k
views
Saving file from INSERT mode
I would like to save files without exiting the INSERT mode. Is it possible? How?
6
votes
3
answers
1k
views
Vim not firing inotify events when writing file
Mentioned here as well: https://stackoverflow.com/questions/13312794/inotify-dont-treat-vim-editting-as-a-modification-event
Really frustrating issue, how can I force vim to write the file?
It ...
6
votes
2
answers
824
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
2
answers
1k
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 ...
5
votes
3
answers
4k
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 ...
5
votes
1
answer
902
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 ...
5
votes
2
answers
1k
views
Is there a way to write a file and skip the autocmd on write?
My .vimrc has,
autocmd FileType rust autocmd BufWritePre <buffer> call LanguageClient#textDocument_formatting_sync()
This works great, unless my LanguageClient crashes. Then I can't write the ...
5
votes
2
answers
876
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
1
answer
3k
views
How to write a value or variable into a file using only vimscript?
This question is very basic, but somehow absurdly difficult to find an answer for, because everything you find explains how to save the buffer, and I'm not interested in making new buffers or saving ...
5
votes
1
answer
2k
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 ...
5
votes
1
answer
552
views
How can I write all named buffers?
I would like a command that saves every buffer that has a filename. :h :wall gives this:
*:wa* *:wall*
:wa[ll] Write all changed buffers. Buffers without a file
...
5
votes
1
answer
1k
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 ...
5
votes
1
answer
445
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 ...
4
votes
1
answer
253
views
How to explain ++opt in :[range]w[rite] [++opt] !{cmd}?
Get manual with help:
help :w_c:
:[range]w[rite] [++opt] !{cmd}
Execute {cmd} with [range] lines as standard input
(note the space in front of the '!'). {cmd} is
...
4
votes
1
answer
398
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
1
answer
305
views
'endofline' option stays false after write operation
When one opens a file with an incomplete last line (File does not end with 0x0A / a new line character), the endofline option is set to false (:echo &endofline will print 0) and the [NOEOL] ...