0
votes

Due to a new coding style that I've been having to use I'm required to use tabs in the beginning of lines but spaces everywhere else to align things.

Is there a way to customize notepad++ to only replace tabs with spaces if it's not at the beginning of a new line?

Just as an example of what I mean I'll use this bit of 'code':

function someFunction():
    while(true):
        veryLongCodeStuff()  // Some comment
        shortCode()          // Aligned comment

Which I would have to write like this (where \t = tab and a "." represents a space):

function someFunction():
\twhile(true):
\t\tveryLongCodeStuff()..// Some comment
\t\tshortCode()..........// Aligned comment
1
I don't think it is possible in Npp. You should write a script in your favorite scripting language.Toto

1 Answers

0
votes

To convert existing files, I would suggest a two step approach:

  1. replace all tabs with spaces (this can be done with Edit -> Blank operations -> TAB to Space )
  2. replace spaces at the beginning of lines: do a regular expression find/replace like this:

    • Open Replace Dialog
    • Find What: ^([\t]?)( ){4} instead of 4 use the number of spaces you have configured as tab width
    • Replace With: \1\t
    • check regular expression
    • click Replace All: as each Replace All replaces only one indent level for all lines: repeat until the status bar of the find dialog tells you, that no more replacements were done (just keep Alt-A pressed for a second or two)