'!q' and 'wq!' failed to quit vim [duplicate]

By

I tried to quit vim

"/etc/sysconfig/network-scripts" "/etc/sysconfig/network-scripts" E212: Can't open file for writing Press ENTER or type command to continue 

When I press Enter, it returns to edit mode. I tried

!q Press ENTER or type command to continue [No write since last change] /bin/bash: q: command not found shell returned 127 Press ENTER or type command to continue 

I press Enter, it returns to the previous editor mode again.

How can I quit vim in this situation?

👉 For more insights, check out this resource.

1

1 Answer

If you want save changes :wq!, but if something wrong and you want quit anyway (ignore changes) - :q!

Often you can start edit file with no permissions to save it. You can make many changes and then understood, you can't save it. In this case i recommend save as it:

👉 Discover more in this in-depth guide.

:w tmp_filename 

then exit vim and replace old file with tmp_filename.