9

If anyone out there is old enough to remember the ISPF editor on IBM mainframes, then you know what I mean. For the rest of you ...

I am looking for a free editor which allows me to edit only particular columns of a text file (preferably only on a series of contiguous lines).

NotpePad++, Crimson Editor (which seems to be longer in development, alas), and UltraEdit (which is not free, alas), all claim a column mode, but that is only the ability to copy/paste rectangular areas of a text file.

While that is certainly nice, I want to he able to search/replace text and be able to restrict it to a a range or of contiguous columns, preferably also on a range of contiguous lines.

A poor example:

Tim likes beer  
Toms likes beer very much  
Bob does not like either beer or wine  
Ann likes beer, and also wine (and the Oxford comma ;-)

and here is is again, with some line & column numbers:

           1         2         3         4   
  1234567890123456789012345678901234567890   
1 Tim likes beer  
2 Toms likes beer very much  
3 Bob does not like either beer or wine  
4 Ann likes beer, and also wine  

If I want to change all "beer" to "fish" between columns 10 and 20, the result would be (changes capitalized).

           1         2         3         4 
  1234567890123456789012345678901234567890  
1 Tim likes FISH
2 Toms likes FISH very much
3 Bob does not like either beer or wine<=== not changed, not between cols 10 & 20
4 Ann likes FISH, and also wine

As a bonus, I would like to also restrict it to certain rows, let's say rows 2 though 4, in which case, the result would be:

           1         2         3         4 
  1234567890123456789012345678901234567890  
1 Tim likes beer                       <== not changed, not between lines 2 and 4
2 Toms likes FISH very much
3 Bob does not like either beer or wine <== not changed, not between cols 10 & 20
4 Ann likes FISH, and also wine

Question: does anyone know of a (preferably) free Widows text editor which can do that?

  • 1
    About your "old enough to remember the ISPF editor on IBM mainframes": I still use (and love) it more or less every day ... PS (if you're in for an extra joke): what is the (short) ISPF mesage shown (upper right) if you save a PDS member named "NOT" ... indeed, "member NOT saved" ... Think about a similar message for a member named POSSIBLY ... – Pierre.Vriens Feb 5 '18 at 9:05
11

Notepad++ / 2 Plugins: “Python Script” and “ColReplace”

I wrote a custom plugin for you.

You need:

  1. Notepad++
  2. Python Script - Plugin for Notepad++
  3. ColReplace – follow the installation instructions below


  • All three products are free.
  • All three products run (only) on Windows.
  • ColReplace can replace based on row and column restrictions.

ColReplace

Plugin for Notepad++ which provides a row and column constrained search/replace feature.

I have never coded in Python before, so the code may not be very pythonic. Any suggestions or improvements are welcome!

Installation

  1. Download ColReplace's repository as a ZIP file: click here and extract the files to an arbitrary location.
  2. Open Notepad++
  3. In the menu click Plugins --> Python Script --> New Script
  4. Choose ColReplace.py as the filename and click Save.
  5. Copy the contents of the extracted ColReplace.py into the file which you just created in step #5.

Usage

  1. In the menu click Plugins --> Scripts --> ColReplace.
  2. The appearing dialogs should be self-explanatory.

Screenshots

Admittedly, the user experience could be improved :)

Screenshot #2 Screenshot #3 Screenshot #4 Screenshot #5

  • 6
    However much Notepad++ is of no interest to me personally, a simple +1 does not do justice to a 5 hour turn-around from asking a question about available software to having a custom open-source plugin posted that solves the problem! This is the sort of thing that will make this site great. – Caleb Jun 9 '14 at 12:26
  • Tested & working!! Thanks a 1,000,000. I wish that I could give some of my S.O points as bounty for this. When I get a few more points here, I will come back & reward this. Please remind me if I forget. And, once again, thank you! – Mawg Jun 10 '14 at 2:43
  • This has inspired me to code some plugins of my own (which is what I ought to have done int he first place) – Mawg Jun 10 '14 at 2:46
  • 1
    @Mawg You are very welcome :) Thank you very much for your nice feedback. – ComFreek Jun 10 '14 at 12:23
  • Hey @Mawg ... looks like you still have not granted tha "bounty" you evere promised in your first comment here. With about 2.5K rep these days, what is stopping you from granting 500 points, via such bounty and a reason something like "one of the answers is outstanding"? BTW, how about a line cmd interface like this: c .here .there beer fish (using line labels '.here' and '.there' also, I trust you understand wha I mean ...). – Pierre.Vriens Feb 5 '18 at 9:01
10

The vim editor is able to do this out of the box¹. There is a simple Windows installer for gvim or various builds are available for installation through Chocolaty, cygwin, etc.

Vim is a mode editor, meaning that there are several states the editor window can be in, including insert (where you intput text), normal (where keystrokes activate commands that manipulate the text) and visual (where you can select blocks of text).

Visual mode can select text in one of three ways:

  • Character-wise selects ranges of characters across one or more lines.

  • Line-wise selects whole lines.

  • Column-wise selects a rectangular block of characters bounded by row/column positions.

The latter is activated by moving your cursor over one corner of your rectangle in normal mode and hitting Ctrlv, then moving the cursor to the other corner. At this point you will see the column highlighted.

Next you need to issue a search and replace command that finds matches inside the current (or last) visual selection:

 :%s/\%Vbeer/fish/g

Note that this will match any instances of "beer" that start inside your selection even if they end outside it. You would anchor both sides of the search in be inside the selection if you did not want this behaviour:

:%s/\%Vbeer\%V/fish/g 

Also note that the leading % in this command tells vim to operate on the whole file. If go straight to command mode (by hitting :) from visual mode, the prompt will be pre-filled out with the prefix :'<,'> which operates on just the selected range. It is fine to use this, but as the search and replace function operates line-wise, you still need to use the \%V to actually match inside the selection only.

:'<,'>s/\%Vbeer/fish/g

For a quick run through of some other things you can do with column mode, check out this VimCast video.

¹ That does not mean you will be able to just use the editor out of the box. There is an old joke that if you want a good string of random text, sit a non-programmed down with VIM and ask them to quit the editor. If you are not familiar with using vim, it might be worth spending a few minutes with some introductory tutorial so you at least know the basics of how to open, edit, save and quit the editor. The usage paradigm is a bit different than most applications you may use regularly on Windows. It can be very powerful, but take the time to get your head around the basics before attempting the more advanced usage detailed in this answer.

4

SynWrite editor: if you select column block, from line 2 to line 4, and from col 10 to col 20, you 're able to do Replace-All in this selection. (This is option in the Replace dialog).

Rep dialog

  • 1
    +1 Thanks. uvviewsoft.com/synwrite looks nice. Since I already use NotePad++ I will probably continue to use it, but others might want to consider SynWrite – Mawg Jun 13 '14 at 3:11

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.