Code Valet dude
The Code Valet is a Visual Studio Code (from here on out, just VS Code) extension that contains a somewhat eclectic collection of text editing tools for coders.
These 5 core tools are the real raison d'être for the Valet:
The line tools are typically used to edit multi-line selections, although the sort tool can also be used to sort delimiter-separated lists (DSLs).
The case-conversion tools add basic text editing features missing from VS Code.
The tools in this group are rather specialized and probably of interest only to the Valet and like-minded souls. Abandon all hope, ye who enter here.
When the Valet is used for the first time in an editing session, it will add the following buttons to the left side of the toolbar at the bottom of the VS Code window.
If you prefer the Valet to remain in the shadows, any or all of these buttons can be removed from the toolbar via the Valet's user configuration settings.
When verbose mode is enabled the Valet will prompt the user for all of a given tool's settings. If verbose mode is disabled, the Valet will only ask for the user to enter data for options that are likely to change between each invocation of a given tool; for all other options, the default or last entered settings will be used.
By default, verbose mode is on. As you become more familiar with the way the Valet likes to do things, you can disable verbose mode in the configuration settings. You can also toggle verbose mode on and off with 'alt+v v' or, by clicking the Valet's "Verbose" button on the toolbar.
The repeat command ignores the verbose mode setting.
The Repeat command (alt+v r) is used to re-run the last Valet command using the last set of options entered for the tool. The repeat command ignores the Valet's verbose mode setting -- regardless of whether verbosed mode is enabled or disabled, when using the repeat command you will not be prompted for input.
Repeat is also available via a button on the VS Code toolbar; moving the screen cursor over the button will reveal a tooltip that shows the last command run by the Valet. As noted in the toolbar section, the Repeat button can be removed from the toolbar via the configuration settings.
If you're at all serious about code aesthetics, you've probably already chosen sides in the great tabs-vs-spaces debate. The Valet strongly believes that in source code tabs should always be used for indentation, but nowhere else. This hybrid approach allows anyone -- particularly coders who don't use linters -- to view code with their preferred level of indentation without distorting the format of the rest of code.
This tabs-are-for-indenting-only philosophy is what led to the creation of the tab cleanup tool, the original member of the Valet tool pantheon. The tab cleanup tool serves as a pre-filter for many of the other tools to ensure that any formatting goodness done by those tools is consistent regardless of the tab size setting. However, while the Valet strongly favors the use of tabs for indentation, if you've enabled VS Code's insertSpaces option the Valet will respect your wishes and dutifully remove even leading tabs from the text. But it won't like it.
Of course, it should go without saying that the Valet's alignment tools assume that you use VS Code with a mono-spaced font. If you don't, your coding style is obviously far beyond the ken of mortal men, and the Valet can only wish you well in your journey beyond the stars.
The Code Valet is copyright (c) 2016-present Sophodoros, LLC (firstname.lastname@example.org)
The Code Valet is free software, licensed under the Apache License, Version 2.0. See the file LICENSE.md in this distribution for more details.
The Valet would be remiss if we didn't acknowledge the help provided by Stack Overflow (http://stackoverflow.com), which has become so ubiquitous that it's easy to forget what an invaluable resource it is.
And finally, as a VS Code extension the Valet is of course indebted to the minions of Redmond for their efforts in making VS Code free, open source, and, most importantly, easily extensible via the extensions API. Although somewhat lacking in examples, the VS Code documentation was indispensable to the creation of the Code Valet.
Command: alt+v m
Aligns tabular data into columns. A typical use for this tool is to re-format tab-delimited data such as might be copy-and-pasted from an Excel© spreadsheet apps. As noted in the Valet's diatribe on tabs, text formatted with tabs doesn't travel well, so after first running the text thru tab cleanup this tool then attempts to line-up the data in columns. This works best on numeric data, but any text organized in columns separated by one or more spaces will do.
Command: alt+v a
Vertically aligns text based on a user-specified target string. The example below shows text aligned on the target string "=".
The valet will prompt you for the target string, even when not in verbose mode. However, the Valet found that aligning on "=" to be so popular it has its own dedicated command (alt-v =) that avoids the prompt.
To ensure that the alignment is done correctly, the Valet runs the tab cleanup tool on the text prior to aligning the text.
Command: alt+v /
Toggle comments on a block of code. VS Code already has this feature via the ctrl + / command; the Valet's version adds a suffix string to the comment to allow it (and you) to differentiate between its comments and regular comments. The default suffix is ">>", but you can change this via the commentBlock.all.suffix configuration setting.
Like the VS Code version, the Valet's block commenter will use the line comment characters for the document's selected language -- i.e. "//" for C-style languages, "#" for Python, etc.
Command: alt+v c
Camel case is simply Pascal case without the attitude, so see that tool's description for more info.
Command: alt+v d
Convert double-spaced lines to single-spaced. This tool is useful when extra blank lines get unintentionally inserted into text that's copied from another source.
Command: alt+v j
Joins the selected lines into a single line. If there are spaces anywhere in the lines to be joined, then the joined lines will be trimmed front and back and then joined by a space. For text that doesn't contain spaces, the lines will be joined without spaces.
Converts a block of C-style line comments to a JSDoc block comment. If the selected text is already in JSDoc format, the tool will convert the comment back to a C-style comment.
Command: alt+v shift-j
Command: alt+v l
Converts all selected text to lower case. (As if you didn't know...)
--------------- # Pascal case
Command: alt+v p
As most coders know, Pascal case and camel case involve capitalization of each word in a variable name; the only difference between the two formats is whether the first letter is capitalized:
The trick, of course, is knowing where one word ends and the next one begins. For example, when converting "kidsexchange" to Pascal case, should it be KidsExchange, or KidSexChange?
Even ignoring the risk of offending delicate sensibilities, deciding how to split scriptio continua into words is well beyond the scope of the Valet's capabilities. As a result, the Pascal case and Camel case tools are limited to converting sets of words that are already delimited by spaces and/or underscores.
Command: alt+v s
Conversion to sentence case simply involves converting all words except the first word in a sentence to lower case. However, in English and most other languages this is complicated by exceptions that include the following:
The number of words that belong to these categories is almost infinite, and the Valet is too self-consciously self-sufficient (one might say arrogant) to ask for help. However, the Valet does maintain a list of exceptions that you can augment by highlighting one or more words and tapping "cmd+ ." This list is saved in the file codeValetWords.txt, so if you would prefer to modify the list directly, find the words file and manually add your exceptional words.
Command: alt+v down (A->Z) Command: alt+v up (Z->A)
You'll be prompted for these options in verbose mode; when verbose mode is disabled, the last values or default will be used. The default settings for case sensitivity and numeric sort can be overridden in the Valet configuration settings.
Those who are paying close attention will note that the down arrow actually invokes an ascending sort (i.e. smallest to largest), while an up arrow kicks off a descending sort. If this seems confusing, don't think of it in those terms, but instead view the down arrow as representing the direction of a "natural" (i.e. A->Z) line sort. Besides, Microsoft Excel's sort icons use the down and up arrows in this fashion, and far be it from the Valet to question the wisdom of Redmond.
The tab cleanup tool is run on the selected lines prior to sorting.
Sorting delimiter-separate lists (DSLs)
The following simple example shows a string containing a comma-separated list (CSL) and the result of sorting a string.
The default delimiters are the comma, semicolon, colon, and vertical line. This list of delimiters can be modified or augmented via the Valet's sort.delimiters configuration option.
The same rules used for sorting lines apply to sorting DSLs.
Numeric sorting As most coders know, sorting text containing numbers won't sort by the numbers' values if the numbers have varying lengths, as shown in the example below:
If the Valet's numeric sort option is on (which it is by default), then the Valet will determine if all of the text to be sorted starts with numeric values and, if so, sort the data numerically.
Command: alt+v tab
Cleans-up tabs in the selected text. Assuming you're using tabs (i.e. you haven't set VS Code's insertSpaces setting to true), each line is updated as follows:
After the Valet cleans-up tabs, tabs are only used for indenting the text at the start of the line. However, as noted here, the Valet will begrudgingly convert all tabs to spaces if you've enabled VS Code's insertSpaces option.
Command: alt+v t
Title case converts the first letter of almost every word in a sentence to upper case. The "almost" aspect comes into play because in English, some simple words (a, in, on, for example) are usually not capitalized; other languages may have different rules. The words that aren't capitalized are defined in the Valet's titleCase.lower configuration property. You can copy the list of words from the default settings into your user settings and add or remove words as needed.
In addition, the list of word exceptions used by the sentence case tool is also used by this tool. When converting to title case, words in the exception list will be set to the case defined in the list.
Command: alt+v shift-u
Show the Unicode hexidecimal values for each character in the selected text.
Command: alt+v u
Converts all selected text to upper case, or as the Valet somewhat superciliously likes to call it, majuscule. No shouting, please.
Command: alt+v shift-v
This tool will only be of use to you if you can answer Yes to all the following statements:
If you've answered yes to all three, the Valet feels your pain and hopes you are getting help for your obsession. To perhaps mitigate your symptoms the Valet offers you the services of this tool, which must be run on the full content of your package.json file to allow it to work its magic.
Command: alt+v w
Wraps comments (or any text, actually) at the specified column. If the text contains comment characters at the start of each line, the text is wrapped without moving the comment characters, and comment lines are added or removed as needed.
The definition of "comment characters" includes not only your language's line comment characters (e.g. "//' for languages that use C-sytle comments), but also includes other characters such as "*" (for block JS Doc comments) and "///" (for Visual Studio .NET). However, the Valet doesn't pretend to know all of the different alternate sets of comment prefixes found in the wild, so you can add your own via the Valet's wrap.commentPrefixes configuration option.
In verbose mode, you'll be prompted each time for the wrap column. The default is 80 (an old-school setting if there ever was one), but the default can be changed via the Valet's wrap.column configuration setting.
If like the Valet you've acquired the bad habit of actually adding comments to your code and you're a bit anal about comment aesthetics, the wrap tool can save you from lots of tedious manual re-formatting of your comment blocks. And if not? Move on then, these aren't the droids you're looking for.
Command: alt+v shift-x
Converts a block of C-style line comments to XML Documentation comments, the documentation-ready comment style used by C# in VS Code's big brother, Visual Studio. If the selected text is already in XML Doc format, the tool will convert the comments back to C-style comments.