Question: How do I replace current word under cursor in Emacs? 

I know that I can use query-replace or replace-string but every time I do so I have to type entire string to be replaced, this is just annoying. 

Vi has equivalent command cword and I can use a shortcut to pull the word under cursor for replacement:

```
nmap <leader>z :%s#\<<C-r>=expand("<cword>")<CR>\>#

```

Anybody know how to do it with Emacs?

Answer: 
I was struggling and wanting the same thing since move from Vim to Emacs.

After some research and experimenting, I came up the function below which allow you to do the same thing with Evil package installed or using spacemacs.

It also works with region active (or visual selection in vim term) and that can be quite useful to replace word like abc-def-hij:

```
; replace current word or selection using vim style for evil mode
(defun evil-replace-word-selection()
(interactive)
(if (use-region-p)
    (let (
            (selection (buffer-substring-no-properties (region-beginning) (region-end))))
        (if (= (length selection) 0)
        (message "empty string")
        (evil-ex (concat "'<,'>s/" selection "/"))
        ))
    (evil-ex (concat "%s/" (thing-at-point 'word) "/"))))

```

then in your init.el, define the same key binding:

```
(global-set-key (kbd "\C-co") 'evil-replace-word-selection)

```

keybinding is slightly different from vim one which is "space z" but I haven't figure out how to map that in emacs when evil mode is there. keep complaining not a prefix etc and I'm relatively new to emacs. But still not too bad and myself is happy with this solution at the moment.
This snippet expands on the answer by Emanuel Berg, to:

* display the selected string to be replaced;
* use symbol rather than words, which gives me better results in Python code (or generally `superword-mode`).

```
(defun query-replace-at-point (old new)
  "Invoke `query-replace', valuing OLD to symbol at point, replacing it with the input NEW."
  (interactive
   (let* ((old-symbol (symbol-name (symbol-at-point)))
          (new-symbol (read-string (format "Rename %s to: " old-symbol) old-symbol)))
     (list old-symbol new-symbol)))
  (query-replace old new))

```