vscode-awarest-alignAlignment and formatting helpers for whitespace, symbols, and transposing. (Marketplace) (GitHub) OverviewThis extension exposes four types of alignment and formmatting helper commands. Due to variations between operating systems and keyboard shortcut preferences, it no longer adds any keyboard shortcuts automatically, but see below for some suggestions and instructions on adding your own set of keyboard shortcuts. This is intended to be a semi-opinionated approach with some obvious room for improvement. Please open an issue on GitHub if you believe something should be different or configurable and we can discuss a PR or I'll make a quick change. CommandsEach of the four main commands behave differently depending on if a single line or multiple lines are selected. If only a single line is selected (see above), then the transposing commands will attempt to split it into multiple lines. For alignment commands, the characters to align by are simply have their repeating duplicates removed if there are any. General - These items apply to all commands unless explicitly stated otherwise.
First Occurrence - Aligns the selected lines using whitespace so the provided character or characters line up vertically including one space prior. When using on a single line, any whitespace before or after the first instance of the provided characters will be removed. Lines that don't contain the provided character or characters are skipped except to conform the indentation. Each Occurrence - Aligns the selected lines using whitespace so that each instance of the provided character or characters are the furthest to the right they need to be to make the first character after the one or ones provided line up vertically. Lines that don't contain the provided character or characters are skipped except to conform the indentation. If a line has less than the maximum number of instances, only the matching number of items are aligned for that specific line. Transpose Lines - Transposes multiple lines into one or a single line into many based on the provided separator character or characters. Each newly created line will be inserted below preserving the same indentation as the originally selected single line. When multiple lines are selected, they are trimmed and converted into a single line delimited by the separator with blank lines being elimated and the maximum indentation preserved for the resulting line. Transpose List - Special handling to transposes multiple lines into one or a single line
into many based on the provided separator character or characters and looking for opening and
closing wrappers of Transpose HTML - Works in a similar way to the Transpose Lines or List items above, but has
some special handling for working with HTML tags and multiple attributes. When transposing into
multiple lines, it will add an extra indent to each property. Also, if the last characters are
either SelectionsCommands function differently depending on if you have a single line or multiple lines selected. They will function in "single line" mode if you have nothing selected (it acts on the line your cursor is on) or your selection only contains portions of a single line and your cursor is at the start of the following line. Also, they always work based on "whole lines" only. That means if part of a line is selected, the entire line is handled. KeybindingsThe following are a set of suggested key bindings that can be copy/pasted into your keyboard
shortcuts file by opening the command pallete (
Keybinding Examples and Suggestions:
Note: The SettingsThe EOL (end of line aka linebreak) and TAB values are now configurable through your typical
user or workspace settings. The defaults are for unix style (LF aka
Known Issues
LearningAn additional goal of writing this was to better understand the internals of how an extension actually works. Even if you don't have a use for this, hopefully it can help give an actual example with a near excessive amount of inline code comments for anyone interested in writing something their self, it is actually pretty straight forward. About 90% of anything you would need to know to create a basic extension such as this appears in only two files: package.json and src/extension.ts that can be viewed in the GitHub repository. Feel free to open an issue on there if something isn't clear and/or if you believe something wasn't done very well, because that is pretty likely. If you are going to dig into how this works, and it really is pretty straight forward, you will
notice that there are really only two main functions. Each of those have a specific logic tree
depending on the actual sub type. The easiest place to start would be the Heavily inspired by a method of whitespace alignment in Sublime Text 3 using randy3k/AlignTab Also referenced and learned a lot from the VS Code extension annsk/vscode-alignment You can find me on Twitter as @brian_jorden Release Notes1.1.0 - (2018-02-05)
1.0.2 - (2018-01-08)
1.0.1 - (2018-01-08)
0.4.0 - (and older)
|