Problems converting Keys in keypad to an AutoHotKey Script - keyboard

I am trying to write a basic ahk script to convert some hotkeys in a game from {'F1' 'F2' 'f3'and Esc} to num1 num2 num3 and num enter. <-- the keys on the Keypad on the right of my keyboard.
Issue
The ahk script does not recognize these values as keys in my number pad.
(the spot on the right side of keyboard that has values from 1-9 in a 3 x 3. I am having trouble finding what to enter for my Num/Keypad values in the script.
This is what I currently have...
Num Enter::Escape
Num 1::F1
Num 2::F5
Num 3::F6
Num 8::up
Num 6::right
Num 5::down
Num 4::left
Ctrl::suspend <----It does not recognize "Num" as a key
And this is the message that I get after I try to run the script via AutoHotKey
Error at line 1.
Line Text: Num Enter:: Escape
Error;Invalid Hotkey
The program will now exit
My Question
What text should I enter to trasnfer the original hotkeys (F1 F2 F3 and Esc to Number pad 1 2 3 and Enter <-- the Enter on the number pad not the one on your main keyboard.

Try to put num* like:
Numlock ON Numlock OFF
Numpad0 NumpadIns
Numpad1 NumpadEnd
Numpad2 NumpadDown
Numpad3 NumpadPgDn
Numpad4 NumpadLeft
Numpad5 NumpadClear
Numpad6 NumpadRight
Numpad7 NumpadHome
Numpad8 NumpadUp
Numpad9 NumpadPgUp
NumpadDot (.) NumpadDel
NumpadDiv (/) NumpadDiv (/)
NumpadMult (*) NumpadMult (*)
NumpadAdd (+) NumpadAdd (+)
NumpadSub (-) NumpadSub (-)
NumpadEnter NumpadEnter
You have all the information on List of Keys

Related

How to wrap some text in vim with '', "", (), [], {}, etc?

I'm new to vim. And I'm pressing too many buttons doing basic text wrapping:
string -> "string"
long string with many words -> 'long string with many words'
a + b * c -> (a + b) * c
(elem0, elem1, elem2) -> [elem0, elem1, elem2] (optional)
I'm doing all that manually: go to begin, Insert mode, press key, Normal mode, (the same for second character).
How to do it faster? E.g.: visually select the text, smart-wrap it with what you need. Or even without visual selection.
string -> "string"
ciw"<C-r>""
long string with many words -> 'long string with many words'
veeeeec'<C-r>"'
a + b * c -> (a + b) * c
vwwc(<C-r>")
(elem0, elem1, elem2) -> [elem0, elem1, elem2] (optional)
"edibxs[<C-r>e]
That one is a bit more complicated:
"edib cut the content of those parentheses into
an arbitrary register, here I used "e
xs cut the closing parenthese then cut the opening one
and enter insert mode
[<C-r>e] insert the opening bracket, followed by the content of
register e, followed by the closing bracket
But yeah, use Tim Pope's Surround.
You can use visuall mode for this. For example you have string. ^ will be cursor positioning. Start in normal mode
1. string # press viwc(your word will be selected and deleted to unnamed register)
^
2. # press " and then <C-r>"(this will paste your selected text) and then press again "
This method can be with any surrounding parenthesis or brackets and with any number of words. you just need to change your selection in visual mode

In Vim, paste over text between two parenthesis?

Something that I find myself doing often is yanking the text between two parenthesis and pasting that over another pair of parenthesis. For example:
foo(int a, int b, int c)
bar(int d, int e)
becomes
foo(int a, int b, int c)
bar(int a, int b, int c)
Is there a quick way in Vim to yank the text from foo and paste it over the text in bar?
Yank the content of the first pair of parentheses:
yib
Visually select the content of the second pair of parentheses and put:
vibp
One way would be yi) inside foo's arguments and "_di)P within bar's arguments.
yi) yanks the text inside the parentheses
"_di)P uses the null register to delete the text inside the parentheses and pastes the text, vi)p also works and avoids the null register
The only thing changing is the function name though, so you could also just yank the line and use cw (change word) to change foo to bar.
Cursor over the first paren of foo, then use y% to yank all the text until the matching paren. (You can also use v%y if you prefer to visually see the text you're yanking.)
Then cursor over the first paren of bar, then use v%p. It selects the text up until the matching paren then pastes over it.
Use this to go to last parenthesis shift + 5.
Press 5 twice for the first parentheses.
I use vim-scripts/ReplaceWithRegister.
Copy as usual with
yi(
Paste with gri(

Vim Copy and paste text on the same line

I have an input text as follows -
(command (and (A B C) ))
(command (and (D E F) ))
(command (and (G H I) ))
...
...
I would like to copy and paste part of text on the same line as
(command (and (A B C) (A B C)))
(command (and (D E F) (D E F)))
(command (and (G H I) (G H I)))
...
...
Will it be possible to do it using VI Editor automatically?
Update :
I think I missed one important point that the values A,B,C ... I... can have variable length. I just used them as symbols.
Thanks !
If all the lines are the same length and format as in your example:
With cursor anywhere on or inside of parens (A B C):
va(Ctrl+v
Now you have (A B C) selected and are in block select mode. Use any mechanism to block select downward. If it is a few lines, you can just move downward. If it is many you can add a count, or use a search (/) or end of file Shift+g.
Once you have selected all:
y/)Enterp
This will yank (y) the whole block, move to the close paren, and paste the block after it (p).
If the lines vary in length or otherwise cannot be reasonably selected as a block
You can use a pattern replacement. This is specific to your example, where we are looking for the pattern (A B C) where A, B and C are capital letters contained in parentheses and separated by spaces. We take a match of that pattern plus the following space, and replace it with the match of that pattern, a space, and the pattern match again.
:%s/\(([A-Z] [A-Z] [A-Z])\) /\1 \1/
Yes, several ways to do this in vim (as with most things). I would probably opt for a quick macro: go to the first line and hit qa from normal mode to start recording a macro named "a". Now do the edit on that line manually. Of course you'll want the operations to be generic, so don't just type in the values, use yank and put to copy it. Once the edit is done, escape to normal mode and press j to move down to the next line (this will set you up to run the macro on the next line). Hit q again to stop recording, then type #a to execute the macro on the next line, then hit it again to run it on the next line, etc. Or, once you do #a once, you can do ## to run the same macro again. You can also supply a count to ## to do is several times.
Alternatively, you can do a regex with the :s command, but it depends on what your lines actually look like and how good you are with regex.
(these work for me in vim)
using block select:
14l<C-v>jj6ly7lp
using macro (if lengths are varied):
record the macro using:
qqf(;vf)y;pj0q
and then repeat as neccessary:
100#q
works for a file with 100 lines
I combine the techniques given by bmearns and Kev.
So what I did is as follows
start recording the macro by q.
/( to find the opening bracket, so it goes to the second one.
n to goto the third one.
v to mark the visual block
/) to search for the end of the bracket
y to copy the visual block
n to goto next ) bracket
One time arrow key to go next to the closing bracket
p to paste the visual block
Down Arrow key to goto next line.
Home Key to goto first location of the next line.
q to stop recording the macro
#a to do the same operation for all the lines.
And it worked just completely fine !
Thanks a lot guys !

vim repeat find next character 'x'

I often navigate in vim by f x to find next occurrence of character 'x',
but overlook that there is a word (or more words) containing 'x' in between the word I want to edit and the beginning cursor position.
So i have to f x again, which is kind of annoying since there is this nice button ., which does repeat the last command. So is there a way to repeat f x with a single button press.
The command to repeat an f is ; (semicolon); , (comma) reverses the direction of the search.
Time has passed since I asked this question - nowadays I use vim-easymotion, which makes the need for ; almost unnecessary.
This plugin allows to jump to a certain letter directly - triggering the plugin makes all letters grey except for all 'x' on the screen - and those are replaced by red letters which you can press to jump directly to it.
To add to #Jeremiah Willcock answer, We can add count to f command to go to the nth occurrence [count]f{char}. For e.g.
2fx => goes to the second occurrence of x [if available]
similarly we can use the same counter to ; and ,. For e.g.
2; => goes to the second occurrence of last search [if available]
2, => goes to the second occurrence of last search in reverse [if available]
This is very useful when using it with c{motion}(change) or d{motion}(delete). For e.g. If we want to change or delete to 3rd occurrence of a char we can do
c3fx => change to 3rd occurrence of character x (included)
d3fx => delete to 3rd occurrence of character x (included)

How can I quickly add something to a few lines in vim?

I'm trying to get away from my arrow use but there is one thing I've yet to solve without using the arrow keys. Take this example:
var1 = "1"
var2 = "2"
var3 = "3"
var4 = "4"
Now I want this to be:
var_1 = "1"
var_2 = "2"
var_3 = "3"
var_4 = "4"
Using arrows I would just goto the var1, insert and add the underscore and then arrow down and do the same thing. The problem with using hjkl is I can't be in insert mode so I have to esc out, move down, insert...rinse repeat which required more work. Is there another way to accomplish this?
You can also use a visual block insert:
go to the "1" in "var1"
press CTRL+V
go down with j to select all the rows you wish to affect
I (that's capital i)
_
<ESC>
The underscore should now be inserted at the correct place in all the rows selected (for some reason it takes a second for it to happen on my machine)
There are many ways to do this. Using movement commands for example:
1G0 → Go to the start of the first line
f1 → go to the first occurence of "1"
i_<ESC> → insert "_" and go back to normal mode
j. → go down a line and repeat the insert command
j. → go down a line and repeat the insert command
...
Or, better yet, use an "ex" command:
:%s/var/var_/
Or even with the visual block command, as johusman notes.
Assuming you're at line 1, character 1...
Using a macro:
qqfra_<Esc>+q3#q
q Record macro
q Into register q
f find
r 'r'
a append
_ underscore
Esc Normal mode
+ Start of next line
3 Three times
# Play macro
q from register q
Par 11.
Or (better) using substitute:
:%s!r!&_<CR>
Par 9!
[Sorry... too much VimGolf!]
I tend to prefer :substitute over the visual block mode.
%s/var\zs\ze\d/_/
I always have line numbers turned on, so I'd do e.g.
1,4 s/var/var_/
This is similar to the
% s/var/var_/
answer, but it only functions on the named lines. You can use visual mode to mark the lines, if you don't like typing the range (the 1,4 prefix) in your command.

Resources