8

I got some files have mixed indentation, is there any way I can automatically convert the indentation in Kate?

Giacomo1968
  • 53,069
  • 19
  • 162
  • 212
Wang
  • 763
  • 11
  • 31

7 Answers7

5

Select the text you want to modify, then 'Tools > Clean Indentation'.

audiomason
  • 243
  • 2
  • 5
  • That's sort of an iffy solution. Cleaning the indentation ensures that all your selected text follows the indentation mode you choose. Depending on what mode you chose and why the indentation varies (like what you manually stuck at the beginning of the different lines), the results may be mixed. It may try to at least make all of the indents uniform (not always successful), which may be based on a rule like the least indented line. – fixer1234 Sep 23 '16 at 17:51
  • This seems to work for me, even in cases of mixed indentation. If I have my preference set to "tabs" with four space width, it will replace all of the following with two tabs: eight spaces), four spaces and a tab, a tab and four spaces, and even really mixed cases like six spaces and a tab (which would render as two tab widths). – Stephen Ostermiller Jan 05 '18 at 11:38
  • 2
    Doesn't work for me in case of tabs in between letters, they are not converted to spaces. This is important e.g. for tabs in comments of programming languages. – Everyday Astronaut Feb 22 '18 at 12:21
  • Worked for me in Version 19.08.3. – Paul Feakins Dec 03 '19 at 15:58
5

Try to do Ctrl + A to select all text and then Ctrl + X to cut it and Ctrl + V to paste it back. It will automatically format the indentation accordingly to your settings in Kate configuration.

fywe
  • 849
  • 1
  • 9
  • 16
  • 5
    Not anymore it doesn't – Oleh Prypin Oct 22 '15 at 11:27
  • I can't get this to work either. I have the setting checked: "Settings" -> "Configure Kate..." -> "Editor Component" -> "Editing" -> "Indentation" -> "Adjust indentation of code pasted from the clipboard". It does not appear to convert tabs to spaces or vice-a-versa when pasting. – Stephen Ostermiller Jan 05 '18 at 11:43
  • Works perfectly, converts all tabs, even those which don't have maximum length, to the correct amount of spaces. I do *not* have the box checked that @StephenOstermiller mentioned. Kate version 3.13.3 – Everyday Astronaut Feb 22 '18 at 12:23
  • 1
    I currently have Kate v 17.04.3. It looks like the 3.x versions are several years old. This functionality must be broken in the newer versions. – Stephen Ostermiller Feb 22 '18 at 12:45
1

Select the text you want to modify and run it through 'Tools > Filter Text'. Use command 'expand -t4' (or whatever indentation you want).

Nenad
  • 11
  • 1
1

Use key combination CTRL+R to open the replacement dialog window. Now use mouse and mark one tabulator, press CTRL+C and paste it under "Find" section. Under section "Replace" just input four spaces and click "Replace all".

71GA
  • 141
  • 1
  • 10
  • 1
    you can enter tabulator as "\t" and switch option "escape sequences" ON, no need to do sorcery with ctrl+C/V ... But this will replace tabulator with fixed amount of spaces provided in the replace dialog, so it will break any indentation previously provided by the tab characters. – Ped7g Oct 10 '19 at 19:17
1

If you do Tools -> Switch to Command Line (or you hit F7), you can highlight the text in question and type the command "cleanindentation" in the command box.

0

In version 15.12.3, Try to do Ctrl + A to select all text and then select Tools -> Align.

-1

Ctrl+A -> ↹ Tab -> Shift+↹ Tab

Assumes you've changed your Settings -> Editing Options to Indent using Spaces.

Jawa
  • 3,619
  • 13
  • 31
  • 36