92

Is there a shortcut or a command to select word under cursor in Sublime Text or Atom? I want a replacement for double-click. So I could press shortcut instead and get selection on a current word and start typing to replace it or get in quotes etc...

firedev
  • 20,898
  • 20
  • 64
  • 94

5 Answers5

156

command+d on OSX

control+d on Windows/Linux

You can find all the default keybindings by going to Preferences > Keybindings - Default and perusing the list.

phuclv
  • 37,963
  • 15
  • 156
  • 475
Liam Cain
  • 13,283
  • 5
  • 39
  • 29
  • 6
    Inaddition to select a word. You can select the words enclosed in quotes with **SHIFT + CMD + SPACE** . It does more, check **Selection -> Expand selection to scope** – palaniraja Jul 30 '12 at 09:00
  • 2
    Great, I was under impression you have to select the word first for Cmd-D to work. – firedev Aug 06 '12 at 18:49
18

You can add a key binding to select the word:

{ "keys": ["ctrl+shift+w"], "command": "expand_selection", "args": {"to": "word"} }

Unlike the find_under_expand command (control+d by default) repeated presses won't add cursors at matching words.

CodingWithSpike
  • 42,906
  • 18
  • 101
  • 138
  • 1
    Thanks for this! This was nagging me for years, that you don't always want `Ctrl+d` to select next word, but sometimes to just expand the selection to the whole word from its part. – certainlyakey Apr 29 '16 at 07:19
10

install ExpandRegion if you want to expand the selection:

  • Expand selection to word
  • Expand selection to quotes (content only)
  • Expand selection to quotes (with quotes)
  • Expand selection to complete self closing tag
  • Expand selection to parent node content
  • Expand selection to complete node
  • Expand selection to parent node content

enter image description here

alwe
  • 1,485
  • 17
  • 22
5

I looked around for this and eventually came up with this, which I assigned to ctrl-F

you need to paste it into a new user plugin python file

import sublime, sublime_plugin

class find_under_cursor(sublime_plugin.WindowCommand):
    def run(self):
        view = self.window.active_view()
        view.run_command("expand_selection", {"to": "word"}) 
        view.run_command("slurp_find_string")
        self.window.run_command("show_panel", {"panel": "find", "reverse": False} )
MikeSmithDev
  • 15,731
  • 4
  • 58
  • 89
bins
  • 61
  • 2
  • 3
2

With Vim bindings (Vintage or vintageous)

* - to find next
# - to find last
For both, all matches are highlighted

Without Vim bindings

For current file: CMD+E, CMD+F, Enter
Explanation:
CMD+E - copies the word under cursor
CMD+F - bring up find in local file dialogue
Enter - er you know what this means

Substitute CMD+F for CMD+SHIFT+F to find in all files in project (or whatever search range you specify)

Community
  • 1
  • 1
snowbound
  • 1,692
  • 2
  • 21
  • 29