Vim Opening File E325 Attention Error - vim

On Git bash windows, I was editing .bash_profile file and then I decided not to save and closed the bash console. Now when I try to open the .bash_profile using vim, I get E325: Attention error. What should I do to fix this?

By closing the console without exiting Vim first, the Vim process got killed, and Vim didn't have a chance to properly shut down. Vim uses swap files to store the last unpersisted changes to a buffer to avoid data loss in case of a crash; you can read the whole story at :help E325.
In your case, as you've consciously closed the console, there probably weren't any pending changes to your .bash_profile [worth saving]. (But there's still the swap file!) Therefore, when prompted
Swap file ".bash_profile.swp" already exists!
[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort, (D)elete it:
answer with D to remove the outdated swap file. Alternatively, you can also search for the .bash_profile.swp (by default, it resides in the same directory as the edited file, likely $HOME in your case) and delete it manually. (It's hidden; use ls -a in Bash, or Windows Explorer.)
In the future, please exit Vim (:qall[!]) before closing the console it runs in, to allow for a clean shutdown.

Related

Nano - File already being edited - How do I switch to the open file?

I have a tendency to miss-type while trying to Ctrl-X to exit nano.
Every now and then I'll try to re-open the file and get the Nano "File xxx is being edited". How do I switch back to the open file? And also, what am I miss-typing to cause this to happen?
First check if there is a process editing the file.
$> jobs
You will get a list of background jobs, look for Stopped ones.
If there is and it's your editor, try re-attaching to it:
$> fg <n>
Else, if there is no running nano, make sure there is no lock-file.
ls -A *.swp
If there is, remove it.
rm nnn.swp
If you still have trouble editing the file, reboot and restart above.
Maybe there are more things to try, but that's all I can think of...
nano creates a lock file once you try to edit the file, I would say just try to move it and it might work.

bug with my zsh in the terminal (linux)?

i have some trouble with my terminal in linux.
When i start my terminal i have this line:
This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~). This function can help you with a few settings that should
make your use of the shell easier.
You can:
(q) Quit and do nothing. The function will be run again next time.
(0) Exit, creating the file ~/.zshrc containing just a comment.
That will prevent this function being run again.
(1) Continue to the main menu.
(2) Populate your ~/.zshrc with the configuration recommended
by the system administrator and exit (you will need to edit
the file by hand, if so desired).
--- Type one of the keys in parentheses ---
how i run zsh ?
And when i press "2" i have this :
cp: not writing through dangling symlink '/home/thomas/.zshrc'
zsh-newuser-install:source:982: no such file or directory: /home/thomas/.zshrc
thx for the help.
zsh is an uncommon choice on linux. If your account is on somebody else's system, ask the sysadmin to fix it up for you. If you installed it, look at .zshrc with ls -l : the 'dangling symlink' suggests it exists but points to somewhere else (that suggests an admin or distro install) and the place it is pointing to does not exist.
If you can identify where it should be pointing (I'm assuming now that this is a distro install), fix the symlink. Otherwise ask on a distro list or forum.

editing file through vi editor in shell script show error

script in which I open a file in vi editor , after that user will write any thing in it then save or quite by :wq!
When I try this then it give an error message as below
e138 can't write viminfo file $home/.viminfo!
and ask for,
Press Enter or command to continue
Now when I press enter then file save. But why that error message shows.
If I open same file direct with vi editor or vim editor and do changes then it does not give any error.
also if I install vim editor then it works fine and no error shows
Please tell me what may be the issue.
my best guess is that $home is not defined properly. try running: !echo $home on both editors. If it's not defined during the script run, define it before running vim.
I came here with mostly the same error, but this answer did not work for me. I had to create more space within my $HOME directory by deleting a few files, and then vim worked normally again.

Vim Ex mode loads when opening terminal

I know little about Vim in terminal(Mac) and the other day I was working copy and pasting text and i think I accidently did it when in terminal. Now whenever I open terminal it instantly loads on Vim Ex mode. I know how to quit Ex mode once in terminal but is there any way i can get rid of Vim loading when I open Terminal?
Thanks
Edit: To explain further to what i mean when I open terminal.app from Utilities I get the following
and the only way I get back to the command prompt is by typing quit every time I open terminal and i cant understand why the Vim process is running in the first place.
I was just outside the terminal in a document copy and pasting text then accidentally did a command v to paste within terminal which resulted in this happening.
It appears that you've accidentally updated one of your shell startup scripts so it launches vim.
If your default shell is csh or tcsh, take a look at .cshrc, .tcshrc, and .login in your home directory, and look for a command like vi -e or vim -e.
If your default shell is bash, check .bashrc and .bash_profile.
It may be easier to figure out which file you messed up by checking which file in your home directory was modified most recently:
% ls -altr $HOME | tail
-a lists all files, including files whose names start with ..
-l gives you a long listing, showing timestamps.
-t sorts by modification time.
-r reverses the order, so newer files are shown last

How do I deal with vim's swap file system?

When using vim in ubuntu, I accidentally pressed ctrl-z which suspended my session of vim. I was editing a file (I'll call it test) which was not saved.
When I opened the file again in vim, I got the swap file error:
E325: ATTENTION
Found a swap file by the name ".test.swp"
Swap file ".test.swp" already exists!
According to Found a swap file by the name question, I have two options:
Find the session and finish it (preferable).
Delete the .swp file (if you're sure the other git session has gone away).
How would I do either of those things? If I perform rm test.swp it doesn't see the file:
rm: cannot remove `test.swp': No such file or directory
What am I doing wrong in the deletion of the swap file and how can I finish the session?
EDIT: I forgot the period in test.swp
So the correct way to remove the swp file is rm .test.swp.
My remaining question is how to resume/finish a suspended session of vim.
This is not related to Ubuntu alone, since what happens is a base mechanism of
nearly every Unix OS.
By pressin ^Z you ave suspended (not ended) the currently running vim session. The vim
session is still there and waiting for a signal to put it to foreground again.
To reactivate the session:
If vim was started directly from the commandline -- use the command "fg" (which is for "ForeGroung") and vim will appear again. This works on all ksh/bourne-like shells. For t/csh I dont know. This only works when the command "fg" was given on the console of the same terminal session as from which vim was started (which is the "controlling terminal" related to the vim session).
If vim was started (mostly under the name gvim) from a menu of a windowmanager you are a little bit out of luck here, since (g)vim gets detached from its controling terminal.
Your options to recover:
Use "fg" if the condition is valid described above. This is the cleanest way.
If the (g)vim session is detached from the controling terminal, which can be checked by doing a "ps -ef | grep vim". If the column for the TTY (see header of the output) shows
a "?" there is no controling terminal anymore, I would recommend to send the process
a SIGHUB (see manpage for the commmand "kill"/"killall") and then a SIGKILL if it is still there.
Killing vim (or any other task) will probably result in inconsistent data though, cause there was no "save" command to vim before it is killed.
After that, start a new vim with the same file, do a "recover" first (as offered by vim, which sees the according swp-file) , save the file, end vim and start it again with that file and do a "delete swap file". This is the savest way possible after killing vim.
To avoid accidentically putting vim into background if not wanted, map ^Z to another, more
"complicated" keysequence, which is hard to press accidentically. You can deactivate the
^Z command by adding the following line to your .vimrc:
map <C-z> ;
Addition: Your rm-command misses the dot in front of .test.swp causing rm not to
find the file...or deleting another file, which is named test.swp instead of ".test.swp". By deleting swp-files via vim, you are sure to delete the correct file.
Swp-files always start with a dot (hidden file) on UNIX like systems.
the file is going to be " .test.swp ", not " test.swp "
So you'll want to:
rm .test.swp

Resources