0

Prob Scenario : I encountered an error msg “e325-attention-swap-file-already-present-error-in-vi” when I tried to perform a git commit.

Qn: “How do I open that particular file on git bash vim editor itself to peer inside the contents where exactly did the clash occur? I’m not asking how to remove the file form the staging area, I’m asking in particular to open that file on the git bash’s vim editor itself? And if so able, once done, how do I save that file ON the vim editor itself in git bash & exit the irritating modes in vim. PS: can any kind soul give me a useful “f1/-help”-type command that I can use to check to move forward whenever I am stuck in the vim editor mode and not exit the editor altogether each time I encounter sucha prob? Thanks!

1615903
  • 32,635
  • 12
  • 70
  • 99

2 Answers2

0
  1. More than likely, the swapfile was from the .git/COMMIT_MESSAGE file (I believe I have the name right). It exists when vim crashes or exits abnormally to aid data recovery. In your case, I recommend deleting it (rm .git/.COMMIT_MESSAGE.sw?—find it with ls -a .git or tab-complete). Then commit.
  2. See this question for exiting vim. Long story short, I hit Esc after finishing my commit message and then hit Z Z to save and quit.
  3. The QA also mentions :help—this is the best place to read about vim. :help can usually be tab-complete (you may need Ctrl-d). I highly recommend running through vimtutor and some of the help pages if you plan to use vim at all. Or, set your EDITOR and VISUAL environment variables to something else (I’ve seen nano a lot for folks who don’t want to learn a command-line editor à la vim or emacs). Also note that vi.stackexchange exists.

Note: normal advice is not to delete the swap file. Often you want to recover information from them, or see if there is recoverable information. The internet and the help pages have details on doing this. For the case of a commit message, however, and for the OP, the simplest thing to do is to start from scratch (as the swap file was likely created by destroying the vim instance once OP couldn’t figure out what to do).

D. Ben Knoble
  • 4,273
  • 1
  • 20
  • 38
0

vi is a pretty overlay on the ex engine. c.f. this man page for ex in particular.

Any command you enter in vi with a colon prompt (escape, then : followed by your command) is actually an ex command. That's why a lot of people use :q or :x or :wq or :q! (etc) to get out of vi.

Paul Hodges
  • 13,382
  • 1
  • 17
  • 36