How to align text to the right with notepad++?
Asked Answered
C

5

6

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?

Clastic answered 30/10, 2017 at 10:1 Comment(0)
E
2

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

  1. Search for the longest line,
  2. set cursor to the end of the longest line,
  3. press and hold Alt,
  4. click left mouse button and move mouse to upper left corner,
  5. go to Menu TextFX > TextFX Edit > Pad rectangular selection with space,
  6. repeat steps for lower left corner (select empty last line too),
  7. save the file looking like upper left corner shown in the screenshot below.

enter image description here

Solution for use case 1 (continue)

  • Ctrl+H
  • Find what: ^(.+?)(\h+)
  • Replace with: \2\1
  • check Wrap around
  • check Regular expression
  • Replace all

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):

enter image description here

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.

Euphonic answered 31/10, 2017 at 15:2 Comment(1)
CTRL+ALT+R and select all lines and SHIFT+TAB.....multiple timesFelicle
E
2

Ctrl+Alt+R will right align your text.

Emplace answered 31/3, 2022 at 15:16 Comment(0)
P
0

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.

Punk answered 31/10, 2017 at 16:43 Comment(0)
M
0

1. prepare the rectangular block

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


2. the technique

Repeatedly apply the following regular expression multiple times until it stops matching:

<PATTERN>(^.*?) (?= *$)</PATTERN>

<REPLACE> $1</REPLACE>


extra - beginner tips (working with rectangular text)

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.


3. example

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.

enter image description here     enter image description here

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.

enter image description here

Mareah answered 4/5, 2020 at 5:8 Comment(1)
For left-align use menu > blank operations > trim leading space (no need for shift-tabbing). For rectangular selections use alt key plus mouse drag (not control plus mouse drag). To right pad a group of lines with spaces, select a rectangle of virtual space after the longest line then type one space character.Punk
C
0

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 :)

Cordle answered 8/3, 2021 at 22:2 Comment(1)
Where do you find CodeWright? A screenshot is welome.Sochor

© 2022 - 2024 — McMap. All rights reserved.