| Swap file | Undo file | |
|---|---|---|
| Protects against | Crash (unsaved keystrokes) | Wanting to undo after reopening |
| Causes E325 conflicts | Yes | No |
| Needs git as safety net | Not if working correctly | Yes, for crash-level recovery |
| Persists across sessions | No (deleted on close) | Yes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :help swap-file | |
| Vim stores the things you changed in a swap file. | |
| Using the original file you started from plus the swap file | |
| you can mostly recover your work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :help undo-persistence | |
| When unloading a buffer Vim normally destroys the tree of undos | |
| created for that buffer. By setting the 'undofile' option, | |
| Vim will automatically save your undo history when you write a file | |
| and restore undo history when you edit the file again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- in init.lua or options.lua | |
| vim.opt.swapfile = false | |
| -- compensate with persistent undo | |
| vim.opt.undofile = true | |
| vim.opt.undodir = vim.fn.stdpath("state") .. "/undo" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| vim.api.nvim_create_autocmd("SwapExists", { | |
| pattern = "*", | |
| callback = function() | |
| vim.v.swapchoice = "e" -- always edit the disk version | |
| end, | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # preview what would be deleted | |
| ls ~/.local/state/nvim/swap/ | |
| # remove all stale swap files | |
| rm -f ~/.local/state/nvim/swap/*.swp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This fails — node_t is not defined yet when used on line 3 | |
| typedef struct Node { | |
| int value; | |
| node_t *next; // error: unknown type name 'node_t' | |
| } node_t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| typedef struct Node node_t; // forward declaration | |
| typedef struct Node { | |
| int value; | |
| node_t *next; // now the compiler knows node_t | |
| } node_t; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. Signature ← this is the forward declaration equivalent | |
| 2. Purpose | |
| 3. Stub | |
| 4. Examples/Tests | |
| 5. Template | |
| 6. Code the body |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| brew install ttyd |
NewerOlder