AltGr key in Sublime Text 2 on Linux - linux

Is it possible to bind the AltGr key in Sublime Text 2 on Linux as a modifier?
In Windows one can use "keys": ["ctrl+alt+<some_key>"].
How would i do this in Linux as "keys": ["altgr+<some_key>"] doesn't work.

Look like altGr work as ctrl+alt on windows, both shortuct does the same thing on my keyboard.
As exemple : altGr + E type '€' and ctrl + alt + e type '€' too (french keyboard layout)

I don't believe so. The list of modifier keys in the docs only has Ctrl, Alt, Shift, and Super (Win/Cmd). AltGr is not addressable on its own through Sublime keymaps.

The best way I've found to get around this is to add a key binding for the character altGr + any-key produces. Won't work for all combinations since not all keys produce a character with altGr, but should work for those that do.
e.g { "keys": ["ł"], "command": "insert", "args": {"characters": "L"} } would insert L for the key combination altGr + L (given ł is produced by that combo on your setup)

Related

Matching square brackets in vim

I am aware of the shortcut for flower braces i.e. Having cursor over { and pressing ]} gets me to the corresponding }. How to do the same for matching square brackets? []
In normal mode, try
vi[oh
vi[ should visually select the entire block between [], and o switch cursor to the front of visual selection, then h moves cursor onto [.
At the expense of more keystrokes, this works in more cases than % where you must hover over the bracket.

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\{

How to multi-line the import functions in {} in VIM?

Sorry for the bad title but
With this code,,,
import { amethod, methodb, methodc } from '../../utils/mockData';
how do you make this
import {
amethod,
methodb,
methodc
} from '../../utils/mockData';
with VIM? I mean how can I do it fast?
What I do is to
go to the first method.
press Enter
go to the end of the method..
press Enter...
go to the second method.
6....
...
It's so slow with VIM. Can we do this fast in VIM? I think I can this much faster with my mouse :(
import { amethod, methodb, methodc } from '../...';
^
f ;r<CR>;.;.;.
doesn't strike me as particularly slow. A tad too repetitive, maybe?
Here is a slightly smarter (but probably not that smart) approach:
ciB " change in brackets
<CR><CR> " insert two carriage returns
<Up> " move up one line
<C-r>" " insert previous content of brackets
<Esc> " leave insert mode
:s/,/,\r/g<CR> " put each symbol on its own line
=iB " re-indent the content of brackets
that can be mapped for convenience:
nnoremap <key> ciB<CR><CR><Up><C-r>"<Esc>:s/,/,\r/g<CR>=iB
Or you can look for a proper plugin that handles corner cases gracefully.
#romainl had a good answer, but you can also use replace for this particular case:
:%s/\([,{]\)/\1\n/g
With the cursor on line1 and col1, you can press this in normal mode:
f 4#=';r^M'
then press ENTER.
Note: for the ^M you press Ctrl-v then Enter
I have got this
import {
amethod,
methodb,
methodc
} from '../../utils/mockData';
Using this:
:%s/\v\{\zs( \w+,?)+ \ze}/\=substitute(submatch(0), " ", "\n\t", "g")
\v ............ very magic regex (avoid many backslashes)
{ ............ literal {
\zs ........... vim trick that marks the start of the pattern
( ............ start of regex group 1
<Space> ....... literal space inside group 1
\w+ ........... one word or more
,? ........... optional coma
+ ............ quantifier for the group (at least one)
<Space>
\ze ........... end of our vim search
The substitute function has three parts like a normal vim substitution and the submatch(0) corresponds to our regex, hence we are substituting in our regex one space for one line breake and two tabs.

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?
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.

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.

Resources