Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
04-03-2014, 08:16 AM
|
#1
|
LQ Newbie
Registered: Apr 2014
Posts: 6
Rep:
|
Vim - saving from insert mode - no confirmation - help?
Hi,
I use the 'zz' key combination to save the file without exiting vim. To make it work in both normal and insert mode I use the following 2 lines in my .vimrc file:
Code:
imap zz <Esc>:w<CR>i<right>
nnoremap zz :w<CR>
When I press 'zz' in normal mode I get a message on the command bar that the file was saved. But in insert mode there is no way to tell if the save was really completed.
Is there some kind of a time delay function in vim so that I can have a line like this:
Code:
imap zz <Esc>:w<CR>:echo "Saved."<CR> timedelay(500ms) i<right>
Is there even a better a way to get similar effect - maybe some kind of popup in the middle of the screen?
(I am using vim in a terminal - not a GUI.)
|
|
|
04-03-2014, 05:00 PM
|
#2
|
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908
|
In vim, you may also write without quiting with this command: :w!
When I used this option in a test, there was a statement displayed which gave the number of characters written to the file.
The vim manpage says this:
Code:
:w[rite]! [++opt] Like ":write", but forcefully write when 'readonly' is
set or there is another reason why writing was
refused.
Note: This may change the permission and ownership of
the file and break (symbolic) links. Add the 'W' flag
to 'cpoptions' to avoid this.
Use this method with care. Pay special attention to the Note:
Within a vim session, give the command ":help write" (without quotes) for more information.
|
|
|
04-03-2014, 06:17 PM
|
#3
|
Senior Member
Registered: Nov 2004
Distribution: Mint, MX, antiX, SystemRescue
Posts: 2,337
|
Why would you want a key sequence like zz to work from within insert mode? Do you never expect to type "jazz" or "fuzz" and are OK with wiping them out of the dictionary now and forever?
Why not save without exiting in command mode by using :w like the majority of everyone else? And NOT try to save while in insert mode, like everyone else? There are already about ten bazillion alternate ways you can accomplish something in vi, why try to add even more non-standard ones?
That's like modifying your car so that pushing the accelerator to the floor actually applies the brakes. Because you never push the accellerator to the floor yourself, and desire an alternate and "more intuitive" (for you) way of applying the brakes. Then you get into somebody elses car that doesn't have your custom modifications and you are set up for a significant crash and burn.
|
|
|
04-03-2014, 07:09 PM
|
#4
|
Member
Registered: Mar 2010
Distribution: Arch
Posts: 211
Rep:
|
The default status line shows "[+]" on the for modified buffers, or you could keep a running changes-since-saved count displayed using the `statusline` option, the `changedtick` variable and a `bufwrite` autocommand to track its value at the last save.
|
|
|
04-04-2014, 02:02 AM
|
#5
|
LQ Newbie
Registered: Apr 2014
Posts: 6
Original Poster
Rep:
|
Quote:
Originally Posted by bigrigdriver
In vim, you may also write without quiting with this command: :w!
When I used this option in a test, there was a statement displayed which gave the number of characters written to the file.
The vim manpage says this:
Code:
:w[rite]! [++opt] Like ":write", but forcefully write when 'readonly' is
set or there is another reason why writing was
refused.
Note: This may change the permission and ownership of
the file and break (symbolic) links. Add the 'W' flag
to 'cpoptions' to avoid this.
Use this method with care. Pay special attention to the Note:
Within a vim session, give the command ":help write" (without quotes) for more information.
|
Thanks, but yes, I wouldn't want to use it to overwrite any 'readonly' file. Plus it does not really solve the problem - I tried it on a test file and after the saving operation I still only get '-- INSERT --' at the bottom.
|
|
|
04-04-2014, 02:29 AM
|
#6
|
LQ Newbie
Registered: Apr 2014
Posts: 6
Original Poster
Rep:
|
Quote:
Originally Posted by haertig
Why would you want a key sequence like zz to work from within insert mode? Do you never expect to type "jazz" or "fuzz" and are OK with wiping them out of the dictionary now and forever?
Why not save without exiting in command mode by using :w like the majority of everyone else? And NOT try to save while in insert mode, like everyone else? There are already about ten bazillion alternate ways you can accomplish something in vi, why try to add even more non-standard ones?
That's like modifying your car so that pushing the accelerator to the floor actually applies the brakes. Because you never push the accellerator to the floor yourself, and desire an alternate and "more intuitive" (for you) way of applying the brakes. Then you get into somebody elses car that doesn't have your custom modifications and you are set up for a significant crash and burn.
|
Hi, thanks for your reply but I think any less-typing is good, especially for something like saving that happens so often. That's why I also have <Esc> mapped to 'jj' which is faster even if it is more typing, and even 'ZZ' to save-and-exit in insert mode. If I want to actually type 'zz', 'jj', and 'ZZ', I just have to wait a bit longer between the two presses of the letter (half a second or so) so that Vim stops expecting a command. Also there is a slight visual jerk when typing the letters 'j' 'z' and 'Z' as the cursor does not automatically advance for about a half a second or until I type the next letter but I got used to it and usually just blast through typing.
Imagine I am editing an HTML document. As soon as I am done I am pressing 'zz' with my right hand (Dvorak) while my left is reaching for the Alt-Tab to go to the browser to refresh. Total 2 "movements" - I count 'zz' as one and Alt-Tab as one. Compare that to 'jj'+:+w+<CR>+Alt-Tab = 5 by the same standard plus I have to press 'i' for insert mode when I get back = 6.
You are right, though, that if I move to someone else's computer I would be typing junk.
|
|
|
04-04-2014, 02:38 AM
|
#7
|
LQ Newbie
Registered: Apr 2014
Posts: 6
Original Poster
Rep:
|
Quote:
Originally Posted by jthill
The default status line shows "[+]" on the for modified buffers, or you could keep a running changes-since-saved count displayed using the `statusline` option, the `changedtick` variable and a `bufwrite` autocommand to track its value at the last save.
|
Thanks! I started reading on these but it quickly became apparent that they are over my head.
|
|
|
All times are GMT -5. The time now is 09:09 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|