Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a faster alternative to using the arrow keys?

I regularly code in R, and I just realized how much of a pain it is for me to move my hand down to the arrow keys and then back to they letters on the keyboard. In Rstudio, I have to do this regularly because the studio completes certain synax automatically, (like parentheses and quotation marks) and then I have to press the arrow key to move out of the parentheses (or quotation marks), this then removed any possible advantage from having R complete the syntax for me. This is extra costly for me because I'm left handed. Is there a shortcut for the arrow keys that's closer to the letter keys?

like image 984
steve zissou Avatar asked Aug 04 '17 14:08

steve zissou


People also ask

How can I make my arrow keys faster?

If you hold the "Ctrl" key down, and then "hold down" the Right arrow key or the Left Arrow key, the cursor will jump quickly from word to word. This is even faster than holding an arrow key down without the Ctrl key.

Can I use WASD instead of arrow keys?

Fortunately, on most keyboards, you can toggle between the standard-setting and the alternate key setting by pressing FN + W keys. If that doesn't work, here are a couple of other key combinations that are known to disable the alternate keys settings: FN + Windows key.


2 Answers

Intro

To do this, you have two approaches in front:

  1. use your own code
  2. use 3rd party softwares

In these answer I introduce the most efficient and easy approach so for some OSs it's easy and efficient to write your own code while in others it's not really efficient and need a harsh work which have no achivement but wasting time

Windows users

In this method you will use:

  • alt+I instead of
  • alt+K instead of
  • alt+J instead of
  • alt+L instead of

In order to use this feature, these are the steps in your way:

  1. Download and install autohotkey
  2. Right-click in your desktop area then go to new and make a new "notepad" file
  3. Open empty notepad file and copy/paste codes below into that
  4. Rename your notepad file eveything you want but with *.ahk format
  5. Click your file to run your script

Now you can enjoy and never use arrow keys again...

; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; AHK Command       ; key   = Effect        (Description)

; ALT Keypress Implied for all below

!i::Send {UP}       ; i UP          (Cursor up line)
!k::Send {DOWN}     ; k DOWN            (Cursor down line)

!j::Send {LEFT}     ; j LEFT        (Cursor left one character)
!l::Send {RIGHT}    ; l RIGHT       (Cursor right one character)

!h::Send {HOME}     ; h     ALT + RIGHT (Cursor to beginning of line)
!;::Send {END}      ; ; ALT + LEFT  (Cursor to end of line)

!u::Send ^{HOME}    ; h     SHIFT + HOME    (Cursor to beginning of document)
!o::Send ^{END}     ; o SHIFT + END (Cursor to end of document)

; CTRL + ALT Keypress Implied for all below

!^j::Send ^{LEFT}   ; j     CTRL + LEFT (Cursor left per word)
!^l::Send ^{RIGHT}  ; l CTRL + RIGHT    (Cursor right per word)

; SHIFT + ALT Keypress Implied for all below

!+i::Send +{UP}     ; i SHIFT + UP  (Highlight per line)
!+k::Send +{DOWN}   ; k SHIFT + DOWN    (Highlight per line)

!+j::Send +{LEFT}   ; j SHIFT + LEFT    (Highlight per character)
!+l::Send +{RIGHT}  ; l SHIFT + RIGHT   (Highlight per character)

!+h::Send +{HOME}   ; h SHIFT + ALT + LEFT  (Highlight to beginning of line)
!+;::Send +{END}    ; ; SHIFT + ALT + RIGHT (Hightlight to end of line)

!+u::Send ^+{HOME}  ; u SHIFT + CTRL + HOME (Highlight to beggininng of document)
!+o::Send ^+{END}   ; o SHIFT + CTRL + END  (Hightlight to end of document)

; SHIFT + CTRL + ALT Keypress Implied for all below

!+^j::Send +^{LEFT}     ; j SHIFT + CTRL + LEFT (Highlight per word)
!+^l::Send +^{RIGHT}    ; l SHIFT + CTRL + RIGHT    (Hightlight per word)

!+^i::Send +!{UP}   ; i SHIFT + ALT + UP    (Multiply cursor up)
!+^k::Send +!{DOWN} ; k SHIFT + ALT + DOWN  (Multiply cursor down)

; CTRL + SHIFT Keypress Implied for all below

+^i::Send +^{UP}
+^k::Send +^{DOWN}

Important Notes

To use autohotkey script which you made, every time you turn on computer instead of clicking on your script every time, you can copy your script in startup folder.

How to find startup folder?

  1. win+R
  2. type: shell:startup
  3. copy your script into that Folder

MacOS users

In this method you will use

  • option+I instead of
  • option+K instead of
  • option+J instead of
  • option+L instead of

Use hammerspoon: Is a tremendous tool for many purposes (not just assign a keybinding, for example you can use it for windows sanping or ...) and I think that is one of the MUST-HAVE tools in any macos

Since the documentation of hammerspoon is very very straightforward, I just put the code here and you can install and config hammerspoon from it's Getting Started with Hammerspoon

hs.hotkey.bind({"alt"}, "I", function()
  hs.eventtap.keyStroke({}, "up")
end)
hs.hotkey.bind({"alt"}, "K", function()
  hs.eventtap.keyStroke({}, "down")
end)
hs.hotkey.bind({"alt"}, "J", function()
  hs.eventtap.keyStroke({}, "left")
end)
hs.hotkey.bind({"alt"}, "L", function()
  hs.eventtap.keyStroke({}, "right")
end)

Important Notes

If you think hammerspoon is slow or not working as genius as you want another option is Karabiner

Debian-based Linux users (not Ubuntu; see important notes):

In this method you will use:

  • CapsLock+I instead of
  • CapsLock+K instead of
  • CapsLock+J instead of
  • CapsLock+L instead of

and

  • alt_gr instead of CapsLock

How? Well:

  1. open up Terminal, write your keyboard layout on in a file(I named it modmap), then open that file and edit it as you will follow next steps:

    xmodmap -pke > modmap
    gedit modmap
    
  2. change keyCode 108 (alt_Gr/ISO_Level3_Shift) value, so it should be like this after modifying:

    keycode 108 = Caps_Lock Caps_Lock Caps_Lock Caps_Lock Caps_Lock Caps_Lock
    
  3. change keyCode 66 (CapsLock) value, so it should be like this after modifying:

    keycode  66 = Mode_switch Mode_switch Mode_switch Mode_switch Mode_switch Mode_switch
    
  4. change keyCode 31 (i) value, so it should be like this after modifying:

    keycode  31 = i I Up NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol
    
  5. change keyCode 44 (j) value, so it should be like this after modifying:

    keycode  44 = j J Left NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol
    
  6. change keyCode 45 (k) value, so it should be like this after modifying:

    keycode  45 = k K Down NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol
    
  7. change keyCode 46 (l) value, so it should be like this after modifying:

    keycode  46 = l L Right NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol
    

Important Notes

  1. xmodmap is no longer used/supported on Ubuntu (because it wasn't handy for many users, I think they stop using xmodmap from 2013) but since this is a professional question for very fast coding and working with computer and also coding, I see many professionals using Debian or their own debian-based Linux (not Ubuntu) and they always prefer native solutions to plugins or... Anyway if you are using Ubuntu you can use xkb or gnome tweak tools where you maybe can adjust your keyboard mapping in a GUI

  2. You can't use this solution easily if you got multi langs/inputs on your keyboard, but you can use it like below:

    • CapsLock+shift+i instead of
    • CapsLock+shift+k instead of
    • CapsLock+shift+j instead of
    • CapsLock+shift+l instead of

for example, if you also want to have persian_language_input you can do step 1,2,3 above then change other steps like below:

keycode  31 = i I Arabic_heh Up 5 6 7 8
keycode  44 = j J Arabic_teh Left 5 6 7 8
keycode  45 = k K Arabic_noon Down 5 6 7 8
keycode  46 = l L Arabic_meem Right 5 6 7 8

be careful that you shouldn't test above keyboard shortcuts in Terminal

  1. Since we're using xmodmap tool (because it's native unlike xkb), You can only change the AltGr keysyms for keycodes that are already using AltGr. So we change it with CapsLock to overcome this problem since CapsLock is more comfort for fingers to find it is a very acceptable solution.

  2. In most cases, alt_Gr is the right alt Key on your keyboard

further reading about xmodmap on ArchWiki

if anyone has knowledge about this answer in BSD OS (or BSD-BASED) I'll appreciate that if he/she add it to my answer

like image 52
kia nasirzadeh Avatar answered Oct 10 '22 23:10

kia nasirzadeh


Two weeks back Microsoft launched "Power Toys" in the Microsoft Store. You can use the keyboard manager to create a shortcut for arrow keys as mentioned in answer. I use the vim shortcut for arrow keys as shown below:

[added shortcuts for arrow keys][1] [1]: https://i.stack.imgur.com/F9syJ.png

like image 1
Suhas Avatar answered Oct 10 '22 22:10

Suhas