While I figured out that I can just use something like #define ctrl(x) ((x) & 0x1f)2 for most plain ASCII (non numerical or [obviously] symbol) characters, I was unable to find any info or documentation on how to capture CTRL + ARROW_KEYS or any other sane\logical combinations of CTRL + SHIFT + ch and so on...
The reason I care about this, is because I am trying to maintain a project called unicurses and while I'm trying to maintain this project I'm also making a prototype demo of a terminal based editor with it where I need to capture those kind of key combinations and so I was looking for some help (also I really don't care if the answer will be in c\c++, python or whatever, I'm just looking for a way of doing it)
Any Idea?
Try the "Input Test" in PDCurses' testcurs demo. You'll see there that CTRL + Up Arrow is returned as "CTL_UP". The full list of named keys is in curses.h. Some combinations can only be distinguished by their modifiers, as returned by PDC_get_key_modifiers().
I'm not sure how or whether you'd do it in ncurses.
In general, I recommend you avoid these exotic key combos.
Related
In Vim, you can go 30i=<esc> to type 30 = signs. (This is handy for taking notes, becaus I like to put a bunch of equals signs under different section headers.)
Is there a way to do this in Kakoune? A numerical prefix on an insert session only types the content once.
There's some discussion of this topic here, where the most relevant comment seems to be:
Since #4041, we can create overlapping selections with the + command and Alt + + to merge them.
Example – Insert 80 asterisks:
80+i*<esc><a-+>
I can't quite get this to work myself (it does create a line of 80 * characters, but I'm not able to exit whatever mode I've gotten myself into at that point), but I haven't used kak before, so perhaps it will be more obvious to you.
So often if I have a code expression like points.length - 1 and I want to replace it with a variable (for example, named target_idx then I'll define the variable:
int target_idx = points.length - 1;
But now I want to go and replace all instances of points.length - 1 with target_idx. I'm aware I could do :%s/points.length - 1/target_idx/g, but I'm not too confident in my regex and don't want to mistakenly replace points.length - 11 or points+length - 1 by mistake. (I'm also aware of very magic searching, but also am not super confident about all the subtleties of what it does/doesn't consider special characters)
So what I want is to be able to search for instances matching points.length - 1 via /points.length - 1 and then go through the search results with n, and then replace the text with target_idx.
But because the searched-for text could have spaces or other characters, I can't simply change to the end of the Word cE since this would only change points.length in my example.
Is there a text motion that goes to the end of the searched-for text?
So I could go
n
c<special text motion here>
target_idx
repeat from 1.
I'm using neovim with CoC installed, so am open to more in-depth ideas with plugins or language server replacements, but this feels like it should be a simple text motion that I just don't know of.
I guess you can go for gn (:help gn for details). (gN searches backward.)
On the other hand, you can give :s/…/…/ the flag c so that it asks you to confirm every substitution (:help :s_flags for details).
Besides, you could most likely take advantage of . to make steps 2 and 3 in one keystroke (:help . for details). In your specific example, you'd do this the first time,
/points\.length - 1Entercf1target_idxEscape
and then just keep going to next match via n and applying the change via ..
The :s solution with c flag I mentioned above is faster (you only press y/n instead of n/n..
You are halfway there with:
:%s/points.length - 1/target_idx/g
All you need is the /c flag:
:%s/points.length - 1/target_idx/gc
which tells Vim to ask for confirmation for each substitution.
See :help :s_flags.
But you might want to look into CoC and the specific language server you use. Maybe they provide higher-level refactoring commands.
I know that there exists String.upper for the alphabet, but I'm looking for the shift version rather than the alphabetic version, such as the "uppercase" of the semicolon would be the colon. When I attempt to google I get irrelevant results about string.upper.
I think the best way to handle this would be a lookup table, for example:
local with_shift = {
["1"] = "!",
["2"] = "#",
["3"] = "#",
}
I haven't been able to find an existing table of this, but I'm sure one exists somewhere.
If you are using that for input, you can always check that both the ',' key and the shift key are pressed at the same time - and then execute whatever code you wanted to do.
As others are saying, keyboard layouts are not universal. In a French keyboard, for example, you have to press shift in order to get a '1' when pressing the '1' key in the "top" number row (it defaults to symbols). Neither LÖVE nor Lua know all the keyboard layouts available, and even if they did you could be using a custom-made one (I in fact use one on my computer).
I'm trying to make a transition to emacs (using evil mode/vim keybindings) and I'm having a hard time feeling more efficient/productive than if I just used the mouse. Here is an example of a situation where I find myself really slow:
for i in range(self.allData.shape[0]):
self.correctSequence = self.displayNumbers(i, self.allData)
self.userSequence = self.numberEntry()
self.allData.set_value(i, 'userSequence', ''.join(self.userSequence))
if len(self.correctSequence) != len(self.userSequence):
self.allData.set_value(i, 'correct', 0)
else:
if list(reversed(self.correctSequence)) == self.userSequence:
self.allData.set_value(i, 'correct', 1)
else:
self.allData.set_value(i, 'correct', 0)
It would be very common for me to have to change the first 4 instances of self.allData to something else (self.testData, for example), leaving the last 2 untouched.
Normally this wouldnt be too bad with a mouse. For example, I could replace the first allData with testData, copy it, use the mouse to the next 3 occurences and just hit CTRL-V for each one. Or better yet, just use multiple cursors in sublime/atom and replace all 4 in one go
I use spacesmacs in emacs with vim keybindings. So, in emacs I find myself having to do something like the following:
SPC-SPC a (avy jump to words beginning with a)
cw testData
Repeat those 2 steps once for each word I want to replace
This seems really inefficient and I'm wondering: am I just using an inefficient method? Is there a faster way to do what I want?
It seems that even if I managed to complete those steps really fast (4 times), theres still A LOT more typing one would have to do, and I fail to see how this would be faster than just reaching for the mouse. Yes, one could make the argument that I'm losing time by constantly reaching for the mouse, but in my mind I'm saving typing time by reaching for the mouse because I can just hit CTRL-V a few times to achieve what I want. Where exactly are the vim speed gains in a situation like this?
If you just want to replace, you can use query-replace, and replace the word one by one.
You can use replace-string too, but remember to limit replacement to part of the buffer, activate the region around that part.
Anyway, these commands could prevent you from finding the word by your eyes, moving cursor by mouse and moving your hand back to keybaord. And they could avoid probable overlook too. At least I don't want to leave my hands from the keyboard when typing. :)
I'm not sure how "vim-like" Spacemacs is, but you could do it like this in Vim:
/all<CR>
cgntest<Esc>
.
.
.
or:
/all<CR>
cetestData<Esc>
n.
n.
n.
or:
:,$s/allD/testD/gc<CR>
Maybe one of these methods works in Spacemacs too?
In addition to the usual (and generally the best) answer, query-replace (see #songyuanyao's answer), you can use the secondary selection to advantage to selectively paste the same thing at various places. Unlike the region, the secondary selection is unrelated to the cursor position (aka point), so it is always available regardless of where the cursor is.
And unlike query-replacing, you can paste it on demand, instead of having to answer for each matching occurrence. If you use delete-selection mode then just select some text to replace and paste the secondary selection to replace it.
You can set and paste the secondary selection using the mouse - see Secondary Selection on the Emacs Wiki, and see the Emacs manual, node Secondary Selection.
If you use library second-sel.el then you can use the secondary selection from the keyboard as well, and get a lot more use out of it.
[Edit: after reading comments I realize that the Surround plugin is adequate for my needs after all, so I'll leave this question for purely academic purposes to gain a better understanding of vimscript's inner workings]
I'd like to make adding/deleting tags, quotes, braces, and other symmetrical text structures easier to do in Vim, and I find the surround.vim plugin a little too quirky and specialized for my needs.
What I really need is more generally a "mirrored" input mode and "mirrored" deletion mode, whereby I could visually select a block of text, then type onto or delete from both ends of the selection at once. As an example workflow, I'd like to:
select the word hello
hit some keystroke combo to enter "mirror mode"
type "
my text now says "hello"
In this example I only typed one character at each end, but it's important that in step three I could have typed many characters, not just one, for instance I should be able to type <b> to produce <b>hello<b> (I still would need to manually add the / in the closing tag, which I'm OK doing).
So is this even possible in Vim? Could someone provide a broad outline of functions that would be involved in the solution? Specifically, I don't know how to intercept text as it's being inserted and then alter the location where it appears so that it's tacked onto the beginning and ending of the selection block instead of the cursor location. And ditto for deletion.
Well, the behavior you describe is exactly what Surround does:
select the word hello
hit S
type "
my text now says "hello"
The difference with what you ask is the "live updating" or "live mirroring" which I have no idea how to do. You could probably take a look at SnipMate or UltiSnips for that part.