How can I emulate Vim’s * search in GNU Emacs?

Based on your feedback to my first answer, how about this: (defun my-isearch-word-at-point () (interactive) (call-interactively ‘isearch-forward-regexp)) (defun my-isearch-yank-word-hook () (when (equal this-command ‘my-isearch-word-at-point) (let ((string (concat “\\<” (buffer-substring-no-properties (progn (skip-syntax-backward “w_”) (point)) (progn (skip-syntax-forward “w_”) (point))) “\\>”))) (if (and isearch-case-fold-search (eq ‘not-yanks search-upper-case)) (setq string (downcase string))) (setq isearch-string string isearch-message (concat isearch-message (mapconcat … Read more

Unset key binding in emacs

The general way to unbind a key (for any keymap) is to define a binding of nil: (define-key KEYMAP KEY nil) For convenience, there are also two standard functions for unbinding from the global keymap and from the local keymap (which is usually the major mode’s keymap). (global-unset-key KEY) (local-unset-key KEY) Those ones are interactive … Read more

How do I write a regular expression that excludes rather than matches, e.g., not (this|string)?

This is not easily possible. Regular expressions are designed to match things, and this is all they can do. First off: [^] does not designate an “excludes group”, it designates a negated character class. Character classes do not support grouping in any form or shape. They support single characters (and, for convenience, character ranges). Your … Read more

how to delete the repeat lines in emacs

If you have Emacs 24.4 or newer, the cleanest way to do it would be the new delete-duplicate-lines function. Note that this works on a region, not a buffer, so select the desired text first it maintains the relative order of the originals, killing the duplicates For example, if your input is test dup dup … Read more

Converting from camelcase to _ in emacs

Use the string-inflection package, available on MELPA, or at https://github.com/akicho8/string-inflection. Useful keyboard shortcuts, copied from https://www.emacswiki.org/emacs/CamelCase : ;; Cycle between snake case, camel case, etc. (require ‘string-inflection) (global-set-key (kbd “C-c i”) ‘string-inflection-cycle) (global-set-key (kbd “C-c C”) ‘string-inflection-camelcase) ;; Force to CamelCase (global-set-key (kbd “C-c L”) ‘string-inflection-lower-camelcase) ;; Force to lowerCamelCase (global-set-key (kbd “C-c J”) ‘string-inflection-java-style-cycle) … Read more

tech