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.

Saving is writing a file open in Vi/Vim to a storage medium, such as a HDD or SSD. This can be done using the :write command, but often, people will use :w instead, as this saves time.

129 questions
25
votes
4 answers

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
  • 485
  • 2
  • 5
  • 8
20
votes
3 answers

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 text more text The normal w command uses lines so…
laktak
  • 2,933
  • 13
  • 27
15
votes
2 answers

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 chunk of a project. Is there a way to set vim to…
Praxeolitic
  • 2,468
  • 2
  • 15
  • 28
14
votes
4 answers

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?
Dom
  • 3,314
  • 5
  • 21
  • 38
13
votes
2 answers

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. When launch ST again all opened and edited files…
LazyS
  • 133
  • 3
11
votes
2 answers

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 mode.
Rajeshwar
  • 379
  • 1
  • 2
  • 9
11
votes
2 answers

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 happens, I see the following error message: …
hayesgm
  • 213
  • 2
  • 6
9
votes
4 answers

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 is the cause of this error. Is there anyway that I…
Mr H
  • 237
  • 2
  • 8
8
votes
3 answers

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 soon as the file changes, all by itself, before I…
Questionmark
  • 335
  • 2
  • 12
5
votes
2 answers

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?
psoo
  • 51
  • 2
5
votes
1 answer

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 since reading it!!! ...and how can I replicate…
traeki
  • 71
  • 6
4
votes
1 answer

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 executed like with ":!{cmd}", any '!' is replaced…
showkey
  • 1,130
  • 2
  • 11
  • 30
3
votes
1 answer

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 explicitly saying :w does try to actually write (I…
Ruslan
  • 475
  • 2
  • 12
3
votes
1 answer

0-length file from new :term buffer: vim -c "w! file"

I have a file mk.out that contains ANSI codes, which can be cleaned up by opening it in Vim and issuing: :term cat % " Interpret codes in new buffer :only " Close source buffer `mk.out` :w! mk.out " Overwrite `mk.out` with cleaned up…
user2153235
  • 905
  • 5
  • 14
3
votes
2 answers

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 opened 10 new files and edited them all. I want to…
domoremath
  • 285
  • 1
  • 6
1
2