I have text like this:
1;a;3;;
2;abc;4;;
3;abcde;5;;
I want to align texts to the right with notepad++, so become like this:
1;a;3;;
2;abc;4;;
3;abcde;5;;
How to do this?
I have text like this:
1;a;3;;
2;abc;4;;
3;abcde;5;;
I want to align texts to the right with notepad++, so become like this:
1;a;3;;
2;abc;4;;
3;abcde;5;;
How to do this?
I think you'll need two main steps here. In Notepad++, select Plugins -> Plugin Manager and check if the TextFX Characters plugin is installed.
Solution for use case 1
Solution for use case 1 (continue)
^(.+?)(\h+)
\2\1
Solution for use case 2
Copy the character used as a delimiter ";" to the clipboard and select all rows.
Select TextFX -> TextFX Edit -> Line up multiple lines by (Clipboard Character):
Special use case 3
BTW - you may want to use Ctrl+Alt+R for viewing and writing right align and switch back by using Ctrl+Alt+L for left align.
This can be done with a three step process. First: find the length of the longest line in the file, let this be N
. Second add N
spaces to the start of every line. Third remove leading spaces from each line so they each have N
characters.
In more detail:
First step, manually scan the file to find the longest line and count the number of characters. This gives N
.
For both replacements, ensure that "Dot matches newline" is not selected.
Second step, do a regular expression replace of ^(.)
with ____\1
, where the ____
is the N
spaces. There are other ways of adding these spaces, such as using column mode to select a zero-width column at start of every line, then typing N
spaces.
Third step, do a regular expression replace of ^ +(.{N})$
with \1
. Where, of course, N
is replaced by the value of N
.
The text you want to right-align must be in a rectangular block as follows. If you need help preparing your text as described, please skip to the starter tips section below.
• contains no TAB characters
• is left-aligned
• is right-padded with SPACE characters to the desired size
Repeatedly apply the following regular expression multiple times until it stops matching:
<PATTERN>(^.*?) (?= *$)</PATTERN>
<REPLACE> $1</REPLACE>
There are are numerous ways end up with a rectangular block of text that meets the criteria above, and the techniques and scenarios generate a lot of variation. Most of this isn't directly related to the question at hand, so rather than attempt to show detailed steps I'll just list some helpful points here.
To left-align text, or equivalently, remove leading whitespace from each line, select the desired lines, and press shift-tab numerous times until every line is jammed all the way to the left.
To convert TAB to SPACE characters, use the Edit / Blank Operations / TAB to Space menu option.
note
:If you plan on copying selected lines or rectangular blocks of text to a new temporary document for easier processing, TAB-to-SPACE conversion should generally be applied on the original source document before copying, because the starting column position within the document affects the conversion process.
Virtual space is any blank area in the document that is to the right of the last character on its respective line(s). To place the typing cursor in virtual space, use alt-mouse-click.
starter hint
: If you're not familiar with manipulating whitespace and virtual space in Notepad++, you'll probably want to turn on the Visible White Space feature. Select it from the View / Show Symbol menu.
To right-pad a line with space characters, simply place the cursor at the desired spot in virtual space, and press the space key. The line will be padded with spaces so that there is no longer virtual space but rather a space character at the cursor.
To create a rectangular selection for copying, pasting, deleting, or typing text, use alt-mouse drag.
Rectangular selections can span over virtual space. If a rectangular block that spans over virtual space is copied, these areas are copied as virtual space (i.e., not right-padded with spaces). If this block is then pasted into a destination such that it intersects a line that has text to the right, it will likely make a mess.
You can use create a tall vertical typing "cursor" that lets you type on multiple lines at once by creating a rectangular selection (see previous tip) that is zero characters wide.
To right-pad many lines at once, create a tall vertical cursor (see previous tip) and press space on the keyboard.
note
: When right-padding line(s) as described here, the padding might include one extra space character beyond what you intended. This is because SPACE characters are added up to and including the position you clicked in virtual space. If so, just press backspace.
Pad your left-aligned text rightwards with space characters to the desired size. Although not shown in the example, the desired right-padding can extend beyond the longest line. Just make sure the area is rectangular and padded the desired width. The image on the right image shows the final right-aligned result.
The regular expression shifts the text on each line by one character to the right, while staying within the rectangular area. Press 'Replace All' repeatedly until all the lines are right-aligned.
CodeWright used to do this using a context menu. Select your box, then select "Right Align", and your column will get right aligned. This is a very useful feature and if you can make it easier to use, a lot of users will use it more often :)
CodeWright
? A screenshot is welome. –
Sochor © 2022 - 2024 — McMap. All rights reserved.