Autohotkey and Azerty: how to remap §,è,ç,à keys without remapping the numbers? - keyboard

In order to program more efficiently, I want to remap some seldomly used keys on my azerty keyboard §èçà to the more useful []{} (Which otherwise need a Alt-Gr).
I tried a script like this
§::{
è::}
ç::[
à::]
But the problem is that Autohotkey automatically also maps the shifted keys; as such I lose my numbers. Adding the following script does not seem to solve the issue:
+§::6
+è::7
+ç::9
+à::0
Any help how I might remap the "lowercase" letters but not the "uppercase" numbers ?

Try this one:
#If !GetKeyState("LShift") && !GetKeyState("RShift")
§::{
è::}
ç::[
à::]

You could try this:
This looks for a string of one character and the capital C makes it case sensitive. Since I don't own a azerty keyboard, I can't test it.
:?C*:§::{{}
:?C*:è::{}}
:?C*:ç::{[}
:?C*:à::{]}

This works perfectly:
:?C*:§::{{}
:?C*:è::{}}
:?C*:ç::{[}
:?C*:à::{]}
although my version is
:?C*:ù::{[}
:?C*:µ::{]}
:?C*:ç::{{}
:?C*:à::{}}

Related

Single key for dwi or dei in Vim

Is there a single key for doing dwi or dei (Substitute a word) in Vi(m)? I use this enough to warrant saving 2 extra keystrokes.
Run vimtutor
Learn about c. There isn't a single key. c[motion] is the same as d[motion]i.
You do not want a single key for that. Yeah I am serious. That's not how Vim works. Vim is modular. You first think about what you want to do, in your case you want to change something. Then you need to know what you want to change, in your case a word. And voila! cw is the sequence to use.
Of course there is but more to think of. Do you need a word or a WORD? Do you want to change around the word (caw)? And so on.
But the important part is, Vim is not a collection of functions, it is a language to modify text. It is always a chain of actions. Sure you could say, ciw is so common it should have a shortcut, then you can map it. But it will only make Vim harder to use.
Thinking about changing a whole sentence? Yeah, it is cs. The same goes for deleting, or yanking and nearly everything else.
So if you map everything you need often to a single command, instead of a chain of commands like in vanilla Vim, you lose everything which makes Vim better than any other editor and you will end up with a worse Emacs...

Vim navigating the text in insert mode

In Vim, after I wrote this :
int[] no={1,2,3,4,5,6}
I've changed my mind and wanted to make it String like this :
String[] no={"1","2","3","4","5","6"};
It is easy once you move your hands to arrow keys and stay in insert mode. Otherwise you need lots of esc key presses. What is the "Vim way" of doing this?
(there were similar questions, but I think this specific example decently demonstrates the need to an easy way of traversing in insert mode.)
No, you don't need to stay in insert mode for this. One option with built-ins:
0cwString<Esc>:s/\d/"&"/g
Another with the surround.vim plugin (ysh" surrounds the character to the left with double quotes):
0cwString<Esc>f,ysh";;.;;.;;.;;.f}.
I'm sure others come up with many more creative approaches...
Compare this with insert-mode:
0cwString<Esc>f{a"<Right>"<Right>"<Right>"<Right>"<Right>"<Right>"<Right>"<Right>"<Right>"<Right>"<Right>"<Esc>
If the 'easy way of editing in insert mode' you were thinking of was
"<Right>"<Right>"<Right>"<Right>...
you can do that in normal mode, too.
Ready: f{.
Set: a"<Esc>.
Go: <Space>.<Space>.<Space>.<Space>.<Space>....!

How to move cursor to specific word in current line in Vim

Let's say we're currently in this line of code:
readonly L|a|zy<ICountryRepository> countryRepo;
and the cursor is in the position of letter "a", as shown in the code between two "|" symbols.
Now I want to move my cursor to the letter y of the word countryRepo, how can I do that using the minimum key strokes?
(Currently I'm using the key sequence of fyfyfyfy in normal mode ... Kind of stupid)
If you know that it's the 4th y, you can do
4fy
If you know it's the last y in the line, you can do
$Fy
If you don't know at which position it is, you can still do
fy;;;
In this case, I would use
W
to move to countryRepo, followed by
fy
I can think of:
4fy
But you should only do this if you are some strange robot.
/co<cr>fy
Which is one character shorter than your solution, but more easy..
Wfy
Go one WORD forward and then find y.
f>fy
Something like this I would do. Depends on what popups in my mind.
You should look into the easymotion plugin, which helps with arbitrary movements.
EDIT:
easymotion is rather worthless here, it is more useful for jumping to targets further away.
If you have vim-easymotion, https://github.com/Lokaltog/vim-easymotion
You can do <leader><leader>t and then search for letter y. It's not that fast for the letters on the same line though. The real advantage is when you jump in the entire file.
I would do
tR;
or
WtR
or maybe
Wfy
Use EasyMotion.
In your case, <Leader><Leader>e then a corresponding keypress (in this case b) will bring your cursor onto the second y. Personally I use <Leader> as the easymotion trigger so it is only 3 keystrokes for me. The main advantage is you do not need to guess or calculate.
use / for search, then type your word and press Enter
however, if you want to jump to next word, just press n

Delete surrounding whitespace in vim

I'm using the awesome https://github.com/tpope/vim-surround plugin to surround words with parenthesis, for example I often use: viws<space><space> to surround a word with spaces.
What I'm missing is the opposite of this, that is, deleting surrounding spaces around a word.
The most common use for me is function arguments like
foo(bar) vs foo( bar ) depending on code style.
Does anyone know a nice way to do this?
Note: This solution requires the surround plugin referenced in the question.
For your specific situation you could do the following:
cs()
This changes foo( bar ) to foo(bar), however, it is not a general solution to your problem.
I often productively procrastinate in search of vim plugins too, when I could just define a mapping for this.
nnoremap <leader>dd F<space>xf<space>x
EDIT more information
<leader> common key for user defined mappings (, is a good one)
dd combination to use (any other mnemonic one will suffice)
F<space>x search backwards for a space, then remove it
f<space>x search forwards for a space, then remove it
Maybe just BXElx in normal mode.
In fact, perfect solution for me is the mapping provided by #puk, but using the keys #sarnold expected in the first place (what one would expect from surround plugin if it implemented this).
This is:
nnoremap ds<space> F<space>xf<space>x

In bash, how to make control-delete mean kill-word?

Bash uses readline, and readline can delete the word to the right of the cursor with "kill-word".
The problem is in recognizing the keypress of control-delete. When I press them in bash, "5~" is output on the screen. I could just bind for this, but it would mean that one day I need to type "5~", and it deletes a word to the right instead! So I'd much rather discover the correct control sequence.
I have googled, and quite a few resources discuss the "delete" key, but none that I've found discuss "control-delete" key. I've experimented with many variations, but nothing works.
The worst is the hours I've spent on this tedious, mindless grind, when it really should be a non-problem.
EDIT: It's through X, so maybe there's a solution with xev and xmodmap
On my machine, pressing Ctrl-V, Ctrl-Delete outputs this:
^[[3;5~
The ^[ escape character can be replaced with \e, so you can then use bind like this for bash (in your ~/.bashrc for example):
bind '"\e[3;5~":kill-word'
Or, you can add the following to your ~/.inputrc so Ctrl-Delete does kill-word in any program that uses readline:
"\e[3;5~": kill-word
This will bind only the Ctrl-Delete key, you don't have to worry about what will happen if you need to type 5~.
What you see is not the whole truth. It's probably <ESC>5~ or something like that. Try Ctrl-V Ctrl-Delete. The Ctrl-V means "do not interpret the next thing".
So binding <ESC>5~ that should be pretty safe.
Alt+D deletes one word to the right of the cursor
Ctrl+W deletes one word to the left of the cursor
(both are based on Emacs, I believe)
If you type ^Q^V (that's Control-Q followed by Control-V, releasing the Control key between them is fine), and then press Control-Delete, do you get the output you mentioned? I just tried it, and at least using Putty I don't get a response at all. Perhaps the behvior is different on an actual Linux console, though.
For other keys, readline prints a longer sequence, often including a special "command sequence introduction" character, which is hard to type by mistake. Try it, and see if you get a longer sequence with the ^Q^V command (which is, btw, called quoted-insert).
For example, if I press ^Q^V and then Delete (without control held down), readline prints ^[[3~. This tells me I can bind stuff to the Delete key by saying \e[[3~. It seems highely likely that the CSI character is present for you, but you're not seeing it since you're not asking readline to quote the input properly.
Ctrl-W deletes words.
Ctrl-u deletes lines.
They're based on Emacs (M-w and M-u).

Resources