12

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?

7
  • 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 ... Feb 5, 2018 at 9:05
  • Is it available for Windows? Feb 8, 2020 at 17:50
  • 1
    yes it is ... see the answer I just posted ... Feb 8, 2020 at 18:38
  • 1
    merci for the bounty! Feb 13, 2020 at 21:46
  • 1
    what exactly do you mean with the last phrase in your last comment? Feb 15, 2020 at 9:25

4 Answers 4

2
+100

Even though I'm not retired yet, I'm "old enough to remember the ISPF editor on IBM mainframes": I still use (and love) it more or less every day ...

To actually answer your question, I suggest you have a look at SPFLite. Here is a quote about it, from Wikipedia:

Editors used in the PC environment typically operate in a significantly different manner than those in operation on large Mainframe systems. PC editors are almost universally character stream oriented while mainframe editors are typically text line oriented. Users who need to work on both PCs and mainframes thus need to become productive in two differing work styles.

SPFlite is a free file manager and text editor which provides, on Windows PCs, a familiar working environment for those who are used to IBM's mainframe based ISPF. As well as providing the basic ISPF functional compatibility, SPFLite has added extended facilities to enhance editing abilities.

Once you open a file in edit mode, you should be able to solve your (sample) question with only this (primary) edit command:

c beer fish 10 20 all

But wait, there is more ... If you'd also label your line 2 with (say) .f and your line 4 with .l, your bonus question can be answered with this command:

c beer fish 10 20 all .f .l

Easy, no?

13

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

12
  • 7
    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, 2014 at 12:26
  • 2
    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! Jun 10, 2014 at 2:43
  • 2
    This has inspired me to code some plugins of my own (which is what I ought to have done int he first place) Jun 10, 2014 at 2:46
  • 2
    @Mawg You are very welcome :) Thank you very much for your nice feedback.
    – ComFreek
    Jun 10, 2014 at 12:23
  • 2
    This was too tempting to not post a competing answer ... Feb 8, 2020 at 18:39
12

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.

6

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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