问题
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?
回答1:
INTRO:
to do this you have two approaches in front:
- use your own code
- use 3rd party softwares
in these answer i introduce the most efficient and easy approache so for some OSs it's easy and efficient to write your own code while in others its 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:
- download and install autohotkey
- right-click in your desktop area then go to new and make a new "notepad" file
- open empty notepad file and copy/paste codes below into that
- rename your notepad file eveything you want but with *.ahk format
- 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 ?- win+R
- type: shell:startup
- 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
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 genious 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
♣and How? well:
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
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
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
change keyCode 31 (i) value, so it should be like this after modifying:
keycode 31 = i I Up NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol
change keyCode 44 (j) value, so it should be like this after modifying:
keycode 44 = j J Left NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol
change keyCode 45 (k) value, so it should be like this after modifying:
keycode 45 = k K Down NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol
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 theit own debian-based linux (not Ubuntu) and they always prefer native solutions instead of 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
3- 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.
4- in most cases alt_Gr is the right alt Key on your keyboard
further reading about xmodmap: ArchWiki - xmodmap
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
来源:https://stackoverflow.com/questions/45509922/is-there-a-faster-alternative-to-using-the-arrow-keys