Creating a 4-5 character column along the left margin in vim - vim

As a bit of context, I am considering making a plugin for vim that would inline specific debugging and/or profiling information on along the left margin (ideally left of the numbers column) which would need to be 4-5 characters wide. However, I cannot find any means to accomplish this. I've searched around, and the closest thing I can find is vimscript code for inserting signs in the sign column, but the sign column is fixed at 2 characters wide.
I've considered the possibility of making my own makeshift column (to the right of the numbers column, in the normally editable text area) and somehow marking it as readonly, but that doesn't seem possible either- from what I've read, the entire buffer must be readonly or not; you can't have just a portion as readonly.
For completeness here's an example. I would like to programmatically insert a 4-5 character column before some text (with numbers set)
1 Text buffer
2 with some
3 text
to make
My 1 Text buffer
own 2 with some
text 3 text
Is there any way to accomplish this task?

The built-in feature for this is the sign column, but yes it is limited to two characters.
Depending on your use cases, it might be okay to enhance the signs with a tooltip popup (:help balloon-eval explicitly mentions This feature allows a debugger, or other external tool, to display dynamic information based on where the mouse is pointing.), or maybe place the additional information in the quickfix or location list.
Modification of the actual buffer has many downsides (as it effectively prevents editing, and Vim's main purpose is just that). What some plugins do is showing a scratch (that is: unpersisted, unmodifiable) buffer in a vertical split, and setting the 'scrollbind' option so that its contents follow the original buffer. For an example, have a look at the VCSCommand plugin, which uses this for annotating a buffer with commit information.

Related

Separate search results panel for each search in sublime text 3?

When I press command + shift + f, I can search for all instances of a string in an entire project.
But when I do it a second time, it brings up the second search in the same panel. This gets very messy very quickly when conducting many searches.
Question: How can I bring up the second (and subsequent) search results in their own, new panel?
Example: 5 searches would result in 5 result sets each of their own panels (i.e. 5 panels total). Also, if possible, I'd like to set this as a default for future if it's simple to do so.
There is currently no way to have different search results buffer for different searches. All of the search results would be appended in the buffer with the name Find Results.
If you want different different search result tabs, then you will need to rename the current search result buffer with a different name than Find Results i.e. Find Results (1). This way, the next time, you perform a find in files, ST would create a new Find Results buffer.
It's actually quite simple to write a small plugin that uses View.set_name() to set the name of the current buffer and then you can bind it to a key (So that you can just change the Find buffer name in one stroke and have other search results in new buffers)

Python Inquirer Module: Remove Choices When Done (Using Curses)

NOTE: Although I give a lot of info on Inquirer, I'm pretty sure that most of it won't apply (just being safe). For my actual question about curses, its at the bottom.
I'm using the Inquirer module in Python 3 to allow the user to select a value from a list. I run this:
import inquirer
choice = inquirer.prompt([inquirer.List("size",message="Which size do you need?",choices=["Large", "Medium", "Small"])
And I'm given this:
[?] What size do you need?: Medium
Large
> Medium
Small
And using the up and down keys, I can change my selection, and hit enter to choose, after which the "choice" variable contains the value I selected. The issue is: Once the selection is done, the choices still show. I want to delete them when done. I'm currently using ANSI Escape Codes to delete the choices from onscreen when done, where x is the number of choices:
import sys
for i in range (x+1):
sys.stdout.write('\x1b[1A')
sys.stdout.write('\x1b[2K')
Which leaves the printed text as:
[?] What size do you need?: Medium
The issue is, ANSI escape codes aren't universal. I want to use a solution that works on all terminals, preferably curses, but curses isn't very friendly to new users, so I was wondering if anyone knew how to use curses to "delete x lines above current position". Thanks!
curses, as such, would erase the whole display (which is probably not what you want). A low-level terminfo/termcap approach might seem promising, but while ECMA-48 does define a sequence (ED, with parameter 1) which erases above the current position, there is no predefined terminfo/termcap capability which corresponds to this. All that you will find there is the capability for erasing to the end of the screen, or erasing the whole screen.
"ANSI sequences" is an obsolete term. Referring to ECMA-48, you could do
sys.stdout.write('\x1b[1J')
after moving the cursor to the last location you would like to erase.

Delimiting quick-open path with fullstops in Sublime Text 3?

I'm making the move to ST3, and I'm having some trouble. I'd like to be able to delimit the quick-open filepath (⌘ + T) with periods instead of slashes or spaces. However, I can't find the setting to do that.
For example:
component.biz_site_promotions.presentation
should be able to open the file that
component biz_site_promotions presentation
would.
Any help would be greatly appreciated!
There is no setting in Sublime that changes the way this works; the search term is always used to directly match the text in the list items (except for space characters).
Note however that the Goto Anything panel uses fuzzy matching on the text that you're entering, so in many cases trying to enter an entire file name is more time consuming anyway.
As an example, to find the file you're mentioning, you could try entering the text cbspp, which in this case is the first letters of all of the parts of the file name in question.
As you add to the search term, the file list immediately filters down to text that matches what you entered; first only filenames that contain a C, then only filenames that contain a C that is followed somewhere after by a B, and so on.
Depending on the complexity and number of files that you have in your project, you may need to add in a few extra characters to dial in better (e.g. comb_s_pp). Usually this search method will either end you up at the exact file you want, or filter the list so much that the file that you want will be easier to find and select.
Additionally, when you select an item and there was more than one possible match, Sublime remembers which item you selected for that particular search term and brings it to the top of the search results next time you do it, under the assumption that you want the same thing again.
As you use Sublime more (and with different projects) you will quickly get a handle on what partial search terms work the best for you.
In addition to finding files, you can do other things with that panel as well, such as jumping to a specific line and/or column or searching inside the file for a search term and jumping directly to it. This applies not only to the current file but also the one that you're about to open.
For more complete details, there is a page in the Unofficial Documentation that covers File Navigation with Goto Anything
As an extra aside, starting with Sublime Text build 3154, the fuzzy searching algorithm handles spaces differently than previous builds.
Historically, spaces in the search term are essentially ignored and the entire input is treated as one search term to be matched character by character.
Starting in build 3154, spaces are handled by splitting up a single search term into multiple search terms, which are applied one after the other.
This allows multiple search terms to hit out of order. For example, index doc in build 3154 will find doc/index.html, but it won't find it in previous versions because the terms aren't in the right order.
As such, assuming you're not currently using such a build (as of right now it's a development build, so only licensed users have access to it), moving forward if you continue to search the way you're searching in your question, you might start getting more results than you expected.

Unicode Codepoints for special characters in MS Keyboard Layout Creator

My goal:
I am trying to get the MS Keyboard Layout Creator to allow me to perform a carriage return/enter whenever I hit the [R-Arrow] key in combination with the [Control] key, but still have the [R-Arrow] key perform as normal (i.e. move one character right) when hit alone. I'm doing this because my laptop keyboard [Enter] key is busted, and I want use this hack for a short time, before I go ahead and get another keyboard. Yes, I know it might be easier to get a new one. :)
As far as I can tell, I have almost figured everything out. The only pieces of information I still need are the exact hexadecimal codepoints for both the 1) right arrow navigation and 2) enter/carriage-return. I am hoping someone can direct me to this info. I have found the unicode reference but I am unable to discern which codes I might use for the carriage return and the right arrow navigation (not the right arrow ascii character →, I don't care about that)
Example code in my existing KLC file:
KBD Layout01 "Layout01 Description"
COPYRIGHT "(c) 2017 Company"
COMPANY "Company"
LOCALENAME "en-US"
LOCALEID "00000409"
VERSION 1.0
SHIFTSTATE
0 //Column 4
1 //Column 5 : Shft
2 //Column 6 : Ctrl
LAYOUT ;an extra '#' at the end is a dead key
//SC VK_ Cap 0 1 2
//-- ---- ---- ---- ---- ----
39 SPACE 0 0020 0020 -1 // SPACE, SPACE, <none>
53 DECIMAL 0 002e 002e -1 // FULL STOP, FULL STOP,
My understanding of the code (SPACEBAR example)
Looking at the preexisting examples in the file, (the space and the decimal) I have figured out the following:
Note: the examples in parentheses below refer only to the spacebar.
The first number is the keyboard key (e.g. 39 above)
The word which follows that number is the designated label to refer to that key (e.g. SPACE above)
the next three numbers are hexadecimal codepoints/symbols which refer to "SHIFTSTATES"
The first is the codepoint for what the key will output if pressed while the CAPSLOCK is pressed.
The second is the codepoint for what the key will output if pressed simultaneously with the SHIFT key.
The third is the codepoint for what the key will output if pressed simultaneously with the CONTROL key.
The goal: figuring out the codes for right-arrow navigation and enter
I have figured out this much for my line of code that I want to add in order so that pressing the right key alone will still navigate right, but in wihc the combination "control-right" will instead trigger a carriage-return/enter
4d RIGHT 0 ??I don't know?? ??I don't know?? -1
I believe the I know following
4d (in the 1st column) is the key code for the right arrow key
the handle RIGHT (in the 2nd column) is the handle/name for the right arrow
0 (in the 3rd column means don't change the key if the capslock is pressed
What I need your help to figure out
What the codepoint/hexadecimal/unicode symbol is for performing a right arrow navigation (I think that is what goes in the fourth column if I want [Shift]-[Right-Arrow] to make the cursor move one character to the right).
What the codepoint/hexadecimal/unicode symbol is for performing a carriage-return/enter(I think that is what goes in the fifth column if I want [Control]-[Right-Arrow] to trigger an enter/carriage-return).
It may be that I am mistaken and the symbols I need are not unicode codepoints; if I am wrong, please correct me, as that info will help me get closer to my goal. Any help would be greatly appreciated!
I don't know if you still need this, as I had already written down most of it I post it.
I looked into it for a while, I haven't found an actual definitive answer but I can give you some hints (I post this as an answer nonetheless because it would have been too unwieldy to use comments).
I have a strong feeling that what you ask is not possible (that control keys such as the arrows cannot be mapped to different keys/characters/functions when a modifier such as ctrl is pressed).
I'm not really a huge expert in these things but I can give you some pointers:
(in the following there is a good deal of information not much related to your problem, but it might help you understand better)
When you press a key in Windows there are at least 3 sets of codes that are involved:
Scan codes: these are the codes that are actually generated by the hardware and sent to the pc. I have little knowledge of them, I never had a need to use them and I was too young when they were more relevant. They can theoretically vary from keyboard to keyboard but they're largely standardized; the USB keyboards are really standardized, for what I could understand, and their scan codes ought to be those listed in these HID Usage Tables (section 10). Wikipedia has some info but not a full list of the traditional codes. Most likely you won't need these, though (but maybe you will). By the way, these scan codes are also passed to the applications (I'm not sure how reliably) but they hardly ever use them.
Virtual-key codes: The scan codes in Windows are translated by the keyboard driver into a common set of key codes specified by Microsoft: the Virtual-Key Codes. These are independent by the keyboard and are what's (normally) used by the applications when they need to handle the single key presses.
Unicode, or other charset, characters: Windows recognizes when the keys being pressed are supposed to produce printable characters and passes these characters to the applications. At the times when an application is only interested in printable characters it only looks at these characters, although when they need to do more complex things (shortcuts...) they also have access to the virtual-key codes (and, if they really want, to the scan codes). Unicode is a character set, not a "key-codes set", so it generally contains only printable characters. To facilitate interoperability with ASCII and other legacy charsets it also includes the control characters defined in previous standards, but among these control characters the arrow keys are not present, so there are no unicode codepoints for the keyboard's arrows.
In the second column of the klc it would appear that you have to put the name of the virtual-key constant with VK_ removed. Quite weird indeed.
Several Microsoft documentation pages say that the WDK kbd.h file that you can also find in the inc directory of the Microsoft Keyboard Layout Creator has the detailed information about this stuff. Personally I couldn't make too much out of it, though.
If you really want to dig into this the late Michael Kaplan's blog has probably the information you're looking for, somewhere.
Your best luck is most likely to use some other application. I stumbled upon KbdEdit, that does handle the arrow keys, but it really seems that it can't assign a different function to the key when used with a modifier (but you can change the effect of the key altogether, irrespective of the pressed modifier).
For the Enter key you would likely need to use the virtual key, which is 0D (VK_RETURN).
The sequence of characters used to indicate line breaks on Windows is CR LF, which have (in Unicode and almost every other existing charset) codepoints 0D 0A, respectively.
The Windows message that notifies applications of entered characters (point 1.3 above - I mean the WM_CHAR message, by the way) though reports only a CR (0D) when you press Enter; so if those klf files use unicode codepoints in some part there's a good chance that they use that (CR) to indicate a Enter key.
All in all, your best bet is probably to just assign the Enter to a different key (for example a function key, the right ctrl or win key if you have them or the caps-lock).

In ncurses what does the attribute A_PROTECT do?

In ncurses:
1.What does the A_PROTECT attribute do? Everywhere on the net, the docs just say: Protected mode. What is that?
2.Also I would like to mark the area where the user inputs characters with an underscore, but I would like when the user deletes or backspaces to have the underscore reappear. Is there an attribute that does that, or I have to manually do that?
Protected mode may refer to a little-used feature of some DEC terminals (notably the VT220 and related), called selective erase.
The general idea is that some text can be internally marked as protected. This doesn't change the way it is rendered on the screen, but character cells so marked are not erased by the DECSEL and DECSED (Selective Erase in Line and Selective Erase Data) commands.
This would typically be used to implement something like a data entry form. Field headings and markup would be protected text, and data entered into the fields would be unprotected. You can erase the contents of the form to reset it by performing Selective Erase; thus erasing the data fields but not the headings.
Protect mode is defined by the terminal I'm not sure if it does anything on modern terminals.
There is an attribute "A_UNDERLINE" that underlines a character if your terminal supports it.
For handling input you may want to look at the form library (distributed with ncurses) or cdk (http://invisible-island.net/cdk/)

Resources