awesomewm remap tag display - window-managers

I'm trying to remap my the tag display feature thats traditionally mapped to modkey, "Control", "#" .. i + 9. I have removed any other instance of {modkey, "Tab"} mappings in my rc.lua, and attempted to replace the word Control with the word Tab. However, despite the rc compiling it the command doesn't run. I have no idea why this might be hopefully one of you more experienced users will be able to see my issue.
awful.key({ modkey, "Tab" }, "#" .. i + 9,
function ()
local screen = awful.screen.focused()
local tag = screen.tags[i]
if tag then
awful.tag.viewtoggle(tag)
end
end,
{description = "toggle tag #" .. i, group = "tag}),

As Uli says in the comment, what can and cannot be a modified is a constraint coming from Xorg. It cannot be Tab.
But. With awful.keygrabber, you can create a keybinding on modkey+Tab, then from that callback, start the keygrabber and intercept the number keys from there. When the keygrabber detect Tab is released, then stop it. There is multiple built-in methods and property to make this rather easy.
See https://awesomewm.org/apidoc/core_components/awful.keygrabber.html for more details.
Just take the Alt+Tab example (link above) and modify it to fit your use case.

Related

Unwanted text appears every time I close a bracket in VIM using VimTex

I am typesetting a latex file in VIM using the Vimtex plugin.
Every time I close a bracket, this text shows up automatically in the <++>.
For example:
\section{This is one}<++>
\section{The variable $V_L$<++> explains things}<++>
\begin{equation}
<+content+>
\label{<+label+>}
\end{equation}<++>
LaTeX compiles my text with those printed out in the pdf so I have to manually remove the every time. This behavior goes from $$ to {} to others also and even inside certain areas when using autocompletion features wit F5.
I did look add this question but it did not provide much help as to how to solve my issue.
How can I prevent the from being added to my tex files?
If they are a feature meant for something I do not understand, how do I prevent them from compiling in my pdf's?
This part of the documentation on the vim-latex (not Vimtex) repo on github
explains how the macro system works, how it's useful and solely meant for editing
NOTE: Place Holders
-------------
Almost all macros provided in Latex-Suite implement Stephen Riem's
bracketing system and Gergely Kontra's JumpFunc() for handling
place-holders. This consists of using "place-holders" to mark off
locations where the next relevant editing has to be done. As an example,
when you type EFI in |insert-mode|, you will get the following: >
\begin{figure}[<+htpb+>]
\centering
\includegraphics{<+file+>}
\caption{<+caption text+>}
\label{fig:<+label+>}
\end{figure}<++>
The text <+htpb+> will be selected and you will be left in |select-mode|
so that you can continue typing straight away. After having typed in the
placement specifier, you can press <Ctrl-J> (while still in insert-mode).
This will take you directly to the next "place-holder". i.e, <+file+> will
be visually selected with Vim in select mode again for typing in the file
aaaa. This saves on a lot of key presses.
Note: Upon testing I realized that the placeholder only appears when the bracketing is empty.

Script to paste a specific string into a text field with a hotkey

I am trying to find a way to paste a predefined string upon entering a specific keyboard sequence, on any app.
For example if I have to paste an url or a password into a field, I can have said password in a hidden script and when I press, say, [ctrl] + [5], it would write "example123" on the text field where my cursor is.
Ideally without copying to the clipboard (I'd prefer keeping what I have on my clipboard and also avoiding to paste a password or such by mistake elsewhere).
I have tried every solution I've found so far that include xclip, xdotool and xvkdb. All of them either do not work or are really inconsistent: They only paste the string sometimes, and when they do, it's usually only part of the string ("ample123" instead of "example123").
I thought of using compose key, which I heavily use anyway to write in french on an us keyboard, but it seems it only supports 1 character sequences, as nothing is printed when I modify my .XCompose to include custom output sequences of len > 1.
I am using Ubuntu 18.04 with Gnome as a DE. Ideally something that also works when logging back (like compose keys).
You need to walk the Document Object Model for either Gnome or your web-page. My concern is that with a desktop script you wont be able to access the web page because you will need to be able to establish a target to send string to. I see in your question that you tried using using "x{tool-name}" to grab the text field element. Delivering the sting really isn't the problem. The problem is getting the GUI element of text box pragmatically. The easiest way to get access to this in a user loaded web-page is with WebExtensions API which is how to make extensions for most modern browsers. Otherwise, if you can get away with only having access to Gnome's GUI I would try LDTP, it's a library used for testing, but it looks like it can be used for automation too.
For keyboard shortcuts:
It really shouldn't matter what the script is doing to how you want to activate it. I would just go to Gnome/Settings/Keyboard and set the path to where I saved the script to be the Command. If you go the WebExtension route, you will want to build the shortcut into your extension.

Sublime text multiple cursors?

Sublime Text is so damn advanced and this seems like such a stupid question, but...
I started writing a for loop in PHP (using SFTP), loved that it gave me a choice to auto-generate the loop. However, it enters this weird multi-cursor mode, which
1)I am not really sure how to use/exit without using the mouse;
2) it seems useless, seeing as all 3 type the same thing, even though I need to change, for example, the $i > x or $i = x.
Although Sublime does indeed support the idea of multiple cursors (which is an incredible time saver and useful as all get out, as we're about to see), what you're actually asking about here is a snippet which in this case happens to also include multiple cursors.
The general idea is that for code that you're likely to type many times (e.g. a for loop), you can create a snippet that will generate the bulk of the text for you in one shot, and then allow you to easily customize it as needed. In this case, the snippet in question is part of the default functionality of Sublime and is provided by the shipped PHP package.
To answer point #2 in your question first, this is far from useless. As seen here, I enter the text for and then press Tab to expand the snippet out. The first thing to notice here is that the status line says Field 1 of 4 to tell me that I'm in a snippet and that it contains four fields.
The first field is the name of the control variable for the loop, and all of them are selected so that as I change the name, all of them change at the same time because when there are multiple cursors, the text you type appears at all of them at the same time.
Once I'm done changing the name of the variable, I press Tab again to go to the next field, which allows me to easily change the point at which the loop starts. Another press of Tab takes me to the third field, where I can specify where the loop ends.
One last press of Tab exits the snippet and selects the text in the loop, so I can start writing my code (caveat: I am not a PHP developer).
At this point you can see Sublime offering another snippet for echo, which would expand out to an echo statement complete with quotes, then allow me to edit the text in the echo and skip to the end.
Circling back around to the first point in your question, you can use Esc at any point to jump out of a snippet and go back to regular editing. You can also use Tab or Shift+Tab to move through the fields in the snippet, and pressing Tab at the last field in the snippet exits it as well.
In this particular case, the first field in the snippet sets up multiple cursors, and so exiting the snippet while this field is active leaves multiple cursors in effect. You can jump back to a single cursor by pressing Esc one more time (this is true regardless of how you ended up with multiple cursors).

Quick console.log insertion in Sublime

Many times when I'm debugging I like to log out a line like this:
console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
console.log(dataThatImTryingToSee);
console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
However, it gets annoying having to type in the console.log line's contents all the time. Is there a way to add hotkeys in Sublime that would insert a line such as the console.log one?
Sublime can do this with something called Snippets, which allow you to re-use bits of text in a variety of ways to make your coding life easier.
To get started, select Tools > Developer > New Snippet... from the menu, and replace what you see there with the following, and then save it in the location that Sublime will select by default, which is your User package. The name doesn't matter as long as it ends in sublime-snippet, but remember what name you used because you're going to need it in a minute.
<snippet>
<content><![CDATA[
console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
console.log(${1:$SELECTION});
console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");${0}
]]></content>
<description>Debug log an item to the console</description>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>dlog</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.js</scope>
</snippet>
If you're not familiar with snippets, the text inside of the CDATA part of the XML is the body of the snippet, which will get inserted into the document.
${0} and ${1} are "fields", which you will be able to tab through entering text as you go. Fields are traversed in numerical order, but the special field ${0} indicates the location where the cursor should ultimately end up, which in this case is at the end of the last line so you can continue coding.
Fields can have the form ${#:default}, where the text initially displayed for the field is default. This will appear automatically in the snippet when it triggers, but it will be selected for you to type over it if you want.
The special field $SELECTION will be replaced with any text that happens to be selected when the snippet triggers (more on that in a second).
With the snippet saved you already have a couple of options open to you to trigger it, as long as you're in a JavaScript file (the syntax has to be set to JavaScript, so be sure to save any new files first).
First, if you open the command palette and enter the text Snippet to filter the list of commands to those which contain that text, you will see all snippets that apply to your current file, and in that list is an entry that says Snippet: Debug log an item to the console, which will trigger the snippet when you select it.
In this case, if you have any text selected, it will automatically be placed into the second console.log, so you can select a variable or what have you and trigger the snippet to log it directly.
Secondly, you can just enter the text dlog and press Tab to expand the snippet as well. The command palette entry mentioned above has text to the right that says dlog,tab to remind you. Depending on your settings, you may also get offered an auto completion popup as well.
Your question specifically talks about adding a hotkey, which is also possible. In that case you want to add a binding something similar to this to your custom key bindings:
{
"keys": ["alt+shift+d"],
"command": "insert_snippet",
"args": {
"name": "Packages/User/data_log.sublime-snippet"
},
"context":
[
{ "key": "selector", "operator": "equal", "operand": "source.js" },
]
},
You can change the key to whatever you would like, naturally. Note also that the name of the snippet you provide has to match what you saved the file as. If you followed the directions above it will have been saved in Packages\User already.
Now when you press the key, the snippet triggers. As above, if you have any text selected, it will automatically be inserted into the second console.log.
Note that in all cases when the snippet triggers, you will first have your cursor set inside the second console.log (possibly with some selected text already there), and Sublime is waiting for you to finish typing text for that field, so press Tab again to skip to the end of the snippet.
As a reminder of this, you'll notice that the status line (if you have it turned on) tells you Field 1 of 2 to let you know that you're inside a snippet.
This example assumes that you're working with JavaScript, so the snippet above and the key bindings will both only trigger when the current file is JavaScript. If you're using some other language, you can remove the scope from the snippet and/or the context part of the key binding to make them apply in all files, or modify the scope there to match the language you want to target.
This just scratches the surface of what you can pull off with a snippet. You can also do things like use the same field more than once to have the same text appear in multiple places, do regular expression substitutions, and much more. Check out the link above for more information.

How to make Sublime Text not autocomplete element names within text elements

When I write HTML in Sublime Text 3, I like having autocompletion of attributes and element names and so on, but Sublime Text is always over-predicting things and turning my text content into elements (inappropriately), when the vast majority of the document body I am writing is text, not elements. What gets really annoying is if I press Enter at the end of a line where it believes the word I am typing is a typo of a different element, I get some really frustrating behavior:
The workaround I see is to press EscEnter at the end of every line but that isn't particularly ergonomic (and I have severe RSI so I'd rather have things be ergonomic).
Here are the relevant portions of my Preferences.sublime-settings:
{
"auto_complete": false,
"auto_complete_selector": "source - (comment, string.quoted)",
"tab_completion": false,
"tab_size": 4,
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true,
"word_wrap": true
}
I have looked at the Sublime Text documentation regarding completions and snippets but it isn't obvious to me how to suppress completions entirely during a text context. I don't currently have any HTML-mode-specific options configured.
Sublime's HTML autocompletions are implemented in a Python script.
It is possible to edit it, such that HTML tags will only be offered when you type < and a letter - instead of offering them while typing "plain" text content inside HTML.
To do this:
Install PackageResourceViewer using Package Control (if it isn't already installed)
From the Command Palette, type PRV: O and select PackageResourceViewer: Open Resource
Select HTML
Select html_completions.py
Find the line # if the opening < is not here insert that (https://github.com/sublimehq/Packages/blob/77867ed8000601962fec21a012f42b789c42195b/HTML/html_completions.py#L243)
Change completion_list = [(pair[0], '<' + pair[1]) for pair in completion_list] to completion_list = []
Save the file
Note that this creates a file that will override the version that comes with ST, so when a new build of ST3 is released, your version will still be used. In case this file is ever updated, it might be a good idea to delete your version to ensure you have the latest changes, and then to re-apply the above steps (if necessary - maybe it will be "fixed" in a future update to not suggest anything when auto_complete is set to false). To do this:
Tools -> Browse Packages
HTML
Delete html_completions.py

Resources