Previously, I had tried accessing the file via FileZilla FTP and it went error while writing after editing. Therefore, I literally lost my weeks of work.
Not saying you shouldn’t take precautions, but losing your work was totally unnecessary even after losing your wp-config.php file. A new file could easily have been created to point to your existing site database, without losing any work.
Is there any good plugin or editor to safely edit and save wp.config.php?
No matter what tool you use, the ONLY “safe” way is to ALWAYS make a backup of important configuration files BEFORE touching it.
I would argue the SAFEST way to edit the file is by downloading a copy to your computer via FTP (after making a backup, of course), editing the downloaded file locally with a proper text editor software on your computer, and re-uploading the edited file.
It seems you tried to edit the file REMOTELY and directly in the FTP client, instead of downloading it to your computer first. That hardly ends well.
An EASIER way is to use the web-based text editor provided by your host. If you have a hosting control panel like cPanel, Plesk, etc, there’s a code editor built into your “FILE MANAGER” that you can use to make such simple and quick edits. Always make a backup first, of course, no matter what tool you use.
If you have more confidence in plugins, there are general File Manager plugins that allow you to edit files (these work similarly to the control panel option I mentioned above), such as https://ww.wp.xz.cn/plugins/file-manager-advanced/
There are also a couple of plugins specifically for editing the wp-config.php file, such as https://ww.wp.xz.cn/plugins/wp-config-file-editor/
Please note that I don’t have any personal experience using any of these plugins. And if I’ve not repeated myself enough, here’s one more try: no matter what tool you use to edit the file, always make a backup first so you can easily restore the original should anything go wrong!
Good luck!