1

When I select some text in a column, replace/in selection will become grey. How can I replace text only within a column of selected text in Notepad++?

  • I can only replace column selected text by first column select and cut, then paste cut text to new lines, then select thos text and replace, then cut and paste to the original place. It's not easy. – Fisher Mar 20 '15 at 18:33
  • How are your columns delimited? Tabs? – Excellll Mar 26 '15 at 20:36
  • Columns are selected by ctrl+alt+left-click. – Fisher Mar 27 '15 at 10:41
  • 1
    Hi, that's not what I asked. In your file, what character(s) are in between columns? Is it a tab? Several spaces? This is important because the best workaround I see is to use regular expressions to search and replace in a way that doesn't require you to select down a column. – Excellll Mar 27 '15 at 14:31
  • Yes, I know. But it doesn't matter. Suppose it's just just a big chunk of random text, it doesn't have to be any "column" at all. :) – Fisher Mar 28 '15 at 4:12
0

This is an annoying limitation of notepad++, but there are a couple of ways to solve this problem. First, if you know the column limitations that you want to replace any occurrences of the word "dog" with "cat" within columns 4 and 10, then do this:

RE search string: ^(.{3})(.{0,3})dog(.{0,3})(.*)$

RE replacement string: \1\2cat\3\4

To break this down:

^          - Must match from the beginning of the line
(.{3})     - match any three characters from the line
(.{0,3})   - match 0-3 characters from the line
dog        - match "dog"
(.{0,3})   - match 0-3 characters from the line
(.*)       - match everything else
$          - up to the end of the line

Caveats to this approach First, make sure you have . matches \n unchecked, this would mess it up. Mixing tabs and spaces won't work, since regular expressions see tabs as just single characters.

Another solution that will work with mixed tabs and spaces Column select the last column you want to search in. Then type a character that isn't otherwise in the file, for example '|' or '!'.

Column select the first column you want to search in. Do the same thing as before (it can be the same character or a different one).

Now, search for your text within those boundaries.

RE search string: |(.*)dog(.*)|

RE replacement string: |\1cat\2|

You want to leave your marker characters since you will probably not match every line in your file and you'll want to remove all of them in a second step (either with column select and delete, or with another search/replace).

-1

I use the Find/Replace dialog that is presented when you enter Ctrl-r. In the Find/Replace dialog there is a field to enter column numbers. This allows you limit the the Find/Replace to these columns in the file. Normal and regular expression Find/Replace are supported. I could not find how to do this Find/Replace via the Ctrl-h dialog.

enter image description here
Find/Replace dialog (Ctrl-r)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.