Hello everyone,
I have a text file that is indented properly, but instead of tabs, the indentation has been done with spaces. Is it possible to replace the spaces with tabs only at the beginning of the line?
In this case, 1 space -> 1 tab.
Thanks!
Anthony
Hi Anthony,
1. Perform a search for this regex: '^ +' (minus quotes) 2. Close the search, place the caret anywhere in the file, and type Opt-Cmd-F 3. Bundle > Source > Convert Spaces to Tabs (make sure to set up your spaces per tab correctly first, so TM converts to the correct number of tabs)
Regards,
Adam
On 29/11/2012, at 9:48 AM, Anthony V. Pulido anthony.pulido@gmail.com wrote:
Hello everyone,
I have a text file that is indented properly, but instead of tabs, the indentation has been done with spaces. Is it possible to replace the spaces with tabs only at the beginning of the line?
In this case, 1 space -> 1 tab.
Thanks!
Anthony
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Hi Adam,
Thank you very much for this. I followed the instructions as well as I could over the last couple of days, and I think I've reached 2 successfully.
I've set Tab size to 1 and tried other numbers, but each time I try step 3, I receive the same result. When I try Bundle > Source > Convert Spaces to Tabs, a couple of lines where the leading spaces have been selected from step 2 are left untouched, and another line's leading spaces are simply deleted and no tabs replace them. In case, I've made sure that the leading spaces are indeed spaces, and not tabs with a size of one space.
Specifically, two lines with one leading space are left untouched, and a line with two leading spaces had its spaces deleted.
I looked in the bundle editor and I see that "Convert Spaces to Tabs" relies on the unexpand command. I've tried running this in the terminal and on a different linux system, without luck.
This might be out of the scope of this list, since we are venturing away from TM, but I hope we can make a small exception in this case...
Just to remind, the goal is to convert leading spaces to tabs. 1 space -> 1 tab. test3.txt is the input file. I've tried
unexpand -t1 test3.txt
unexpand -t1 test3.txt t3.txt
(where t3.txt would be the output file)
with no luck. Would you or someone else be able to tell me what I'm doing wrong? or tell me what in TM I'm doing wrong?
Thanks again!
Anthony
On Nov 28, 2012, at 6:01 PM, Adam Sharp adsharp@me.com wrote:
Hi Anthony,
- Perform a search for this regex: '^ +' (minus quotes)
- Close the search, place the caret anywhere in the file, and type Opt-Cmd-F
- Bundle > Source > Convert Spaces to Tabs (make sure to set up your spaces per tab correctly first, so TM converts to the correct number of tabs)
Regards,
Adam
On 29/11/2012, at 9:48 AM, Anthony V. Pulido anthony.pulido@gmail.com wrote:
Hello everyone,
I have a text file that is indented properly, but instead of tabs, the indentation has been done with spaces. Is it possible to replace the spaces with tabs only at the beginning of the line?
In this case, 1 space -> 1 tab.
Thanks!
Anthony
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 02/12/2012, at 6:53 AM, Anthony V. Pulido anthony.pulido@gmail.com wrote:
I've set Tab size to 1 and tried other numbers, but each time I try step 3, I receive the same result. When I try Bundle > Source > Convert Spaces to Tabs, a couple of lines where the leading spaces have been selected from step 2 are left untouched, and another line's leading spaces are simply deleted and no tabs replace them. In case, I've made sure that the leading spaces are indeed spaces, and not tabs with a size of one space.
Specifically, two lines with one leading space are left untouched, and a line with two leading spaces had its spaces deleted.
Ok, I think it will probably be easier to just do it all from the find and replace dialogue. Set up the search as before, and with regex search/replace enabled it looks like you can put \t in the replace field and hit Replace All, and TM will insert literal tabs for you.
–Adam
I just tried that and it is replacing spaces with tabs now, but it replaces all leading spaces with one tab. I tried it on a line with 19 leading spaces, all of which were replaced with one tab. I have set the tab size to 1, 2, 3, etc., without any change in the outcome.
Anthony
On Dec 2, 2012, at 6:22 PM, Adam Sharp adsharp@me.com wrote:
On 02/12/2012, at 6:53 AM, Anthony V. Pulido anthony.pulido@gmail.com wrote:
I've set Tab size to 1 and tried other numbers, but each time I try step 3, I receive the same result. When I try Bundle > Source > Convert Spaces to Tabs, a couple of lines where the leading spaces have been selected from step 2 are left untouched, and another line's leading spaces are simply deleted and no tabs replace them. In case, I've made sure that the leading spaces are indeed spaces, and not tabs with a size of one space.
Specifically, two lines with one leading space are left untouched, and a line with two leading spaces had its spaces deleted.
Ok, I think it will probably be easier to just do it all from the find and replace dialogue. Set up the search as before, and with regex search/replace enabled it looks like you can put \t in the replace field and hit Replace All, and TM will insert literal tabs for you.
–Adam
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Would anyone know how to fix this so that 1 leading space -> 1 tab?
Thank you!
Anthony
On Dec 2, 2012, at 8:32 PM, Anthony V. Pulido anthony.pulido@gmail.com wrote:
I just tried that and it is replacing spaces with tabs now, but it replaces all leading spaces with one tab. I tried it on a line with 19 leading spaces, all of which were replaced with one tab. I have set the tab size to 1, 2, 3, etc., without any change in the outcome.
Anthony
On Dec 2, 2012, at 6:22 PM, Adam Sharp adsharp@me.com wrote:
On 02/12/2012, at 6:53 AM, Anthony V. Pulido anthony.pulido@gmail.com wrote:
I've set Tab size to 1 and tried other numbers, but each time I try step 3, I receive the same result. When I try Bundle > Source > Convert Spaces to Tabs, a couple of lines where the leading spaces have been selected from step 2 are left untouched, and another line's leading spaces are simply deleted and no tabs replace them. In case, I've made sure that the leading spaces are indeed spaces, and not tabs with a size of one space.
Specifically, two lines with one leading space are left untouched, and a line with two leading spaces had its spaces deleted.
Ok, I think it will probably be easier to just do it all from the find and replace dialogue. Set up the search as before, and with regex search/replace enabled it looks like you can put \t in the replace field and hit Replace All, and TM will insert literal tabs for you.
–Adam
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On 07/12/2012, at 4:27 AM, Anthony V. Pulido anthony.pulido@gmail.com wrote:
Would anyone know how to fix this so that 1 leading space -> 1 tab?
Strange, I responded to this, but it isn't showing up in the archives and you clearly never saw it. Quoted below.
–Adam
Begin forwarded message:
From: Adam Sharp adsharp@me.com Subject: Re: [TxMt] Replace spaces with tabs at beginning of line Date: 3 December 2012 1:16:38 PM AEDT To: TextMate users textmate@lists.macromates.com
On 03/12/2012, at 12:32 PM, Anthony V. Pulido anthony.pulido@gmail.com wrote:
I just tried that and it is replacing spaces with tabs now, but it replaces all leading spaces with one tab. I tried it on a line with 19 leading spaces, all of which were replaced with one tab. I have set the tab size to 1, 2, 3, etc., without any change in the outcome.
Ah, of course. Tested it myself this time, and what you need to do is steps 1 and 2 (so you have a document with all leading spaces selected). Then, perform a new find and replace *in the current selection* which replaces a single space with a single tab.
–Adam
Hi Adam, yes, that is strange, but, I don't care! Your solution worked!
Thanks!!
Anthony
PS: ...Hopefully, this list lapse is an isolated case.
On Dec 7, 2012, at 1:21 AM, Adam Sharp adsharp@me.com wrote:
On 07/12/2012, at 4:27 AM, Anthony V. Pulido anthony.pulido@gmail.com wrote:
Would anyone know how to fix this so that 1 leading space -> 1 tab?
Strange, I responded to this, but it isn't showing up in the archives and you clearly never saw it. Quoted below.
–Adam
Begin forwarded message:
From: Adam Sharp adsharp@me.com Subject: Re: [TxMt] Replace spaces with tabs at beginning of line Date: 3 December 2012 1:16:38 PM AEDT To: TextMate users textmate@lists.macromates.com
On 03/12/2012, at 12:32 PM, Anthony V. Pulido anthony.pulido@gmail.com wrote:
I just tried that and it is replacing spaces with tabs now, but it replaces all leading spaces with one tab. I tried it on a line with 19 leading spaces, all of which were replaced with one tab. I have set the tab size to 1, 2, 3, etc., without any change in the outcome.
Ah, of course. Tested it myself this time, and what you need to do is steps 1 and 2 (so you have a document with all leading spaces selected). Then, perform a new find and replace *in the current selection* which replaces a single space with a single tab.
–Adam
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate