OS X Lion (and Snow Leopard) tweaks that will save your sanity

OS X Lion needs a few tweaks from stock to really make the system cook so I’ve added them in this post as a record for myself and hopefully a help to someone. MacBook Air key mapping tweaks to use the same Home/End/PgUp/PgDown keys in Cocoa apps and Terminal/Vim type applications. Stop Safari from prompting when you attempt to navigate away from a form. This article may be in various states of completeness and may be broken out in to other posts.  

MacBook Air Home/End/PgUp/PgDown key sanity

I have a MacBook Air, so the Home/End/PgUp/PgDown keys in the terminal and Vim are frustrating. To get Vim and terminal page up, page

down, home, end working, go to Terminal > Preferences and change the following keyboard settings:
 Home: \033[4~
 End: \033[1~
 PageUp: \033[5~
 PageDown: \033[6~
    You’ll have to copy and paste the values since the program will attempt to capture your keystrokes. Then setup those keys to have, linux like, sane behaviour in bash and other readline aware programs, as root edit /etc/inputrc or as user ~/.inputrc:    
# Be 8 bit clean.
set input-meta on
set output-meta on
set convert-meta off
# allow the use of the Home/End keys
"\e[1~": beginning-of-line
"\e[4~": end-of-line
# allow the use of the Delete/Insert keys
"\e[3~": delete-char
"\e[2~": quoted-insert
# mappings for "page up" and "page down" to step to the beginning/end
# of the history
"\e[5~": beginning-of-history
"\e[6~": end-of-history
# alternate mappings for "page up" and "page down" to search the history
# "\e[5~": history-search-backward
# "\e[6~": history-search-forward
You should setup all your Cocoa Mac OS X programs to have the same behaviour with end / home / page up / page down keys if. You’ll have to create a new folder called KeyBindings in the ~/Library folder and file here:
~/Library/KeyBindings/DefaultKeyBinding.dict
{
/* Changes home/end keys to a sane behaviour */
"\UF729" = "moveToBeginningOfLine:"; /* home */
"\UF72B" = "moveToEndOfLine:"; /* end */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* shift + home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:"; /* shift + end */

/* Changes pgup/pgdn keys to sane behaviour */
"\UF72C" = "pageUp:"; /* pgup */
"\UF72D" = "pageDown:"; /* pgdn */
"$\UF72C" = "pageUpAndModifySelection:"; /* shift + pgup */
"$\UF72D" = "pageDownAndModifySelection:"; /* shift + pgdn */
}
I’ve found that you’ll have to do a reboot to get everything working, but once you do, you’ll be able to use these commands:
Home: fn + left
End: fn + right
PgUp: fn + up
PgDown: fn + down
Hold Shift and use the above keystrokes to select text while traveling the cursor.

Stop Safari from asking you about unsubmitted forms

This one is quick and easy. Just a terminal command.
defaults write com.apple.Safari DebugConfirmTossingUnsubmittedFormText 0

Enable key repeating in Lion

Not sure who’s bright idea it was to disable key repeating (couldn’t we use a modifier key like shift/alt/option/command/etc?), but this is how you re0enable it.
defaults write -g ApplePressAndHoldEnabled -bool false

Program for remapping keys in OS X

This program works in Lion and comes highly recommended; however, I have not tried it myself – keyremap4macbook.

Turn Off Autosave for Safari

defaults write com.apple.Safari NSQuitAlwaysKeepsWindows -bool false

Turn Off Autosave for Chrome

defaults write com.google.Chrome NSQuitAlwaysKeepsWindows -bool false

Turn Off Autosave for QuickTime

defaults write com.apple.QuickTimePlayerX NSQuitAlwaysKeepsWindows -bool false

Turn Off Autosave for Preview

defaults write com.apple.Preview NSQuitAlwaysKeepsWindows -bool false

Turn Off Autosave for Other Apps

It’s possible to turn off the autosave feature for other applications that create file in ~/Library/Saved Application State/ You’ll want to delete the .savedState file in the folder and then run this in the terminal:
defaults write com.apple.<YOUR_APP> NSQuitAlwaysKeepsWindows -bool false
Just swap out false for true if you want to turn the feature back on.

Comments

Posted On
Nov 08, 2011
Posted By
sachin

Thanks, perfectly worked for VIM, its better than using cntr-f and cntrl-b for page up and page down.

Posted On
Jul 09, 2012
Posted By
Chavy

These are great tips and help make the colsoel usable. Thanks

Posted On
Aug 10, 2012
Posted By
Jessie Haden

Hello,I love to find out more on this field. Thank you for publishing OS X tweaks

Posted On
Aug 22, 2012
Posted By
Martin

Thanks! I think the home and end keys are the wrong way round in .inputrc.

It should be:
“\e[4~”: beginning-of-line
“\e[1~”: end-of-line

Posted On
Mar 22, 2013
Posted By
vic

actually I think what was wrong was the terminal’s setting

It should be
Home: 33[1~
End: 33[4~

I checked some other websites and the settings in inputrc seems to be correct.

Posted On
Sep 06, 2012
Posted By
Tony Su

instead of turning off auto-safe for each application, you can press command + option + q to quit the applications without saving /remembering the previous status

Leave a Reply



× 8 = twenty four

Login