Dealing with 2 space codebase

I like more pronounced indents, this codebase I am working in (typescript) is two space indents, and I am trying to find the best way to handle it. I have some hacky 2 space to real tab then back on save – but it is wonky and I sort of hate it.

Wondering if anyone has a better recommendation.

I can’t test because I’m on my phone right now, but test with the replace-ranges highlighter.

  1. Declare a range-specs option to store the coordinates for indenting, alongside with the characters to replace with.
  2. Add a hook to update that option when the buffer changes.
  3. Add a replace-ranges highlighter with that option in parameter.

i’m on my phone right now

you don’t have kakoune on your phone?

1 Like

@alexherbo2 that is a great idea. Since it is just a highlighter, it isn’t mucking with the file so I don’t have to worry about any sort of accidental damage to the source, and as a bonus, this lets me do stuff like https://github.com/dodie/vim-fibo-indent completely in the view of the file rather than the file itself!

@andreyorst I just added ssh and man in my Termux.

One issue, if I put in coords 1.1, 1.3 — if I replace it with more than 3, it just overtypes what is after it, and I am not sure how to insert like a tab.

Replace spaces with tabs and adjust the width of them after.

I am not sure how to insert a tab, I naively tried \t and <tab>.

Any clue on how to do the expansion style indent (can’t insert tabs thus far). I just want to VIEW two spaces at ilke 16 (8 space indent universal truth).

I think there was a plugin for Vim that automatically detected indentation level based on file you’re editing. I guess someone have to implement such a thing and use the method described by @alexherbo2 using replace-ranges highlighter to set 2 spaces to 16 spaces. E.g. a plugin should detect how many spaces are being used and set needed amount of spaces:

int main() {
  return 0; // detects 2 spaces as 1 indentation level
}

int main() {
        return 0; replaces 2 spaces with 8 spaces as 1 indentation level
} 

int main() {
    return 0; // detects 4 spaces as 1 indentation level
}

int main() {
        return 0; replaces 4 spaces with 8 spaces as 1 indentation level
}

Edit: here it is: https://github.com/tpope/vim-sleuth