ide – Highlight entire word in R Studio, including backticks, underscores, and other special characters

I’m a heavy keyboard shortcut user (I loathe using the mouse when editing code especially). In R Studio one of the things I often want to do is highlight and select an entire variable name. When the variable name consists of just letters and/or underscores and/or periods, I can easily highlight to select an entire variable name by simply pressing Ctrl+Shift+{RA} or Ctrl+Shift+{LA} on a Windows PC, where {RA} is the right arrow key and {LA} is the left arrow key. The R Studio Keyboard Shortcuts menu refers to these two shortcuts as “Select Next Word” and “Select Previous Word,” respectively. For example, if I want to highlight the variable name var2_attribute in the code below:

Example 1

example1 <- var2_attribute

I simply move my cursor to the left of the “v” in var2_attribute, press Ctrl+Shift+{RA} and the entire variable is selected as desired and shown below.

enter image description here

However, if I encounter a variable that has some non-standard characters in it like a backtick, or a curly brace, and I attempt to use the same keyboard shortcut to highlight the entire variable, only portions of the variable are highlighted (up to the special characters, typically). So if I want to highlight the entire word, I have to press Ctrl+Shift+{RA} several times until I reach the end of the variable name that I’m highlighting. For example, when I attempt to highlight the entire variable `an_example_var` including the backticks, using Ctrl+Shift+{RA} after placing my cursor to the left of the left-most backtick, only the first backtick is initially highlighted. When I press the Right Arrow key again, the middle portion of the variable name, an_example_var is highlighted, and when I press the Right Arrow key again, the entire variable name is selected (what I was hoping to achieve with a single keyboard shortcut, rather than three sequential keystrokes of Ctrl+Shift+{RA}). The images below show this behavior in two separate examples that highlight (pun intended) my frustration:

Example 2

  • First Keystroke Combination:

enter image description here

  • Second Keystroke Combination:

enter image description here

  • Third Keystroke Combination:
    enter image description here

Example 3

  • First Keystroke Combination:
    enter image description here

  • Second Keystroke Combination
    enter image description here

  • Third Keystroke Combination
    enter image description here

  • Fourth Keystroke Combination
    enter image description here

  • Fifth Keystroke Combination
    enter image description here

Note in Example 3, when I press the fifth and final keystroke combination, the highlighting actually overshoots the second double-quote and highlights the final parenthesis, when I was thinking from a logical standpoint, it would stop at the final closing double-quote.

ASK: Is there any way to change my settings or add a keyboard shortcut that will highlight and entire valid R variable name (typically when white space or a second backtick is encountered if the variable name has spaces surrounded by backticks)? If so, could you provide some brief instruction on how I might go about setting this up? It seems a bit tedious for me to have to press the keyboard shortcut five times to highlight a single variable name (and even then it’s overshooting my intended highlight).

Read more here: Source link