Showing posts with label keyboard. Show all posts
Showing posts with label keyboard. Show all posts

Wednesday, October 19, 2011

Delete selected page(s) from a PDF in Preview (Snow Leopard)

The function to delete the selected page (or pages) from a PDF file disappeared from the Edit menu of Preview in Snow Leopard. Even worse, the Command-Delete shortcut moves the entire PDF document to the trash.

An undocumented keyboard shortcut: Shift-Command-Delete allows in Snow Leopard to delete the selected pages, and only those pages will be deleted from the document.

Source: http://hints.macworld.com/article.php?story=20091026213158621

Tuesday, September 27, 2011

OSX Hotkeys for screen lock, invert colors and dictionary

The keyboard shortcut: Control+Shift+Eject
blanks immediately the screen and locks if set to do so (with “Require password after sleep or screen saver begins” enabled).


The keyboard shortcut: Control+Alt+Cmd+8
inverts the screen colors. This is ideal for presentations when the visibility due to the lighting conditions is poor.


The keyboard shortcut: Control+Cmd+D
pops-up immediately the dictionary with the description of the word under the cursor.



Source http://osxdaily.com/2011/01/17/lock-screen-mac/http://www.silvermac.com/cool-things-to-do-on-mac/

Friday, October 22, 2010

Disabling Option-Space (and AltGr-Space) key combination for non-breaking space

Solving “bash: grep: command not found” on OSX and Linux terminals.
How many times this happened to you?

$ find .  | grep something
bash: grep: command not found

This problem affects non US-keyboard users, suffering from sloppy finger.
Typing the pipe ( | ) in a command line requires the combination with Option or AltGr in most non US keyboard, and after the pipe the use of the space is not mandatory but certainly a touch of distinction.
The problem is that by the time when the Space key is hit, some sloppy finger is still firmly pressing the Option key resulting in the Option-Space combination (or AltGr-Space). 
It turns out that the combo produces something that looks exactly like a sp character, but that bash does not recognize as a space. A closer inspection reveals that the Option-Space combination instead of producing the sp byte \040, produces the sequence \302\240 which turns out to be Unicode for non-breakable space.


While working with OSX my solution for several moths was to remove the spaces from the command, recently I found a simpler solution which was described here.
Add the following text to the key binding file (it may not exist yet, if so create it) : ~/Library/KeyBindings/DefaultKeyBinding.dict
  {
    "~ " = ("insertText:", " ");
  }
this file defines the key-sequence mappings for all Cocoa applications. In particular with this line, every time Option-Space is pressed the non-breakable space it is replaced by a regular space. This file can be used for further customizing the behavior of key sequences. The following links provide more information about key binding:
http://hints.macworld.com/article.php?story=2008031611584277
http://www.object.com/TechNotes/DefaultKeyBinding.html
http://www.hcs.harvard.edu/~jrus/site/cocoa-text.html


The solution for Linux is described here. The non-breakable space can be disabled using a xkb option in xorg.conf, adding the following in the InputDevice section related to your keyboard
  ...
  Option "XkbOptions"    "nbsp:none"
  ...
or calling
  setxkbmap -option "nbsp:none"
in a console, or initialization file (~/.bash_profile).


Regarding Unicode, I recommend to read this article: "The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)", it gives a brief historical overview and tells pretty much everything one should know about Unicode.

A nice observation from Poul-Henning Kamp, that we don't use of Unicode as part of our programming languages: "Sir, Please Step Away from the ASR-33!".

Saturday, July 24, 2010

Code folding with Vim

I've learned about code folding using Vim.
The command zfa} collapses (folds) a C block using the } symbol as guide.

The following code maps the Spacebar to a function that folds/unfolds the current block (add this to ~/.vimrc), based on this.

"Fold coloring 
hi Folded        ctermfg=white ctermbg=NONE

fun! ToggleFold()
if foldclosed('.') < 0
". foldclose
:execute "normal zfa}<cr>"
else
. foldopen
endif
" Clear status line
echo 
endfun

" Map fold/unfold function to Space key.
"nmap <space> zfa}<cr>
"nmap <space> :call ToggleFold()<cr>
noremap <space> :call ToggleFold()<cr>

Here there is a more sophisticated function for folding.

vmap <space> zf

" inspired by Max Ischenko's http://www.vim.org/tips/tip.php?tip_id=108
function ToggleFold()
   if foldlevel('.') == 0
      " No fold exists at the current line,
      " so create a fold based on braces
      let x = line('.')    " the current line number
      normal 0
      call search("{")
      normal %
      let y = line('.')    " the current line number
      " Create the fold from x to y
      execute x . "," . y . " fold"
   else
      " Delete the fold on the current line
      normal zd
   endif
endfunction

nmap <space> :call ToggleFold()<cr>

Tuesday, September 22, 2009

Screenshots

To Capture the Screen:

Command-Shift-4 ----- window (use spacebar or mouse to select)
Command-Shift-3 ----- desktop

Add Control to the two shortcuts above to place the screen shot on the clipboard instead of saving it to the desktop.

Cycle between all open windows, with non US keyboard

It was not evident to me but cycling between open windows using
Command-Tab, cycles between applications.
To cycle between open windows of the same application there is another key mapping:
Command-`

But on non-english keyboards this is very uncomfortable.
I changed it to
Command-º
º is on the same place as ` in my spanish keyboard.

System preferences > Keyboard & Mouse > Keyboard Shortcuts > Keyboard Navigation > Move focus to next window in active application


Sources:

Monday, September 21, 2009

OS X VIM Terminal PageUp, PageDown, Home, End and Forward/Backward Word WORKING

One really big issue with the mac laptops is that some keys are missing.
Home, End, PageUp and PageDown are obtained as combination of Fn+Arrows.
And the forward/backward-word are not mapped by default they are Ctrl-Right/Left in linux.

Sometimes these keys are not properly reflected inside vim.

To correct this issue I found several pages, one of them is
http://blog.sbw.be/2008/12/11/mac-osx-vim-terminal-page-up-page-down-home-end-working/

Just go to:
Terminal > File > Preferences
and change the following keyboard settings.

OSX VIM TERMINAL PAGE UP, PAGE DOWN, HOME, END WORKING
Home: \033[1~
End: \033[4~
PageUp: \033[6~
PageDown: \033[5~

TERMINAL backward/forward-word
"\033[5D": backward-word
"\033[5C": forward-word

UPDATE: TERMINAL backward/forward-word ALSO WORKING WITH VIM
Change both: .inputrc and the terminal preferences to match these codes.
"\033[1;5C": forward-word
"\033[1;5D": backward-word