Is there any way to convert all spaces to tabs, not file by file?
If I open a file and go through View => Indentation => Convert Indentation to Tabs, it only changes this file. I want to convert indentations to tabs in a whole project.
Use search and replace in multiple files to convert n spaces to tabs in select files.
First open find in files panel, cmd + shift + f, by default to find and replace in multiple files. Next define a regular expression to match spaces as tabs eg {4} (make sure you set Regular Expressions in the panel) for 4 spaces and replace with \t in desired files. Change {4} to however many spaces are being used for indentation.
As mentioned in comments to match spaces at the start of a line you can use the regexp ^( {4})+
Related
I need to edit a piece of code that looks like this both in Sublime and PyCharm (a small portion of a large source file):
I am not sure what kind of modern code editor (and innovative methodology calling for mixing tabs and spaces within a single line) authors were using, but somehow their indentation looks reasonably in on github (so I guess all team members were using Atom?) - I checked and the page source code still involves \t symbols.
The python -m py_compile command seems happy with this code as is, so I tried replacing tabs with 8 spaces, still looks horribly. Any attempt to replace these with 'fixed number' of spaces did not work either, including 5 spaces that is presumably the number or   browser is supposed to use). The file does not have CRLF endings, I checked.
I tried using a formatter that uses Python 2.7 AST internally, it says that indentation is wrong, so still no luck.
My attempt to find some logic behind the number of tabs and supposed number of spaces lead to following observations:
2 spaces + tab + 4 spaces => 12 spaces
sstssss ->
ssssssssssss (12 spaces) => t = 6 spaces
example
for |<- these pipes should be one on top of the other
|correct_t
sst ->
ssssssss (8 spaces) => t = 6 spaces
example
|writer.add_scalar('eval/acc', acc, epoch)
|if acc >= best_acc:
but
ssstsssss ->
sssssssssssss (13 spaces) => t = 5 spaces
|best_acc = acc
|model.save_networks('best'+str(epoch))
Oh, I have figured the solution! I set tab width to 8 spaces in sublime and then it works as expected, i.e. instead of replacing each \t with 8 spaces it 'tabs' them up to 8 spaces!
In linux one can do the same thing via expand -t 8 <filename>.
I am using visual studio code Version 1.19.3, and I have 174 occurrences of a specific json object which I would like to replace with a different object. Is there an easy way to do this in visual studio code? find and replace doesn't work because of the tabs.
You can search and replace tabs in vscode but perhaps you have your tabs converted to spaces as your default indentation. If you try Ctrl-Shift-P and "Convert Indentation to Tabs" then search and replace for \t will work as you expect (with the Use Regular Expression button clicked).
Then you could back to indentation with spaces by Ctrl-Shift-P and "Convert Indentation to Spaces" if you wish when you are done.
How to write a key binding to replace specific character to another one?
For example I want to replace "[" and "]" to empty string "".
Unfortunately, to make a custom key binding you would need to write a plugin in Python to do the finding and replacing, as there are no built-in commands for doing so. However, what you want to do is easily accomplished using the Find -> Replace... dialog. Make sure the regular expressions button is selected, then put \[|\] in the Find What: box, and nothing in the Replace With: box (it's best to put your cursor in there and delete everything, just in case there are invisible characters such as spaces or tabs there). Hit Replace to replace characters one at a time, or Replace All to replace all of them in one go.
I'm liking HAML but running into annoyances with tabs vs spaces. Is there an easy way to convert a file from one to the other in TextMate?
I prefer tabs but I'm seeing spaces used alot...wondering if that's preferred or if that's an artifact of code I've seen posted to the web?!? I don't really care though it would seem, to me, that tabs would be simpler to work with...
It's as simple as this: Text > Convert > Spaces to Tabs
I prefer tabs over spaces too (as long as they are size of 2 spaces).
Edit:
Textmate 2: 'Bundles > Source > Convert Tabs to Spaces'
Shortcut: ⌃⇧⌘T (ctrl + shift + cmd + t)
Now I'm all in for spaces with soft tabs always on ;)
I have a macro that I wrote to convert tabs in spaces, and another one for spaces to tabs:
Just start a macro recording, do a Find and Replace (with Replace all) finding (tabs or spaces) and replacing with (the other one).
How do I make it so that instead of indenting my elements by multiples of 2 spaces (when formatting without wrapping is selected), HTMLTidy indents them by multiples of tabs (4 spaces long but only 1 byte in size)?
The HTML Tidy docs say that tidy never outputs tabs. But, since you're in Notepad++, you can use TextFX Edit -> Leading space to tabs to convert the spaces that HTMLTidy gives you into tabs. Just make sure that indent-spaces is set to 4 in your config file.
The location of your config file will vary depending on how you installed notepad++ and what version you have, but its path will probably look like one of these
C:\Program Files\Notepad++\plugins\NPPTextFX\tidycfg.ini
C:\Program Files\Notepad++\plugins\Config\tidy\tidycfg.ini