8

Very close to reverse of this question. I prefer coding with 2-whitespace indentation, but need to have files indented with tabs to align with project convention. What I would like to do is preferably automatically convert 2 spaces upon entry to tab symbol in Notepad++ and have the editor configured to tab length of 2.

A possible manual way for doing this could be Edit->Blank Operations->Space to TAB but this converts all of my spaces to tabs, even those of length 1 - which are, for example, spaces between function arguments, not just leading spaces.

In a perfect case scenario I'm trying to achieve formatting style as described in this question, but with typing just spaces and the editor taking care of the rest.
I'm on Notepad++ 6.0, but willing to upgrade if this helps

Community
  • 1
  • 1
Sergii Zaskaleta
  • 502
  • 1
  • 4
  • 21

2 Answers2

8

Let me complete the answer of Ari Okkonen to add a workaround to the problem commented by Sergii Zaskaleta of mixed tabs and spaces at the beginning of the line.

  1. Settings->Preferences->Tab Settings->Tab size: 2 (if not already)
  2. Edit->Blank Operations->Space to TAB (Leading)
  3. Select a block of lines of text with the problem of mixed spaces and tabs. Press [Tab] and [Shift]+[Tab] to add and remove a tab from each line. In the process, the leading spaces had been converted to tabs.
txema
  • 116
  • 1
  • 3
5

A manual way that seems to work: After having edited the file before saving you may try (Works in Notepad++ v6.8.3):

  1. Settings->Preferences->Tab Settings->Tab size: 2 (if not already)
  2. Edit->Blank Operations->Space to TAB (Leading)
Ari Okkonen
  • 165
  • 1
  • 10
  • I've checked and its good. Sadly, there's a somewhat of a limitation: leading [Tab][Tab][Space][Space] does not get converted to [Tab][Tab][Tab], whereas [Space][Space][Tab] becomes [Tab][Tab] and [Space][Space][Tab][Space][Space] become [Tab][Tab][Tab]. Anyways, an improvement already, thank you! – Sergii Zaskaleta Dec 16 '15 at 11:19