Can you convert tabs to spaces in selected text?
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 5
- Joined: Tue Nov 18, 2003 2:23 pm
Can you convert tabs to spaces in selected text?
I'd like to leave my tabs in documents as they are, when creating them, or when saving the file. But sometimes, I'd like to convert the tabs to spaces in a specific, selected block of text. Is this possible?
- s_reynisson
- Posts: 939
- Joined: Tue May 06, 2003 1:59 pm
1. Select Block Select Mode from the Configure menu, or
hold down the alt-key while selecting with your mouse.
2. Press F8 for Replace, find \t, replace " " (space), the
Selected text radio button should be selected already.
(3. Make sure "Convert New tabs to Spaces" and
"Convert Existing Tabs to Spaces When Saving Files"
are unchecked for the relevant document class, use
Default for all.)
HTH
hold down the alt-key while selecting with your mouse.
2. Press F8 for Replace, find \t, replace " " (space), the
Selected text radio button should be selected already.
(3. Make sure "Convert New tabs to Spaces" and
"Convert Existing Tabs to Spaces When Saving Files"
are unchecked for the relevant document class, use
Default for all.)
HTH
Then I open up and see
the person fumbling here is me
a different way to be
the person fumbling here is me
a different way to be
-
- Posts: 5
- Joined: Tue Nov 18, 2003 2:23 pm
Hi s_reynisson,
Thanks for quick response. I'm aware of the process for replacing regular expressions, things like double spacing paragraphs and the like. I was thinking of doing what you described, but thought, this is not really going to work, since the various tab symbols in my selection need to be replaced with varying quantity of spaces. I tried your suggestion and this turn out to be the case, I think, unless I'm missing something.
If I have "Convert New tabs to Spaces" or "Convert Existing Tabs to Spaces When Saving Files" ticked in preferences, it does exactly what I want: replace tabs with an APPROPRIATE number of spaces to match the spacing which existed previously, with each tab symbol. The number of spaces varies.
But, I don't want to apply this globally. The only way I can see to cobble a solution:
1. Cut and paste the selection to a new document.
2. Tick "Convert Existing Tabs to Spaces When Saving Files"
3. Save the new document
4. Select all and copy.
5. Untick "Convert Existing Tabs to Spaces When Saving Files"
6. Paste my selection back into the original document.
7. Delete the new document I've created.
Thanks for quick response. I'm aware of the process for replacing regular expressions, things like double spacing paragraphs and the like. I was thinking of doing what you described, but thought, this is not really going to work, since the various tab symbols in my selection need to be replaced with varying quantity of spaces. I tried your suggestion and this turn out to be the case, I think, unless I'm missing something.
If I have "Convert New tabs to Spaces" or "Convert Existing Tabs to Spaces When Saving Files" ticked in preferences, it does exactly what I want: replace tabs with an APPROPRIATE number of spaces to match the spacing which existed previously, with each tab symbol. The number of spaces varies.
But, I don't want to apply this globally. The only way I can see to cobble a solution:
1. Cut and paste the selection to a new document.
2. Tick "Convert Existing Tabs to Spaces When Saving Files"
3. Save the new document
4. Select all and copy.
5. Untick "Convert Existing Tabs to Spaces When Saving Files"
6. Paste my selection back into the original document.
7. Delete the new document I've created.
- s_reynisson
- Posts: 939
- Joined: Tue May 06, 2003 1:59 pm
-
- Posts: 5
- Joined: Tue Nov 18, 2003 2:23 pm
Does the new document class have to have a different extension? Sounds like cobble #2, first impression. I tryed to create one, "tabs to spaces", and told it to use extension ".txt", and it warned me this was taken, so I cancelled out. Would I have to be creating separate files, with separate filename extensions?? Sounds awkward, if that's the case. I'd just like to work in ".txt" extension files, and be able to do this within any file, without rigamorol.
I suspect it just isn't possible at present, at least not in a simple, direct way. Wish list item???
I suspect it just isn't possible at present, at least not in a simple, direct way. Wish list item???
-
- Posts: 5
- Joined: Tue Nov 18, 2003 2:23 pm
Ok, if I tick just the convert new tabs to spaces in the text document class, copy the tabbed text, then paste, it comes in with spaces. If I then untick that same box, and do another paste, it comes in with tabs. Relatively painless. Helps that the configure menu remembers where you just were. Thanks for the suggestions, I'll muddle off now.
- Tomas Eklund
- Posts: 40
- Joined: Tue Mar 16, 2004 1:15 am
- Location: Sweden
Should be on the wishlist though..
"Replace tabs with spaces" and "Replace spaces with tabs" really should be easily accessible menu options - not something you have to create document classes and use clumsy workarounds for. Working with a file that uses real tabs is a lot smoother I think, but sometimes you need to temporarily convert the tabs to spaces - like when you send the file to a program, printer, whatever that doesn't handle tabs very well.
I need to do these conversions back and forth every now and then. And when I do, I have to resort to a different editor (EditPad Pro), which has this feature.
So... Put it on the todo-list please! Shouldn't be too hard to implement either.
I need to do these conversions back and forth every now and then. And when I do, I have to resort to a different editor (EditPad Pro), which has this feature.
So... Put it on the todo-list please! Shouldn't be too hard to implement either.
- s_reynisson
- Posts: 939
- Joined: Tue May 06, 2003 1:59 pm
- Tomas Eklund
- Posts: 40
- Joined: Tue Mar 16, 2004 1:15 am
- Location: Sweden
Are you an opponent of useful, lightweight features? ;-)
I know about the "convert existing tabs to spaces on save" feature and it may come in handy at times, but for this purpose it's useless. First of all, I don't want to have to do five clicks and a save in order to do the tabs-to-spaces conversion. One single keystroke please. Secondly, I want to be able to convert back from spaces to tabs, and the workaround can't do that. (And even if it could, it would still be a workaround -- and workarounds are, and always will be, workarounds.)
I know about the "convert existing tabs to spaces on save" feature and it may come in handy at times, but for this purpose it's useless. First of all, I don't want to have to do five clicks and a save in order to do the tabs-to-spaces conversion. One single keystroke please. Secondly, I want to be able to convert back from spaces to tabs, and the workaround can't do that. (And even if it could, it would still be a workaround -- and workarounds are, and always will be, workarounds.)
- s_reynisson
- Posts: 939
- Joined: Tue May 06, 2003 1:59 pm
*hick!* No. Agreed!
and while Helios scramble their forces on this you could record two macros(*):
1. Ctrl-Shift-R, F8, find "_{4}", replace "\t", replace all, close, Ctrl-Shift-R
2. Ctrl-Shift-R, F8, find "\t", replace "____", replace all, close, Ctrl-Shift-R
Where _=space and tick regular expression in the replace dialog
Goto Configure->Preferences->Keyboard and assign shortcuts to the macros
I'm using 4 spaces as my indentation and now Ctrl-Shift-A and Q "toggle" nicely for me.
Not perfect and you risk loosing your shortcuts and macros on diffrent systems if you don't transfer your settings etc... on the plus side it only takes you two or three minutes to do this.
(*) denotes a workaround
and while Helios scramble their forces on this you could record two macros(*):
1. Ctrl-Shift-R, F8, find "_{4}", replace "\t", replace all, close, Ctrl-Shift-R
2. Ctrl-Shift-R, F8, find "\t", replace "____", replace all, close, Ctrl-Shift-R
Where _=space and tick regular expression in the replace dialog
Goto Configure->Preferences->Keyboard and assign shortcuts to the macros
I'm using 4 spaces as my indentation and now Ctrl-Shift-A and Q "toggle" nicely for me.
Not perfect and you risk loosing your shortcuts and macros on diffrent systems if you don't transfer your settings etc... on the plus side it only takes you two or three minutes to do this.
(*) denotes a workaround
Then I open up and see
the person fumbling here is me
a different way to be
the person fumbling here is me
a different way to be
- Tomas Eklund
- Posts: 40
- Joined: Tue Mar 16, 2004 1:15 am
- Location: Sweden
I do appreciate your attempts to help out. However, I'm afraid I'm still out of luck... (well, I do have EditPad Pro and I use it right now so it's not as bad as it sounds)
I don't think it's possible to create a regexp search-and-replace that accurately replaces spaces with tabs - nor the other way around. You have to consider that a tab sometimes should be replaced with one space character, sometimes with two, three or four. (I also use four space indentation.) Because tabs aren't used for indentation only.
For a while I thought: Perhaps it would work if I created a sequence of search-and-replace operations like this (see below)? But it will not work. Because when a tab is inserted at a certain position it will count as only one character even though it occupies the space of 1-4 characters.
find "^_{4}" replace "\t"
find "^([^ \t]{1})_{3}" replace "\1\t"
find "^([^ \t]{2})_{2}" replace "\1\t"
find "^([^ \t]{3})_{1}" replace "\1\t"
find "^([^ \t]{4})_{4}" replace "\1\t"
find "^([^ \t]{5})_{3}" replace "\1\t"
I don't think it's possible to create a regexp search-and-replace that accurately replaces spaces with tabs - nor the other way around. You have to consider that a tab sometimes should be replaced with one space character, sometimes with two, three or four. (I also use four space indentation.) Because tabs aren't used for indentation only.
For a while I thought: Perhaps it would work if I created a sequence of search-and-replace operations like this (see below)? But it will not work. Because when a tab is inserted at a certain position it will count as only one character even though it occupies the space of 1-4 characters.
find "^_{4}" replace "\t"
find "^([^ \t]{1})_{3}" replace "\1\t"
find "^([^ \t]{2})_{2}" replace "\1\t"
find "^([^ \t]{3})_{1}" replace "\1\t"
find "^([^ \t]{4})_{4}" replace "\1\t"
find "^([^ \t]{5})_{3}" replace "\1\t"
- Tomas Eklund
- Posts: 40
- Joined: Tue Mar 16, 2004 1:15 am
- Location: Sweden
I just HAVE to bring this up again
Gosh, I would've liked that feature right now... :-/
Are Helios Software Solutions really responsive to feature requests made in this forum? I haven't been around long enough to tell.
It's interesting to see how much work some people here put down into making complex workarounds to problems that should be really easy for Helios to fix.
Perhaps I should contact them directly on this matter?
Are Helios Software Solutions really responsive to feature requests made in this forum? I haven't been around long enough to tell.
It's interesting to see how much work some people here put down into making complex workarounds to problems that should be really easy for Helios to fix.
Perhaps I should contact them directly on this matter?
- s_reynisson
- Posts: 939
- Joined: Tue May 06, 2003 1:59 pm
Helios staff frequent here in the forums, at least two of them anyway. You can contact them directly at http://textpad.com/support/feedback.php , set the form "type" to "feedback". You can also start a poll to back you up, ie. if its simple to implement and does not affect TP regarding performance and/or size etc. you are likely get a good response on it.
Polls are posted in the Enhancement Suggestions forum and take care to use five options, that way it will be counted/included in Jeffy's list, scroll down to view the latest version.
Polls are posted in the Enhancement Suggestions forum and take care to use five options, that way it will be counted/included in Jeffy's list, scroll down to view the latest version.
Then I open up and see
the person fumbling here is me
a different way to be
the person fumbling here is me
a different way to be
Easy... if REAL regex were supported
I am pulling my hair out-- I wish Textpad had the same support for RegEx as Perl does.
To solve your problems, if TextPad support REAL regex, you could do it with this single search and replace:
Search:
^\s{1,4}
Replace:
\t
That would search for a minimum of 1 space, up to 4 spaces, and replace them with the tab character. But of course, TexPad barfs horribly on such a statement.
I myself am trying to search for multiple instances of the space character (2+) and replace them with a single space. In perl, the following would work:
Search:
\s{2,}
Replace:
\s
But not in TextPad... grrrrr.... "\s" searches for the "S" character (?!?!) and not the space character. WTF?
As far as I am concerned, TextPad has a crippled and limited support of RegEx, and I think I am going to stick with Perl to do all my search/replace when RegEx is involved.
Hey Mendel Leisk,
If you are still needing to do the aformentioned, reply to this and let me know. I'll post a simple perl program, and you can download/install the ActivePerl for Win32, and run the program against your file.
To solve your problems, if TextPad support REAL regex, you could do it with this single search and replace:
Search:
^\s{1,4}
Replace:
\t
That would search for a minimum of 1 space, up to 4 spaces, and replace them with the tab character. But of course, TexPad barfs horribly on such a statement.
I myself am trying to search for multiple instances of the space character (2+) and replace them with a single space. In perl, the following would work:
Search:
\s{2,}
Replace:
\s
But not in TextPad... grrrrr.... "\s" searches for the "S" character (?!?!) and not the space character. WTF?
As far as I am concerned, TextPad has a crippled and limited support of RegEx, and I think I am going to stick with Perl to do all my search/replace when RegEx is involved.
Hey Mendel Leisk,
If you are still needing to do the aformentioned, reply to this and let me know. I'll post a simple perl program, and you can download/install the ActivePerl for Win32, and run the program against your file.
- Tomas Eklund
- Posts: 40
- Joined: Tue Mar 16, 2004 1:15 am
- Location: Sweden
Nope... Still not easy
It is true that TextPad's support for regular expressions are very limited and I'm hoping for an improvement soon. However, what you are trying to accomplish is rather easy, even using TextPad.
You don't need the \s to search for a space character. Just type the space character in explicitly. Like this:
Search:
^_{1,4}
Replace:
\t
However, that is NOT the same as doing a "convert spaces to tabs" operation. To accomplish that you need more programming than just a simple regexp
Replacing multiple spaces with a single one is easy:
Search:
_{2,}
Replace:
_
Where _ is the space character - just press the space bar in the search and replace boxes. I made it a red underscore here so that it would be visible. You can even get away with:
Search:
_+
Replace:
_
You need to get a little more complicated than that (but just a little) in order to outgrow TextPad's regex-flavor.
You don't need the \s to search for a space character. Just type the space character in explicitly. Like this:
Search:
^_{1,4}
Replace:
\t
However, that is NOT the same as doing a "convert spaces to tabs" operation. To accomplish that you need more programming than just a simple regexp
Replacing multiple spaces with a single one is easy:
Search:
_{2,}
Replace:
_
Where _ is the space character - just press the space bar in the search and replace boxes. I made it a red underscore here so that it would be visible. You can even get away with:
Search:
_+
Replace:
_
You need to get a little more complicated than that (but just a little) in order to outgrow TextPad's regex-flavor.