Is there a faster alternative to using the arrow keys? - keyboard
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?
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 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:
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: 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:
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
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
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
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.
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
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
I have the same pain, I've tried to use hjkl as arrow keys, and some layout like fun plus wsad. But now I have gotten the best solution since I got a Filco Minila-R. It divided space key into three keys, two function on two sides of sapce key. Like when I type right arrow, I hold the left fn key (at the left side of space) with my left hand thumb while touch F key, F key always used for locating for left hand.
e-d-f-s plus left function keys achived up-down-right-left, right function plus jm-k,-l. achived ins del-home end-pu pd.
If I use capslock + hjkl, I have to use two hands, Minila-R layout allows me using one sigle hand to touch this keys, besides, the two functions which devided from space key just at the most fine place for thumb to touch.
Related
Jump to current function declaration from middle of function
Is there a way to jump to the signature of the function my cursor is currently in, then jump back to where I was? For example, when I have a 1000 line function, where the prefix x + y: refers to line numbers, is there a way from me to jump from my cursor location at x + 555 to the signature at x + 0 then back to where I was at (x + 555): x + 000: void theFn(int arg) { x + ...: ... x + 555: /// where my cursor starts x + ...: ... x + 999: } And, yes, I couldn't agree with you more that there shouldn't be 1000 line functions. Also, is there a way to automatically jump to the end of function without being at the opening bracket of the function?
Useful motions in such case are [[, ][ and <C-o>. As we can read in help: *[[* [[ [count] sections backward or to the previous '{' in the first column. |exclusive| Note that |exclusive-linewise| often applies. *][* ][ [count] sections forward or to the next '}' in the first column. |exclusive| Note that |exclusive-linewise| often applies. *CTRL-O* CTRL-O Go to [count] Older cursor position in jump list (not a motion command). {not available without the |+jumplist| feature} In short: [[ to got to the beginning <C-o> to go back to previous place ][ to go to end Those motions will have the desired effect only when braces are in the first column, but from your example seems like this requirement is not met. In such case at the end of :h section we can read: If your '{' or '}' are not in the first column, and you would like to use "[[" and "]]" anyway, try these mappings: > :map [[ ?{<CR>w99[{ :map ][ /}<CR>b99]} :map ]] j0[[%/{<CR> :map [] k$][%?}<CR> Unfortunately, Vim doesn't offer better solution as it doesn't parse syntax. It may change though as Neovim experiments with Tree-sitter. It also wouldn't be surprising if there was a plugin which provides better support for such motion. Tagbar could fit this role: Toggle Tagbar window Switch to it Cursor should be already over the current tag Press enter Toggle window You are at beginning of the function Use <C-o> to get back I also once found and had in my config a mapping which could also be useful in such case: nnoremap <Leader>gd ?\v%(%(if|while|for|switch)\_s*)#<!\([^)]*\)\_[^;(){}]*\zs\{
Linux keyboard config (xkb) for three Shift keys
I am looking for a way to define an additional Shift key, for a given key scan code. So that I would end up with unchanged left and right shift, plus an extra shift key, which would be definable on any existing key (assuming I know its scan code). In xkb/keycodes, I see shift keycodes defined for: <LFSH> <RTSH> But if I was to add a third entry here, I don't know I'd tell xkb that it was also to be considered a Shift key. (This is not relevant to the question, but in case you wondered, the use case is for some keyboards which have a split spacebar, where I would like to set one of the spacebar halves to be the extra Shift). Interested on what xkb configuration I would need for this?
Perhaps you can do this using xmodmap, if you rename the keycode to keysym Shift_L, and add the Shift_L back into the modifier map. Eg for keycode 110: xmodmap -e 'keycode 110 = Shift_L Shift_L Shift_L Shift_L' xmodmap -e 'add shift = Shift_L Shift_R' Find the keycode by looking through xmodmap -pke or using xev or similar.
I have now found a way to achieve the above directly in xkb configuration, without the need to use xmodmap. STEP ONE: In the xkb/symbols/pc file, note the following is already defined: key <LFSH> { [ Shift_L ] }; key <RTSH> { [ Shift_R ] }; So, what is required as to add a new key definition for MDSH (ie "mid shift"): key <MDSH> { [ Shift_L ] }; STEP TWO: Assign these keys to the keycodes. In xkb/keycodes/evdev, left and right shift are already defined: <LFSH> = 50; <RTSH> = 62; So all that remains to add an extra definition for MDSH: <MDSH> = XXX; where XXX is the keycode you want to assign.
How to select words from inside current word and backwards in vim
I've had some fun learning vim, but have encountered a problem. While it's fairly straightforward to select from inside the current word and forward (v + iw + w +w + ...), and backwards (v + b + b + ... or v + ge + ge + ...). (This question describes that process quite well: In Vim/Vi, how do you move the cursor to the end of the previous word? ). I know one solution is to move the marker to the end of the word before beginning the selection, but it seems less elegant than just including the entire word the cursor is in in the selection (like you can with iw when going forward (I think what I'm asking for is a sort of ib or modifier key to make w cycle backwards without making custom aliases)). Is it possible or am I just being unreasonable? Sorry for the messy formatting.
You are looking for viwo + b + b + b
How can I make vim to format matrix side by side
I am using vim to log a lot of my day-to-day work. I usually have a lot of results with matrix. When I paste those at the end of the day I have pages of (sometimes) 0ne or 2 columns matrix My question is how can I ask vim to programatically format this: R) DT = data.frame(x=rnorm(6),y=rnorm(6)) R) DT x y 1 -0.0007499 0.7661 2 1.5559552 -0.6664 3 0.2082094 -0.1598 4 -0.1684766 -0.0536 5 3.1014233 -0.7439 6 0.1985104 2.0415 R) DT2 = data.frame(x=rnorm(7),y=rnorm(7)) R) DT2 x y 1 -0.005116 -0.4388 2 2.317381 0.6597 3 0.359883 0.4770 4 -1.426220 0.4911 5 0.468820 -0.3260 6 0.626147 -0.6254 7 -1.086660 2.1973 to this: side by side R) DT = data.frame(x=rnorm(6),y=rnorm(6)) R) DT2 = data.frame(x=rnorm(7),y=rnorm(7)) R) DT R) DT2 x y x y 1 -0.0007499 0.7661 1 -0.005116 -0.4388 2 1.5559552 -0.6664 2 2.317381 0.6597 3 0.2082094 -0.1598 3 0.359883 0.4770 4 -0.1684766 -0.0536 4 -1.426220 0.4911 5 3.1014233 -0.7439 5 0.468820 -0.3260 6 0.1985104 2.0415 6 0.626147 -0.6254 7 -1.086660 2.1973 EDIT: Thanks everybody, Kent solution worked, strangely before set ve=all my C-Q did not allow to select a block like ############ ############### ######### ######### ######### I couldn't reach the last column of the second line (using gvim on win XP). Now works very well I'll also use Ingo Karkat plugin"
try following steps: :set ve=all move cursor to beginning of line R) DT2 = data.frame(x=rnorm(7),y=rnorm(7)) press C-V, then using motion magic to select the 2nd block press d move cursor to the first line, the position you want to paste the 2nd block. type p if your text is always like that format, you could try this mapping: :nnoremap <leader>mt :let &ve='all'<cr>gg/^R)<CR>n<c-v>G$dgg$3lp then you could in normal mode type <leader>mt to do the transformation. NOTE I have no experience of vim on windows... so you may have to change the mapping for windows blockwise selection. <C-Q> ? not sure. I assume the first line of the file is R)... this will paste the 2nd block to the position: 3 spaces after the end of 1st line, change the number 3 in mapping if you want to adjust it
The key to this is blockwise visual mode. Go to the beginning of the second block (what should become the right column next to the first block), press Ctrl+V (on Windows, this is often remapped to Ctrl+Q), create the selection with $ and jjj. . ., then delete with d. Then go to the first line of the first block, $ to go to the end of line, (optionally append padding whitespace), then paste with p . The second block should be pasted to the right of your cursor. Finally, you can delete the empty lines left where the second block was. My UnconditionalPaste plugin simplifies this task: You can then simply delete the second block with dd or Vjjj. . .d, and force a paste in blockwise mode with the plugin's gdp mapping. If you find a way to determine the size of the blocks (the } key, which jumps to the next empty line, may come handy here), you can then put all of the steps into a custom mapping.
How to setup Super/Windows/mod4 key bindings for eclipse
I'd like to setup some key bindings in eclipse (3.7.2) involving the key ("windows" key), but it doesn't seem to be picking up that modifier key when I press it. Why? What can I do so it detects it?
You have "linux" tagged in your question, so I'll assume you're using Linux and X ... So, to use Super with Eclipse, first you have to discover whether you have a Super, and if not, make one. The rest of this is probably way more than you need on the subject of xmodmap. The first thing to do is see if you already have a Super modifier key. Run "xmodmap -pm" to see what your modifiers currently are. Here's a common output: $ xmodmap -pm xmodmap: up to 4 keys per modifier, (keycodes in parentheses): shift Shift_L (0x32), Shift_R (0x3e) lock Caps_Lock (0x42) control Control_L (0x25), Control_R (0x69) mod1 Alt_L (0x40), Alt_R (0x6c), Meta_L (0xcd) mod2 Num_Lock (0x4d) mod3 mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf) mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb) In the output above, a bunch of keys are already mapped to Super, with (hex) keycodes 0x85, 0x86, 0xce, and 0xcf. To see if anything on your keyboard happens to be one of those keys (which isn't always the case), run "xev" in a terminal and move your mouse pointer into "xev"'s mostly-white input window, and try different keys. Typical output looks like this for keys (try control and shift to see examples) - pay particular attention to the third line with the keycode and keysym name, here 64 and Meta_L. Be sure to try your "Windows" key too, to see what keycode and mapping it has currently. KeyPress event, serial 42, synthetic NO, window 0xe600003, root 0x6b6, subw 0x0, time 2232472454, (-1,167), root:(871,683), state 0x0, keycode 64 (keysym 0xffe7, Meta_L), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False Find the "keycode" part and covert it to base 16. If you've hit one of the Supers, your converted code will match one of the (in the example above, four) hex keycodes, and show Super_L or Super_R instead of the Meta_L shown above. If you don't have any keys mapped to Super, or it turns out that none of them exist on your keyboard, then use xev to find the keycode for the key you want to use for Super (CapsLock might be a good choice for some folks), then use xmodmap or some other tool in your desktop's UI to set it up. The latter is outside of the scope of this reply, but with xmodmap, you could just make a file named .Xmodmap in your home directory with this in it: ! note: replace the 0xff below with your *actual* Super_L key's keycode. ! note: whether to use mod3 or mod4 depends on your environment. keycode 0xff = Super_L clear mod4 add mod4 = Super_L Apply the results with "xmodmap ~/.Xmodmap". Many X startups will automatically apply these for you. If you're using Ubuntu Unity, look up Startup Applications in the Dash and add one for that same command. I'm not sure if "~" works in the context, you might want to try $HOME or just use your home directory there. It ends up producing a file in ~/.config/autostart/xmodmap.desktop like this one (erlkonig = me; put your home in instead): $ cat ./.config/autostart/xmodmap.desktop [Desktop Entry] Type=Application Exec=/usr/bin/xmodmap /home/erlkonig/.Xmodmap Hidden=false NoDisplay=false X-GNOME-Autostart-enabled=true Name[en_US]=Xmodmap Keymap Settings Name=Xmodmap Keymap Settings Comment[en_US]=Set Keyboard Bindings Comment=Set Keyboard Bindings You can verify the results with "xmodmap -pm" or "xev". Here's the output for the former for my environment from a more complex setup (which probably won't match what you'd want yourself). $ xmodmap -pm xmodmap: up to 4 keys per modifier, (keycodes in parentheses): shift Shift_L (0x32), Shift_R (0x3e) lock Caps_Lock (0x7f) control Control_L (0x25) mod1 Meta_L (0x40), Meta_L (0xcd) mod2 Alt_L (0x6c), Alt_L (0xcc) mod3 Super_R (0x69), Super_L (0x85), Super_R (0x86), Super_L (0xce) mod4 Hyper_L (0x42), Hyper_L (0xcf) mod5 Num_Lock (0x4d) Hyper replaces CapsLock (which I've moved elsewhere); I use it for window manager functions, like Hyper-f to "front" a window, Hyper-r to resize, etc. For another random(ish) example of what you can with xmodmap, here's a keymap that map whatever keycode 78 is to Mode_switch, and then allow you to combine it with ', ", `, and ~ to enter prefixes that make your next vowel have the similar diacritic on them. You can also use the Mode_switch with a to get æ, d to get ð, ? to get ¿, and some others. ! note: 78 is probably not the keycode most would want here; pick your own :-) keycode 78 = Mode_switch ! no mods shift mode-switch shift+mode-switch keysym a = a A ae AE keysym d = d D thorn THORN keysym n = n N ntilde Ntilde keysym o = o O oslash Oslash keysym t = t T eth ETH keysym s = s S ssharp keysym 0 = 0 parenright degree keysym 6 = 6 asciicircum dead_circumflex keysym 8 = 8 asterisk multiply keysym apostrophe = apostrophe quotedbl dead_acute dead_diaeresis keysym grave = grave asciitilde dead_grave keysym comma = comma less dead_cedilla guillemotleft keysym period = period greater NoSymbol guillemotright keysym slash = slash question NoSymbol questiondown keysym 1 = 1 exclam NoSymbol exclamdown keysym equal = equal plus notequal plusminus for more information use "man xmodmap".
Eclipse does not hook the Windows key. The only thing you can do is use a tool to rebind the windows key to, for example, CTRL+ALT+SHIFT (if you don't use that). Tools like AutoHotkey may do the job. Then, whenever you press the windows key, it will be as if you pressed CTRL+ALT+SHIFT, which you can then use to bind your desired hotkeys.
I suspect your core goal is to create key bindings in addition to your existing control and alt bindings. So, for example, have Windows-L do something different from Control-L, Alt-L or Shift-L. Unfortunately, it seems that Eclipse on linux doesn't support modifiers beyond shift, control, and alt (which is mod1 in xmodmap). So there is no additional modifier for you map the Windows key to. The logical choice would be mod4, but it seems SWT doesn't support mod4 on non-Windows platforms. There is a bug for adding non-windows mod4 support at https://bugs.eclipse.org/bugs/show_bug.cgi?id=55236. Unfortunately it's been marked "won't fix" for a while. I suggest going there and voting for it and sharing additional user cases/reasons for reopening it if you have them.