One editor feature I find really useful when programming is highlighting the word currently under the cursor, like this:

Highlighting current word

Emacs comes with this functionality built in, but it is very awkward to use.

To highlight the symbol under point (Emacs terminology for “word under cursor”), you need to use the function highlight-symbol-at-point which is bound to C-x w ..

Worse, to remove the current highlighting, you need to run unhighlight-regexp with C-x w r RET.

This is really cumbersome which is a shame because the feature is so useful.

So instead, I wrote a small function to toggle the highlighting of the symbol under point and bound it to Super-.:

(require 'hi-lock)
(defun jpt-toggle-mark-word-at-point ()
  (if hi-lock-interactive-patterns
      (unhighlight-regexp (car (car hi-lock-interactive-patterns)))

(global-set-key (kbd "s-.") 'jpt-toggle-mark-word-at-point)

I am aware that some libraries let me automatically highlight the symbol under point after a short wait, but I actually prefer to keep it manual to reduce visual clutter.

I recently switched back to Emacs after spending four years in Vim. This has been a really interesting journey which I may want to write more about in the future. If you’re curious, let me know in the comments.