LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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


Reply
  Search this Thread
Old 04-03-2014, 08:16 AM   #1
petreza
LQ Newbie
 
Registered: Apr 2014
Posts: 6

Rep: Reputation: Disabled
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.)
 
Old 04-03-2014, 05:00 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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.
 
Old 04-03-2014, 06:17 PM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Mint, MX, antiX, SystemRescue
Posts: 2,337

Rep: Reputation: 358Reputation: 358Reputation: 358Reputation: 358
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.
 
Old 04-03-2014, 07:09 PM   #4
jthill
Member
 
Registered: Mar 2010
Distribution: Arch
Posts: 211

Rep: Reputation: 67
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.
 
Old 04-04-2014, 02:02 AM   #5
petreza
LQ Newbie
 
Registered: Apr 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bigrigdriver View Post
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.
 
Old 04-04-2014, 02:29 AM   #6
petreza
LQ Newbie
 
Registered: Apr 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by haertig View Post
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.
 
Old 04-04-2014, 02:38 AM   #7
petreza
LQ Newbie
 
Registered: Apr 2014
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jthill View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] vim insert mode in Emacs cola Linux - Newbie 2 04-20-2010 08:51 PM
Are there certain things one cannot type in Insert mode in vim? violagirl23 Linux - Desktop 1 01-07-2008 10:18 AM
moving around in vim while in insert mode cleff Linux - Software 3 06-14-2004 11:26 PM
VIM Setup- No 'insert' mode uveraser Linux - Software 1 05-25-2004 11:44 AM
insert mode in vim usr Linux - Software 1 01-18-2004 02:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration