Skip to content

Notepad++ Column Editing

This post is part 3 of 5 in the series Notepad++ Tips and Tricks
Logo for blog post "Column Editing in Notepad++"

Spoiler alert! Column editing is super simple in Notepad++ :) All you have to do is press the Alt key while selecting text. You can use either Alt+Mouse Dragging or Alt+Shift+Arrows. This works perfectly on text that is already aligned. But what if your text is not formatted as columns already? You can quickly fix that by using the TextFX plugin.

Animation showing column editing in Notepad++

Column Editing in Notepad++ using TextFX

In this example, we want to clean up a “table”. We have created the table by separating columns with the pipe (|) character. We want to reorganize the columns, then sort the data alphabetically.

Step 1: Line Up Columns using the TextFX Plugin

1. Select the pipe (|) character that separates the “columns” and copy it to the clipboard:

Screenshot showing copying the column separator
Select column separator and copy to clipboard (CTRL+C)

2. Select all the text and use Line up multiple lines by (Clipboard Character):

Screenshot showing clicking "Line up multiple lines by (Clipboard Character)"
Select the text (CTRL+A) and click TextFX → TextFX Edit → Line up multiple lines by (Clipboard Character)

3. We have now lined up the text using the pipe (|) character to make it look like a table with columns:

Screenshot showing text formatted as table

Step 2: Move and Sort Columns

4. Use Alt+Mouse Dragging or Alt+Shift+Arrows to select the “colums” you want to move:

Screenshot of selecting columns


5. Drag the columns to the start of the first line. You can also Cut (CTRL+X) the selected columns, move the caret to the start of the first line, then Paste (CTRL+V) the columns there.

Screenshot of dragging columns

6. Select all the text and use Sort Lines Lexicographically Ascending:

Screenshot of sorting lines alphabetically
Click Edit → Line Operations → Sort Lines Lexicographically Ascending

7. We have now sorted the text alphabetically by the first “columns”:

Screenshot of lines sorted alphabetically

Summary

Do you already have text formatted as columns? Then you can edit these columns by pressing the Alt key while selecting text. You can use either Alt+Mouse Dragging or Alt+Shift+Arrows.

Do you not already have text formatted as columns? No problem! Quickly fix this first by using the Line up multiple lines by (Clipboard Character) option in the TextFX plugin.

About the Author

Cathrine Wilhelmsen is a Microsoft Data Platform MVP, BimlHero Certified Expert, Microsoft Certified Solutions Expert, international speaker, author, blogger, and chronic volunteer who loves teaching and sharing knowledge. She works as a Senior Business Intelligence Consultant at Inmeta, focusing on Azure Data and the Microsoft Data Platform. She loves sci-fi, chocolate, coffee, craft beers, ciders, cat gifs and smilies :)

Comments

Hi! This is Cathrine. Thank you so much for visiting my blog. I'd love to hear your thoughts, but please keep in mind that I'm not technical support for any products mentioned in this post :) Off-topic questions, comments and discussions may be moderated. Be kind to each other. Thanks!

Great!
Very useful for a quick reorder and to view a csv in column mode.

Tranks

Thank you, nice trick.

This made me fall in love with notepad++

I have the same need, more or less. But the text I have to work with is already tabbed, and the columns may vary in length (e.g. the text in line 1, field A is longer than the one in line 2, field A: that results in line 1, field B to be “one tab further” than line 2, field B – so that it’s impossible to exactly select “the columns to move”. Any suggestion on how to do that?

(I know my explanation is terrible, I can send you the text I’m working with if needed)

I think I understand what you mean, and I will attempt to explain how I solve that kind of problem. (If my explanation is not good enough or I misunderstood you, please feel free to e-mail me your example.)

If the character that separates your “columns” is a tab, you won’t be able to line up multiple lines by using the tab character. There are a couple of different ways you can get around this, you will just have to experiment to find the solution that works best for you. Basically you will have to manipulate the separator, then do the editing, then manipulate the separator again:

1. Replace all tabs with a tab and a second character, for example a vertical line.
2. Line up multiple lines by the second character. You will now have equally sized “columns” that you can move.
3. Replace all tabs plus the second character with a single tab, or whatever else you need to use as the separator

1. Replace all tabs with a whole bunch of tabs so you’re sure that there is enough whitespace between each “column”
2. The columns are not aligned, but you will be able to select one column at the time
3. Replace all tabs with a single tab, or whatever else you need to use as the separator

It worked like a charm, thank you so much!

Hi Catherine, first of all, I am new to Notepad++. Like in Seans comment, my data is already separated by tabs. I tried both of the solutions you described afterwards, but they did not work out. I tried different plugins, and they are not helping either :(

thank you so much, it worked perfectly :)

Thank you for that.
There is an issue with a single line, though.

A single line CSV cannot be ordered that way. It’s not a huge issue, but I’m still waiting for a “no exception” solution to this.

VERY helpful. Thanks!

Great tutorial, but I have a csv with more than 100.000 rows… there is a way to use ALT+SHIFT and go to the last row quickly? (I tried ALT+SHIFT+CTRL+END but it doesnt work :(

You can’t do it with keyboard commands (that I know of), but you can do it a different way. Put your cursor on the first line in your file, in the column you want the column selection to start, say column 12. Then use your mouse to drag the scrollbar to the bottom. Scroll right or left until the other side of your column select is in view. Now, Alt-Shift-left-click in that column and it will select from the first row to the row you clicked in.

Thank you very much Scott. It worked (with Alt-Shift-leftclick) !!!

You’re very welcome. Notepad++ is amazing, but does have its idiosyncrasies.

Masterpiece!

Great post, thanks! Ever run into a memory error? I tried this on a file with about 50k records, but “not enough memory.” Thought I’d see if you ever ran into the same. Thanks again!

Hi Catherine, Thanks much for this very practical site. I have a question that’s been plaguing me for some time concerning multiple column editing…How do you move data up or down in a column without moving data in an adjacent column. I tried everything. I know how to move a line or multiple lines of text with Shift+CTRL, but I only want to move data in a particular column without affecting adjacent columns. Thanks in advance. ~ Sean.

Hi Sean, I’m not sure this is even possible, at least I haven’t found a way to do it in Notepad++ yet. Maybe some of my other readers know how to achieve this? (This is the kind of task I use Excel for, since Excel is built for working with rows, columns and cells.)

Hi, Catherine and Sean. A bit late, but Notepad++ has a “column mode” editing, see here:

https://notepad-plus-plus.org/features/column-mode-editing.html

It’s far from perfect, but maybe you can can use that to achieve what you want.

if there is a ‘ (apostrophe) somewhere in the line, the line up doesn’t seem to work. Is it a known bug ?

I don’t know if it’s a known bug, you’d have to ask the Notepad++ author about that, but I’ve also had problems with apostrophes and slashes. Sometimes it works if you escape the characters (like adding another slash), other times I have simply replaced the characters with something else and then replaced it with the original value afterwards. It’s not the most perfect solution, but it’s usually quicker than other methods :)

Hi Cathrine,

I found out the “Line up multiple lines by (Clipboard Character)’, reformatting my csv file into readable columns. It works fine wit one file at a time, but I have to reformat a few hundred files. Can I do this reformatting with TextFX in one action over all open files?

@P, here is a method for aligning columns in a file that uses Regex replace in any editor. It does require a little footwork since you have to specify the alignment columns (where textfx dynamically calculates the best alignment column) but it can be used in many files, and you can save it off to use later.

• First, replace all commas with 50 spaces (however many you need to guarantee the commas are in free columns) followed by a comma. This is only to give you space to work.
• Now, we must choose the column we want for the first comma, say column 50, then the column for the second comma, and continue until we have defined a match for each comma. So, we create a regular expression to do this, like:
o ^([^,]{50,50})( *,)([^,]{15,15})( *,)(.+)$
o This grabs the first 50 non-comma characters and creates a group out of them,
o the second group is the extra spaces we need to remove in each line followed by a comma,
o the third group is the next 15 non-comma characters,
o the fourth group is again the extra spaces we need to remove,
o the fifth group is everything else.
• The replace string for this regex is:
o 1,3,5
o This pastes in the first, third, and fifth columns with commas inbetween (effectively deleting the blocks of spaces you don’t want, resulting in aligned characters).
• A good way to test this is to use one of the regex web sites, paste in part of one file.
• Now all you have to do is tell notepad++ to run this replacement in all opened documents.

To clarify, I should have said to replace all commas with 50 spaces plus the original comma, so you would run a replace in all files for “,” to ” ,”. I don’t know if that second string will display properly, but it’s 50 space characters followed by a comma.

One more clarification, if you want the commas in each group to be before the spaces rather than after do a search and replace of “( +),” with “,1”. This matches all spaces before a comma, and pastes in as a comma followed by the exact spaces that were there before, so your columns remain lined up, but the commas are moved.

Also, if it wasn’t clear, you would duplicate the groupings for all available columns and do the replace of all of them at once. This is assuming that all of your files share the same number of columns and can be processed with the same column widths. You could encapsulate this whole thing in a macro as well, if you are going to edit many files over time with this same structure (Catherine has blog entries to help with that).

thanks for this helpfully hint! Saves a lot of time and reduce some confusion with some files I have to deal.

Thanks a lot Cathrine! How many years I did that manually in Notepad++ and lost a lot of time, and now one google later I landed on that page and it does exactly what I needed, just great!

In SQL you always have “AS columnName”, which doesn’t seem to work with TextFX, because it’s more than one character. In that case I found “code alignment” where you can specify “Align by ..” and then you type your ” AS “. Works perfectly good as well.
Here the link I found that lead me to this Plugin: https://stackoverflow.com/questions/8808127/looking-for-an-easy-way-to-align-text

Thanks nice tips and helpfull

What a brilliant blog! How you fit the rest of life in around all the work you do beats me. But thank you very much for spurring my interest in trying to be the best at ‘some little helpful things’ in my office. :)

Thanks for sharing! For some reason the regex in the post doesn’t work on my Notepad++. The regex I used is \s*\| instead of +|\
All other instructions worked perfectly.

Second time in a day that I ended up here, and second time that it was the perfect answer to my question!

Thank you very much!

Few people try to present the use of the plugin in such a simple way based on examples. I’m here for the first time at your place at , and probably .05.2019 not the last one because a lot of learning in front of me.

Hi! This is Cathrine (again). Just a reminder. I'd love to hear your thoughts, but please keep in mind that I'm not technical support for any products mentioned in this post :) Off-topic questions, comments and discussions may be moderated. Be kind to each other. Thanks!

Leave a Reply to Eric Cancel reply