For all text editor or application I'm using, I want to select a word under cursor using keyboard shortcut.
How can I do it? I tried look around I didn't find anything helpful.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIn vim
, viw
(view inside word) enters visual mode and selects the word under the cursor, though in vi
typical usage pattern, you'd rather do things like diw
(delete inside word), or ciw
(change inside word) to change it rather than first select it and do something on it.
Change w
to W
to switch to whitespace delimited words, i
to a
(view a word) to also include the surrounding whitespace in the selection.
Replace iw
/aw
with 2iw
/2aw
to select two words, etc.
You can also always use b
to move to the start of the word and then to ce
, de
, ve
to change/delete/view up to the end of the word or cw
, dw
, vw
to the word (similar kind of distinction as in between iw
and aw
). Those (as opposed to iw
/aw
which are vim
extensions) are standard vi
operators.
Run :h iw
or :h aw
or more generally :h motion.txt
for details on those motion operators.
That's also available in the line editor of the zsh
shell, when in vi
mode (bindkey -v
to switch to vi
mode from the emacs
mode).
There’s no universal single shortcut to do this, however many applications support shortcuts to move the cursor while tracking word boundaries, and select. Using arrow-based key combinations, you should find that Ctrl ← will move to the start of the current word (or the previous word, if the cursor is already at the start of the current word), and then Ctrl Shift → will select the current word.
Some applications use different shortcuts for the above. For example, Emacs supports the arrow-based key combinations now, but historically Emacs users would use Meta B (M-b
), Ctrl Space (C-SPC
), and Meta F (M-f
).