3

Can I assign a key binding starting with C-s such as:

(global-set-key (kbd "C-s C-w") 'isearch-forward-symbol-at-point)

but I want to keep (kbd "C-s") for i-search.


I am having following error:

error: Key sequence C-s C-w starts with non-prefix key C-s

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the ‘--debug-init’ option to view a complete error backtrace.
3

As I understand your question, you want C-s to start an interactive search, as it normally does, but if you press C-w after you've started that search, you want it to switch to isearch-symbol-at-point.

First off, the feature you're after is almost the same as the default behaviour bound to C-s C-M-w. That will call isearch-yank-symbol-or-char, which is close, but not identical to isearch-symbol-at-point. Maybe that's close enough.

If you really want to call isearch-forward-symbol-at-point, without overwriting the default behaviour of C-s, you'll need to add the new binding to the isearch-mode-map:

(define-key isearch-mode-map (kbd "C-w")
  'isearch-forward-symbol-at-point)

Note that this will overwrite the default definition of C-s C-w, which is to call the function isearch-yank-word-or-char.

The default options to isearch are described in the manual (info "(emacs) Isearch Yank")

| improve this answer | |
0

The C-s needs to be assigned as a prefix command.

eg

(define-prefix-command 'myprefix)
(global-set-key (kbd "C-s") 'myprefix)
(global-set-key (kbd "C-s C-s") 'helm-occur)
| improve this answer | |
  • I am confused I want to keep C-s key binding for the isearch @RichieHH – alper Feb 5 at 10:08
  • 1
    @alper: then how is emacs to guess that you mean to type a second C-s? It can either be a prefix or it can be a key bound to a command, but it cannot be both. – NickD Feb 5 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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