7

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

6 Answers 6

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.

4
  • 4
    Not anymore it doesn't Oct 22, 2015 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. Jan 5, 2018 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 Feb 22, 2018 at 12:23
  • 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. Feb 22, 2018 at 12:45
5

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

4
  • 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, 2016 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). Jan 5, 2018 at 11:38
  • 1
    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. Feb 22, 2018 at 12:21
  • Worked for me in Version 19.08.3. Dec 3, 2019 at 15:58
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".

1
  • 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, 2019 at 19:17
0

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

0

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

0
-1

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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