Search code examples
emacselispfind-occurrences

emacs key bind search buffer to occur


I like the option to do C-s C-w and then show all in a separate buffer by using M-s o, but I would really like to keybind the M-s o ('occur) such that I can type C-s C-w C-, or similar-

I have tried the normal keybind:

(global-set-key (kbd "C-,") 'occur)

But it just do the normal occur, not the search buffer occur.


Solution

  • The command that is bound to M-s o during an isearch isn't the default occur command, but a special version called isearch-occur, that automatically invoke occur on isearch hits.

    You can bind this to the C-o (or C-, if you prefer) shortcut without overriding other commands using the define-key command with the isearch-mode-map:

    (define-key isearch-mode-map (kbd "C-o") 'isearch-occur)
    

    In this way you can use the sequence C-sC-wC-o.