4

Anyone know of a way to reformat either the whole txt file or the selection (I don't really care, either is fine) so that it would would add spaces to align text as columns?

example:

Green 5 Vest
Black 6.93 Scarf
Red 35.6 Hat

so that it ends up like:

Green 5    Vest
Black 6.93 Scarf
Red   35.6 Hat

or something similar... I mean the important thing is that they are arranged in an easy-to-read fashion.

3
  • 2
    Based on your example, just replace Spaces with Tabs. :) Oct 28, 2014 at 18:38
  • sure for this example, but I was just trying to illustrate what I meant with something simple.
    – Mikey
    Oct 28, 2014 at 18:50
  • I figured as much, that's why I made that a comment instead of an answer. ;) Oct 28, 2014 at 19:03

2 Answers 2

6

Notepad++ has a plugin that does this for you. It's called "Code alignment". It allows you to align text vertically based on characters of your choosing. You can install it via the Plugin Manager for notepad.

Below is a simple usage scenario. You start off with the following code, then you align by "equals" which is a built-in shortcut/command for the plugin.

Initial Code Sample, without alignment

After that, you end up with the following below:

Code after equals alignment

You can also take it a step further and use the "align by..." command which allows you to specify any arbitrary alignment string. In the example below, I chose the "#" character in order to align my comments next to one another. This could just as easily have been a longer string, and not one of length 1.

End result below:

Final result after arbitrary code alignment string

Source

1
  • 1
    just installed it as per your suggestion... works great.
    – Mikey
    Oct 28, 2014 at 21:42
0

Yes. Replacing space with tabs is best example as per " Ƭᴇcʜιᴇ007".

But still if you like to have specific repeated automation work you can use Macros. Macro allows you to repeat a set of actions again (and again...) but you will need to "teach" Notepad++ what it is you want to do first. So follow the instructions below closely or you could end up with a non-working result.

Please note that for simplicity I will only explain how to work with macros for your first case (your first file) so as not to repeat myself unnecessarily. Also, please make sure you have a backup copy of the original file before you attempt this in case something does not work as intended.

Okay, here goes:

  • Open up Notepad++, open up your file.
  • Make sure you are at the beginning of your first line of data, that is, the first line with the first word in your dictionary in your case.
  • From the "Macro" menu select "Start recording"

Do what you need to do with only the first set of data. In the case of your first file, that would be something like:

  1. move the cursor to next word "Green 5"
  2. Enter space and then move the cursor to next word "Vest".

    • The last step here is important because you want to be at the 'right place' for the next run-through of your macro
    • Now from the "Macro" menu select "Stop recording"
    • From the "Macro" menu, select "Save the recorded macro", and give it some appropriate name and click "OK"
    • Now (still having the cursor at the beginning of next line) select "Macro" > "Run a macro multiple times", select the macro you saved in step 6 and choose "Run to end of file", then click OK.

The macro will now work its way through your file. Be sure to give it a moment to finish if your file is large! You should now see that the macro has moved all your lines down as needed.

The same principle can be applied to your second request, although that requires a more advanced macro with more recorded actions. Once you understand the concept and know how to record a macro and play it back, however, it should be doable.

Hope this was helpful!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .