How can I recover the original file from a .swp file?
I tried opening the .swp file using vi
and cat
but it displays junk.
ubuntu vim
add a comment |
I tried opening the .swp file using vi
and cat
but it displays junk.
ubuntu vim
Are you using vi or vim?
– frabjous
Oct 28 '10 at 15:13
add a comment |
I tried opening the .swp file using vi
and cat
but it displays junk.
ubuntu vim
I tried opening the .swp file using vi
and cat
but it displays junk.
ubuntu vim
ubuntu vim
edited Oct 28 '10 at 7:34
Ignacio Vazquez-Abrams
96k6155211
96k6155211
asked Oct 28 '10 at 7:32
zarnazarna
351133
351133
Are you using vi or vim?
– frabjous
Oct 28 '10 at 15:13
add a comment |
Are you using vi or vim?
– frabjous
Oct 28 '10 at 15:13
Are you using vi or vim?
– frabjous
Oct 28 '10 at 15:13
Are you using vi or vim?
– frabjous
Oct 28 '10 at 15:13
add a comment |
5 Answers
5
active
oldest
votes
vim -r .swp
This goes into recovery mode and gives you more info. I think this is what you want.
.swX
-files are left behind if a session with an unsaved file is killed/crashes/something else bad happens. They are also present during the time an unsaved buffer is open in a Vim session. vim -r
reads these temporary files and recreates the content. After you've recovered it, just save it as usual, e.g. :w newfilename
.
4
Precisely what I was looking for. For anyone else, this is how you recover as-of-yet unsaved files. The above methods work fine if a file already exists, but you can't open a file with no name.
– Eric Hu
Jan 18 '12 at 23:22
add a comment |
You don't need to have the original file to recover the .swp. Just open the file as if it exists. vim will look for the file with the .swp extension and offer to recover it.
e.g.:
$ ls -a
. .. .test.txt.swp
$ vim test.txt
[...]
Swap file ".test.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
Just press R to recover it and :wq the file
Edit:
Note that the .swp file only contains the changes done to the file (see comment). This means that you will need to fetch a recent copy of the file from backup and then use vim to recover the latest changes. If you don't have a backup copy of the file you're really out of luck.
2
You definitely have to have the original file, without it the data in the .swp file is useless. See ":help swap-file". There are situations where it may appear to work without the original file, but the .swp file only stores change information and requires some starting point to apply that information during recovery.
– Heptite
Oct 28 '10 at 17:57
You are right, of course. I actually didn't know this about vim. But it is only logical as storing a complete copy of the original file would be a huge waste. Then the answer is: Recover your file from backup, then use vim to recover the latest modifications.
– Vegar Westerlund
Nov 2 '10 at 9:27
Storing the entire file in a single swp would be wasteful, yes, but I see potential value in accumulating swp files (when enabled.) For the same reason you edit via diff and patch the original only on explicit save, it makes sense to me if you could stage a sequence of diffs, generate a partial sum (dates before today -> nightly; nightly + today = current) etc. I found ':pre[serve]` in the manuel, I think it works that way. In any case, the most important line is:The original file is no longer needed for recovery.
– John P
Aug 1 '17 at 15:15
Looks like it works -:preserve
and:set cpoptions=...&
leaves a .swp and .swo file in the directory and offers to recover from either. Usingvim -r <file>
you can choose between .swp and .swo. Further edits generate .swn, .swm, etc., which appear to be the partial sum of swaps up to that point. You can revert to the version of your liking and edit (~=fork) or save (~=stash). Eventually you can tar up the swap files, daemonize their backups, etc. I could be wrong about the details when it comes to larger files - I'm not sure how that affects the extra swap files either - see below.
– John P
Aug 1 '17 at 16:02
(Continued) - the buffer carries the flags and it's the buffer that produces the swap files, so even if the flags aren't set from global configuration or autoload, they are inherited during recovery itself. To replace a recovery sequence with a single recovery file, you can move the swap you want to .swp and hide the rest. I'd love to know more about the overlap between file recovery and Vim session management if anyone can fill in the gaps.
– John P
Aug 1 '17 at 16:09
add a comment |
Open the original file using vim, and choose the recovery option.
I don't have the original file.I just have it's '.swp'
– zarna
Oct 28 '10 at 7:36
1
That's less important than you think. Open it regardless.
– Ignacio Vazquez-Abrams
Oct 28 '10 at 7:40
add a comment |
1 Open the swap file .file.swp
in vim
2 :recover
will recover your file
add a comment |
After reading Vegar Westerlund and Heptite comments, I wanted to know at what point vim needs the original file (or a backup) to recover from a .swp file. Here's what did:
I opened a 975 lines file, edited it on line 949 (creating a .swp
file) and killed the process, then deleted the original. $ vim Original_File
asked if I wanted to recover from the .swp » > yes; only the first 68 lines and the last 34 lines (starting 8 lines above my edit) were actually recovered.
I then repeated the test with smaller files: From 20 up to 200 lines, the .swp file contained 100% of the original content. But at 300 lines, only the first 68 and the 18 last lines (starting 2 lines above my edit) were included in the .swp.
As a conclusion it's good to know that vim always save the file's "header" and "bottom" in the .swp files. Maybe there's a setting to control how much lines should a .swp contains?
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f204209%2fhow-can-i-recover-the-original-file-from-a-swp-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
vim -r .swp
This goes into recovery mode and gives you more info. I think this is what you want.
.swX
-files are left behind if a session with an unsaved file is killed/crashes/something else bad happens. They are also present during the time an unsaved buffer is open in a Vim session. vim -r
reads these temporary files and recreates the content. After you've recovered it, just save it as usual, e.g. :w newfilename
.
4
Precisely what I was looking for. For anyone else, this is how you recover as-of-yet unsaved files. The above methods work fine if a file already exists, but you can't open a file with no name.
– Eric Hu
Jan 18 '12 at 23:22
add a comment |
vim -r .swp
This goes into recovery mode and gives you more info. I think this is what you want.
.swX
-files are left behind if a session with an unsaved file is killed/crashes/something else bad happens. They are also present during the time an unsaved buffer is open in a Vim session. vim -r
reads these temporary files and recreates the content. After you've recovered it, just save it as usual, e.g. :w newfilename
.
4
Precisely what I was looking for. For anyone else, this is how you recover as-of-yet unsaved files. The above methods work fine if a file already exists, but you can't open a file with no name.
– Eric Hu
Jan 18 '12 at 23:22
add a comment |
vim -r .swp
This goes into recovery mode and gives you more info. I think this is what you want.
.swX
-files are left behind if a session with an unsaved file is killed/crashes/something else bad happens. They are also present during the time an unsaved buffer is open in a Vim session. vim -r
reads these temporary files and recreates the content. After you've recovered it, just save it as usual, e.g. :w newfilename
.
vim -r .swp
This goes into recovery mode and gives you more info. I think this is what you want.
.swX
-files are left behind if a session with an unsaved file is killed/crashes/something else bad happens. They are also present during the time an unsaved buffer is open in a Vim session. vim -r
reads these temporary files and recreates the content. After you've recovered it, just save it as usual, e.g. :w newfilename
.
edited Apr 26 '12 at 12:46
answered Oct 30 '10 at 10:33
Daniel AnderssonDaniel Andersson
19.3k34056
19.3k34056
4
Precisely what I was looking for. For anyone else, this is how you recover as-of-yet unsaved files. The above methods work fine if a file already exists, but you can't open a file with no name.
– Eric Hu
Jan 18 '12 at 23:22
add a comment |
4
Precisely what I was looking for. For anyone else, this is how you recover as-of-yet unsaved files. The above methods work fine if a file already exists, but you can't open a file with no name.
– Eric Hu
Jan 18 '12 at 23:22
4
4
Precisely what I was looking for. For anyone else, this is how you recover as-of-yet unsaved files. The above methods work fine if a file already exists, but you can't open a file with no name.
– Eric Hu
Jan 18 '12 at 23:22
Precisely what I was looking for. For anyone else, this is how you recover as-of-yet unsaved files. The above methods work fine if a file already exists, but you can't open a file with no name.
– Eric Hu
Jan 18 '12 at 23:22
add a comment |
You don't need to have the original file to recover the .swp. Just open the file as if it exists. vim will look for the file with the .swp extension and offer to recover it.
e.g.:
$ ls -a
. .. .test.txt.swp
$ vim test.txt
[...]
Swap file ".test.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
Just press R to recover it and :wq the file
Edit:
Note that the .swp file only contains the changes done to the file (see comment). This means that you will need to fetch a recent copy of the file from backup and then use vim to recover the latest changes. If you don't have a backup copy of the file you're really out of luck.
2
You definitely have to have the original file, without it the data in the .swp file is useless. See ":help swap-file". There are situations where it may appear to work without the original file, but the .swp file only stores change information and requires some starting point to apply that information during recovery.
– Heptite
Oct 28 '10 at 17:57
You are right, of course. I actually didn't know this about vim. But it is only logical as storing a complete copy of the original file would be a huge waste. Then the answer is: Recover your file from backup, then use vim to recover the latest modifications.
– Vegar Westerlund
Nov 2 '10 at 9:27
Storing the entire file in a single swp would be wasteful, yes, but I see potential value in accumulating swp files (when enabled.) For the same reason you edit via diff and patch the original only on explicit save, it makes sense to me if you could stage a sequence of diffs, generate a partial sum (dates before today -> nightly; nightly + today = current) etc. I found ':pre[serve]` in the manuel, I think it works that way. In any case, the most important line is:The original file is no longer needed for recovery.
– John P
Aug 1 '17 at 15:15
Looks like it works -:preserve
and:set cpoptions=...&
leaves a .swp and .swo file in the directory and offers to recover from either. Usingvim -r <file>
you can choose between .swp and .swo. Further edits generate .swn, .swm, etc., which appear to be the partial sum of swaps up to that point. You can revert to the version of your liking and edit (~=fork) or save (~=stash). Eventually you can tar up the swap files, daemonize their backups, etc. I could be wrong about the details when it comes to larger files - I'm not sure how that affects the extra swap files either - see below.
– John P
Aug 1 '17 at 16:02
(Continued) - the buffer carries the flags and it's the buffer that produces the swap files, so even if the flags aren't set from global configuration or autoload, they are inherited during recovery itself. To replace a recovery sequence with a single recovery file, you can move the swap you want to .swp and hide the rest. I'd love to know more about the overlap between file recovery and Vim session management if anyone can fill in the gaps.
– John P
Aug 1 '17 at 16:09
add a comment |
You don't need to have the original file to recover the .swp. Just open the file as if it exists. vim will look for the file with the .swp extension and offer to recover it.
e.g.:
$ ls -a
. .. .test.txt.swp
$ vim test.txt
[...]
Swap file ".test.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
Just press R to recover it and :wq the file
Edit:
Note that the .swp file only contains the changes done to the file (see comment). This means that you will need to fetch a recent copy of the file from backup and then use vim to recover the latest changes. If you don't have a backup copy of the file you're really out of luck.
2
You definitely have to have the original file, without it the data in the .swp file is useless. See ":help swap-file". There are situations where it may appear to work without the original file, but the .swp file only stores change information and requires some starting point to apply that information during recovery.
– Heptite
Oct 28 '10 at 17:57
You are right, of course. I actually didn't know this about vim. But it is only logical as storing a complete copy of the original file would be a huge waste. Then the answer is: Recover your file from backup, then use vim to recover the latest modifications.
– Vegar Westerlund
Nov 2 '10 at 9:27
Storing the entire file in a single swp would be wasteful, yes, but I see potential value in accumulating swp files (when enabled.) For the same reason you edit via diff and patch the original only on explicit save, it makes sense to me if you could stage a sequence of diffs, generate a partial sum (dates before today -> nightly; nightly + today = current) etc. I found ':pre[serve]` in the manuel, I think it works that way. In any case, the most important line is:The original file is no longer needed for recovery.
– John P
Aug 1 '17 at 15:15
Looks like it works -:preserve
and:set cpoptions=...&
leaves a .swp and .swo file in the directory and offers to recover from either. Usingvim -r <file>
you can choose between .swp and .swo. Further edits generate .swn, .swm, etc., which appear to be the partial sum of swaps up to that point. You can revert to the version of your liking and edit (~=fork) or save (~=stash). Eventually you can tar up the swap files, daemonize their backups, etc. I could be wrong about the details when it comes to larger files - I'm not sure how that affects the extra swap files either - see below.
– John P
Aug 1 '17 at 16:02
(Continued) - the buffer carries the flags and it's the buffer that produces the swap files, so even if the flags aren't set from global configuration or autoload, they are inherited during recovery itself. To replace a recovery sequence with a single recovery file, you can move the swap you want to .swp and hide the rest. I'd love to know more about the overlap between file recovery and Vim session management if anyone can fill in the gaps.
– John P
Aug 1 '17 at 16:09
add a comment |
You don't need to have the original file to recover the .swp. Just open the file as if it exists. vim will look for the file with the .swp extension and offer to recover it.
e.g.:
$ ls -a
. .. .test.txt.swp
$ vim test.txt
[...]
Swap file ".test.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
Just press R to recover it and :wq the file
Edit:
Note that the .swp file only contains the changes done to the file (see comment). This means that you will need to fetch a recent copy of the file from backup and then use vim to recover the latest changes. If you don't have a backup copy of the file you're really out of luck.
You don't need to have the original file to recover the .swp. Just open the file as if it exists. vim will look for the file with the .swp extension and offer to recover it.
e.g.:
$ ls -a
. .. .test.txt.swp
$ vim test.txt
[...]
Swap file ".test.txt.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort:
Just press R to recover it and :wq the file
Edit:
Note that the .swp file only contains the changes done to the file (see comment). This means that you will need to fetch a recent copy of the file from backup and then use vim to recover the latest changes. If you don't have a backup copy of the file you're really out of luck.
edited Jan 18 at 11:32
DaniGuardiola
1033
1033
answered Oct 28 '10 at 7:41
Vegar WesterlundVegar Westerlund
27316
27316
2
You definitely have to have the original file, without it the data in the .swp file is useless. See ":help swap-file". There are situations where it may appear to work without the original file, but the .swp file only stores change information and requires some starting point to apply that information during recovery.
– Heptite
Oct 28 '10 at 17:57
You are right, of course. I actually didn't know this about vim. But it is only logical as storing a complete copy of the original file would be a huge waste. Then the answer is: Recover your file from backup, then use vim to recover the latest modifications.
– Vegar Westerlund
Nov 2 '10 at 9:27
Storing the entire file in a single swp would be wasteful, yes, but I see potential value in accumulating swp files (when enabled.) For the same reason you edit via diff and patch the original only on explicit save, it makes sense to me if you could stage a sequence of diffs, generate a partial sum (dates before today -> nightly; nightly + today = current) etc. I found ':pre[serve]` in the manuel, I think it works that way. In any case, the most important line is:The original file is no longer needed for recovery.
– John P
Aug 1 '17 at 15:15
Looks like it works -:preserve
and:set cpoptions=...&
leaves a .swp and .swo file in the directory and offers to recover from either. Usingvim -r <file>
you can choose between .swp and .swo. Further edits generate .swn, .swm, etc., which appear to be the partial sum of swaps up to that point. You can revert to the version of your liking and edit (~=fork) or save (~=stash). Eventually you can tar up the swap files, daemonize their backups, etc. I could be wrong about the details when it comes to larger files - I'm not sure how that affects the extra swap files either - see below.
– John P
Aug 1 '17 at 16:02
(Continued) - the buffer carries the flags and it's the buffer that produces the swap files, so even if the flags aren't set from global configuration or autoload, they are inherited during recovery itself. To replace a recovery sequence with a single recovery file, you can move the swap you want to .swp and hide the rest. I'd love to know more about the overlap between file recovery and Vim session management if anyone can fill in the gaps.
– John P
Aug 1 '17 at 16:09
add a comment |
2
You definitely have to have the original file, without it the data in the .swp file is useless. See ":help swap-file". There are situations where it may appear to work without the original file, but the .swp file only stores change information and requires some starting point to apply that information during recovery.
– Heptite
Oct 28 '10 at 17:57
You are right, of course. I actually didn't know this about vim. But it is only logical as storing a complete copy of the original file would be a huge waste. Then the answer is: Recover your file from backup, then use vim to recover the latest modifications.
– Vegar Westerlund
Nov 2 '10 at 9:27
Storing the entire file in a single swp would be wasteful, yes, but I see potential value in accumulating swp files (when enabled.) For the same reason you edit via diff and patch the original only on explicit save, it makes sense to me if you could stage a sequence of diffs, generate a partial sum (dates before today -> nightly; nightly + today = current) etc. I found ':pre[serve]` in the manuel, I think it works that way. In any case, the most important line is:The original file is no longer needed for recovery.
– John P
Aug 1 '17 at 15:15
Looks like it works -:preserve
and:set cpoptions=...&
leaves a .swp and .swo file in the directory and offers to recover from either. Usingvim -r <file>
you can choose between .swp and .swo. Further edits generate .swn, .swm, etc., which appear to be the partial sum of swaps up to that point. You can revert to the version of your liking and edit (~=fork) or save (~=stash). Eventually you can tar up the swap files, daemonize their backups, etc. I could be wrong about the details when it comes to larger files - I'm not sure how that affects the extra swap files either - see below.
– John P
Aug 1 '17 at 16:02
(Continued) - the buffer carries the flags and it's the buffer that produces the swap files, so even if the flags aren't set from global configuration or autoload, they are inherited during recovery itself. To replace a recovery sequence with a single recovery file, you can move the swap you want to .swp and hide the rest. I'd love to know more about the overlap between file recovery and Vim session management if anyone can fill in the gaps.
– John P
Aug 1 '17 at 16:09
2
2
You definitely have to have the original file, without it the data in the .swp file is useless. See ":help swap-file". There are situations where it may appear to work without the original file, but the .swp file only stores change information and requires some starting point to apply that information during recovery.
– Heptite
Oct 28 '10 at 17:57
You definitely have to have the original file, without it the data in the .swp file is useless. See ":help swap-file". There are situations where it may appear to work without the original file, but the .swp file only stores change information and requires some starting point to apply that information during recovery.
– Heptite
Oct 28 '10 at 17:57
You are right, of course. I actually didn't know this about vim. But it is only logical as storing a complete copy of the original file would be a huge waste. Then the answer is: Recover your file from backup, then use vim to recover the latest modifications.
– Vegar Westerlund
Nov 2 '10 at 9:27
You are right, of course. I actually didn't know this about vim. But it is only logical as storing a complete copy of the original file would be a huge waste. Then the answer is: Recover your file from backup, then use vim to recover the latest modifications.
– Vegar Westerlund
Nov 2 '10 at 9:27
Storing the entire file in a single swp would be wasteful, yes, but I see potential value in accumulating swp files (when enabled.) For the same reason you edit via diff and patch the original only on explicit save, it makes sense to me if you could stage a sequence of diffs, generate a partial sum (dates before today -> nightly; nightly + today = current) etc. I found ':pre[serve]` in the manuel, I think it works that way. In any case, the most important line is:
The original file is no longer needed for recovery.
– John P
Aug 1 '17 at 15:15
Storing the entire file in a single swp would be wasteful, yes, but I see potential value in accumulating swp files (when enabled.) For the same reason you edit via diff and patch the original only on explicit save, it makes sense to me if you could stage a sequence of diffs, generate a partial sum (dates before today -> nightly; nightly + today = current) etc. I found ':pre[serve]` in the manuel, I think it works that way. In any case, the most important line is:
The original file is no longer needed for recovery.
– John P
Aug 1 '17 at 15:15
Looks like it works -
:preserve
and :set cpoptions=...&
leaves a .swp and .swo file in the directory and offers to recover from either. Using vim -r <file>
you can choose between .swp and .swo. Further edits generate .swn, .swm, etc., which appear to be the partial sum of swaps up to that point. You can revert to the version of your liking and edit (~=fork) or save (~=stash). Eventually you can tar up the swap files, daemonize their backups, etc. I could be wrong about the details when it comes to larger files - I'm not sure how that affects the extra swap files either - see below.– John P
Aug 1 '17 at 16:02
Looks like it works -
:preserve
and :set cpoptions=...&
leaves a .swp and .swo file in the directory and offers to recover from either. Using vim -r <file>
you can choose between .swp and .swo. Further edits generate .swn, .swm, etc., which appear to be the partial sum of swaps up to that point. You can revert to the version of your liking and edit (~=fork) or save (~=stash). Eventually you can tar up the swap files, daemonize their backups, etc. I could be wrong about the details when it comes to larger files - I'm not sure how that affects the extra swap files either - see below.– John P
Aug 1 '17 at 16:02
(Continued) - the buffer carries the flags and it's the buffer that produces the swap files, so even if the flags aren't set from global configuration or autoload, they are inherited during recovery itself. To replace a recovery sequence with a single recovery file, you can move the swap you want to .swp and hide the rest. I'd love to know more about the overlap between file recovery and Vim session management if anyone can fill in the gaps.
– John P
Aug 1 '17 at 16:09
(Continued) - the buffer carries the flags and it's the buffer that produces the swap files, so even if the flags aren't set from global configuration or autoload, they are inherited during recovery itself. To replace a recovery sequence with a single recovery file, you can move the swap you want to .swp and hide the rest. I'd love to know more about the overlap between file recovery and Vim session management if anyone can fill in the gaps.
– John P
Aug 1 '17 at 16:09
add a comment |
Open the original file using vim, and choose the recovery option.
I don't have the original file.I just have it's '.swp'
– zarna
Oct 28 '10 at 7:36
1
That's less important than you think. Open it regardless.
– Ignacio Vazquez-Abrams
Oct 28 '10 at 7:40
add a comment |
Open the original file using vim, and choose the recovery option.
I don't have the original file.I just have it's '.swp'
– zarna
Oct 28 '10 at 7:36
1
That's less important than you think. Open it regardless.
– Ignacio Vazquez-Abrams
Oct 28 '10 at 7:40
add a comment |
Open the original file using vim, and choose the recovery option.
Open the original file using vim, and choose the recovery option.
answered Oct 28 '10 at 7:34
Ignacio Vazquez-AbramsIgnacio Vazquez-Abrams
96k6155211
96k6155211
I don't have the original file.I just have it's '.swp'
– zarna
Oct 28 '10 at 7:36
1
That's less important than you think. Open it regardless.
– Ignacio Vazquez-Abrams
Oct 28 '10 at 7:40
add a comment |
I don't have the original file.I just have it's '.swp'
– zarna
Oct 28 '10 at 7:36
1
That's less important than you think. Open it regardless.
– Ignacio Vazquez-Abrams
Oct 28 '10 at 7:40
I don't have the original file.I just have it's '.swp'
– zarna
Oct 28 '10 at 7:36
I don't have the original file.I just have it's '.swp'
– zarna
Oct 28 '10 at 7:36
1
1
That's less important than you think. Open it regardless.
– Ignacio Vazquez-Abrams
Oct 28 '10 at 7:40
That's less important than you think. Open it regardless.
– Ignacio Vazquez-Abrams
Oct 28 '10 at 7:40
add a comment |
1 Open the swap file .file.swp
in vim
2 :recover
will recover your file
add a comment |
1 Open the swap file .file.swp
in vim
2 :recover
will recover your file
add a comment |
1 Open the swap file .file.swp
in vim
2 :recover
will recover your file
1 Open the swap file .file.swp
in vim
2 :recover
will recover your file
edited Nov 8 '14 at 6:40
answered Nov 8 '14 at 6:20
SathyamSathyam
18115
18115
add a comment |
add a comment |
After reading Vegar Westerlund and Heptite comments, I wanted to know at what point vim needs the original file (or a backup) to recover from a .swp file. Here's what did:
I opened a 975 lines file, edited it on line 949 (creating a .swp
file) and killed the process, then deleted the original. $ vim Original_File
asked if I wanted to recover from the .swp » > yes; only the first 68 lines and the last 34 lines (starting 8 lines above my edit) were actually recovered.
I then repeated the test with smaller files: From 20 up to 200 lines, the .swp file contained 100% of the original content. But at 300 lines, only the first 68 and the 18 last lines (starting 2 lines above my edit) were included in the .swp.
As a conclusion it's good to know that vim always save the file's "header" and "bottom" in the .swp files. Maybe there's a setting to control how much lines should a .swp contains?
add a comment |
After reading Vegar Westerlund and Heptite comments, I wanted to know at what point vim needs the original file (or a backup) to recover from a .swp file. Here's what did:
I opened a 975 lines file, edited it on line 949 (creating a .swp
file) and killed the process, then deleted the original. $ vim Original_File
asked if I wanted to recover from the .swp » > yes; only the first 68 lines and the last 34 lines (starting 8 lines above my edit) were actually recovered.
I then repeated the test with smaller files: From 20 up to 200 lines, the .swp file contained 100% of the original content. But at 300 lines, only the first 68 and the 18 last lines (starting 2 lines above my edit) were included in the .swp.
As a conclusion it's good to know that vim always save the file's "header" and "bottom" in the .swp files. Maybe there's a setting to control how much lines should a .swp contains?
add a comment |
After reading Vegar Westerlund and Heptite comments, I wanted to know at what point vim needs the original file (or a backup) to recover from a .swp file. Here's what did:
I opened a 975 lines file, edited it on line 949 (creating a .swp
file) and killed the process, then deleted the original. $ vim Original_File
asked if I wanted to recover from the .swp » > yes; only the first 68 lines and the last 34 lines (starting 8 lines above my edit) were actually recovered.
I then repeated the test with smaller files: From 20 up to 200 lines, the .swp file contained 100% of the original content. But at 300 lines, only the first 68 and the 18 last lines (starting 2 lines above my edit) were included in the .swp.
As a conclusion it's good to know that vim always save the file's "header" and "bottom" in the .swp files. Maybe there's a setting to control how much lines should a .swp contains?
After reading Vegar Westerlund and Heptite comments, I wanted to know at what point vim needs the original file (or a backup) to recover from a .swp file. Here's what did:
I opened a 975 lines file, edited it on line 949 (creating a .swp
file) and killed the process, then deleted the original. $ vim Original_File
asked if I wanted to recover from the .swp » > yes; only the first 68 lines and the last 34 lines (starting 8 lines above my edit) were actually recovered.
I then repeated the test with smaller files: From 20 up to 200 lines, the .swp file contained 100% of the original content. But at 300 lines, only the first 68 and the 18 last lines (starting 2 lines above my edit) were included in the .swp.
As a conclusion it's good to know that vim always save the file's "header" and "bottom" in the .swp files. Maybe there's a setting to control how much lines should a .swp contains?
edited Jun 20 '17 at 10:59
answered Feb 6 '15 at 20:16
tuk0ztuk0z
25427
25427
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f204209%2fhow-can-i-recover-the-original-file-from-a-swp-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you using vi or vim?
– frabjous
Oct 28 '10 at 15:13