Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have been trying to setup the shell version of vim to save any changed files when the shell window loses focus.

Following these instructions does not work.

Even though I am using OS X, I figure this may be something that affects vim running on Linux as well. Could be wrong, but I thought I'd also try on here as well as apple.stackexchange.com.

Am I to assume that maybe the reason why this does not work for a command line version of vim is because it's only intended to work with GUI versions, i.e. MacVim?

Is there a way to get this to work for a shell version of vim?

I'm using the latest version of vim available in homebrew.

share|improve this question
    
"Console"? Did you mean "TUI"? –  Ignacio Vazquez-Abrams Mar 19 '12 at 3:17
    
Ignacio: Sorry that I wasn't completely clear. When I think console, I mean shell (e.g. bash, etc). I'll amend the question to say shell instead. –  dbarros Mar 19 '12 at 4:22
    
Cross-posted from AskDifferent 44347. –  Chris Johnsen Apr 19 '12 at 4:29
add comment

2 Answers 2

up vote 3 down vote accepted

From :h FocusLost:

FocusLost                       When Vim lost input focus.  Only for the GUI
                                version and a few console versions where this
                                can be detected.  May also happen when a
                                dialog pops up.

*nix (including OS X) terminals do not make their focus status known to any applications run within them so this will not work there, and indeed there's no way to make it work.

share|improve this answer
    
D'oh! Thank you Ignacio. I guess that the Homebrew version of vim that I am using falls under the category which you quoted: "few console versions where this is detected". –  dbarros Mar 19 '12 at 4:24
add comment

If your goal is to prevent losing code maybe backup files could help you.

set backup                    " keep a backup after overwriting a file
set backupdir^=/tmp//         " list of directories to put backup files in

I have it in my .muttrc, it stores backup files until restarting the Mac in /tmp/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.