5

To copy the character at point usually I do Shift-<right> M-w. I am wondering what are the alternative ways to do this action using only the Emacs standard keybindings (maybe with minimal keystrokes but this is not very important).

Specially when working with unicode characters, it is easier to copy-paste them rather than insert them directly, this is maybe a reason why a convenient shortcut for copying a character would be helpful.

Perhaps an inconvenience with Shift-<right> M-w is that the fours keys involving in this action are a little far away.

Of course one can define a personal shortcut for this, but I am looking for a standard shortcut.

(Note: It appears that in vim mode vy can do this).

Edit: I appears that the short answer to my question is no. For this reason I accepted the answer given by Emacs User. An alternative solution is the following: We can exploit the fact that the shortcut Meta-w bounds to nothing if a region is selected. Hence we can use the ordinary Meta-w to copy the character with the following settings The first function was suggested by lawlist. This is the best alternative way I found without introducing an extra shortcut.

(defun my-copy-region-as-kill ()
  (interactive) (copy-region-as-kill (point) (1+ (point))))

(defun my-copy-character () (interactive)
       (if (region-active-p) (kill-ring-save (region-beginning) (region-end))
     (my-copy-region-as-kill)))

(global-set-key (kbd "M-w") 'my-copy-character)
  • 3
    Instead of S-<right> you could use `C-SPC C-f`` to set the mark and move forward one char. Not shorter, but less reach. – glucas Aug 7 '15 at 0:28
  • 1
    How about a function key -- that way you would only be pressing one key? (defun my-copy-region-as-kill () (interactive) (copy-region-as-kill (point) (1+ (point)))) (global-set-key [f5] 'my-copy-region-as-kill) – lawlist Aug 7 '15 at 0:47
  • 2
    In my opinion you don't need easy way to copy a character, because it's usually quite useless if you can enter the character. Your inability to easily enter unicode character of interest is the real problem. Consider asking this question instead. – Mark Karpov Aug 7 '15 at 7:54
  • 2
    @Mark I use input-methods for inserting my frequently used unicode characters. But sometimes I need to manipulate occasional unicode characters. I saw in some buffer something like (like ¡, ƒ, ≠, ...) and I would like to change them, to insert elsewhere, etc. In these situation I do not necessarily know the the name or the code of this characters and the ability to easily copy them would be handy tool. – Name Aug 7 '15 at 11:35
  • @lawlist Thanks, If there isn't another way to do it with the standard shortcuts provided by Emacs your alternative solution would be fine. I would preferred to use the built-in shortcuts in order to do it in every machine. – Name Aug 7 '15 at 11:50
0

but I am looking for a standard shortcut

I'm afraid there's not one for such a purpose, but you can adapt standard ways. For example:

get it into kill-ring and then re-use as shown by lawlist above

I've used C-/ as my shortcut key. This is useful for only the last character. What if you frequently use a handful of unicode characters?

Then you can saves to registers beforehand for all the unicode characters you want and then restore from registers as needed. This can be very fast and convenient if you especially need to use multiple machines and don't have much time for configuration.

  • The comments can get deleted any time and that would make your answer incomplete. It would be a good idea to copy the relevant stuff from the comment, making your answer all-inclusive. – Kaushal Modi Oct 6 '15 at 20:45
0

C-SPC C-f C-insert does the same thing with more keychords but less modifier shuffling.

I'm struggling to see why you're using this so much:

  • For characters that you use often, set up a suitable input method.
  • For characters that you use rarely, there's insert-char, bound to C-x 8 RET by default (but a good candidate for a simpler binding such as C-c c or f8 if you use it often). Inserting a recently-inserted character again is easy by navigating the history.
  • For whole words, you can use M-@ M-w.
  • For whole words that start with something easy to type, there's M-/ and C-M-/ (dynamic abbrevs).
  • I have explained the motivations in the original post and in the comments above. – Name May 4 '16 at 5:40

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.