How do I replace a word under the cursor?
ciw
The ciw command deletes the inner word under the cursor and drops you into insert mode so you can type a replacement.
26 results for "ciw"
ciw
The ciw command deletes the inner word under the cursor and drops you into insert mode so you can type a replacement.
ciw + new text + Esc, then n.
The ciw command followed by new text, combined with and .
cw vs ciw
The cw and ciw commands both change a word, but they behave differently depending on cursor position.
editing #editing #text-objects #motions #normal-mode #productivity
yiww"_ciw\<C-r>0\<Esc>
When you are doing repetitive refactors, cw is fast but it overwrites the unnamed register with the replaced text.
ciw""<Esc>P
Vim doesn't have a built-in "surround" operator, but you can wrap any word in quotes or brackets with a short sequence: ciw""P.
editing #editing #text-objects #normal-mode #productivity #surround
:set iskeyword+=-
By default, Vim treats hyphens, dots, and many punctuation characters as word boundaries.
iW vs iw
Vim has two flavors of the "inner word" text object that are easy to confuse: iw (lowercase) and iW (uppercase).
qq;.q then @q or @@
The dot command (.
:let @q then use in nnoremap
Macros are stored in registers as plain keystroke strings.
let @q = 'keystrokes'
Macros recorded with q{register} are stored in registers and lost when Vim exits.
:let @q = 'commands'
Macros in Vim are just text stored in named registers.
ce
The ce command changes from the cursor position to the end of the current word.
diw
The diw command deletes the inner word under the cursor.
qaciw"<C-r>""<Esc>wq
This macro wraps the current word in double quotes by changing the word, inserting quotes around the original content, and moving to the next word.
:setlocal iskeyword+=-
The iskeyword option defines which characters are part of a "word" for motions like w, b, e, , and text objects like iw.
mzgUiw`z
When you run an operator like gUiw, Vim can leave your cursor in a slightly different place than where you started.
w vs W, b vs B, e vs E
Vim distinguishes between "words" (sequences of keyword characters) and "WORDS" (sequences of non-blank characters).
.
The .
yyp
The yyp command duplicates the current line by yanking it and immediately pasting it below.
:let @q = "dwelp"
Recording macros with q works well for simple sequences, but complex macros with special keys can be hard to get right in one take.