~otheb/tidywhities

Simple Vim plugin for tidying up the whitespace in your files
Ignore double-indents.
Modified indent logic so double indents are kept too.
Modified logic to try and continue to correctly align with spaces when

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~otheb/tidywhities
read/write
git@git.sr.ht:~otheb/tidywhities

You can also use your local clone with git send-email.

                              ### TIDY WHITIES ###

Small and simple Vim plugin to "fix" the whitespace in your code files according
to some simple rules.

	* All trailing whitespace is removed.
	* Leading whitespace is reduced to the maximum number of tabs that will fit,
	  followed by spaces to get the position the same.
	* Where a line's indent is greater than `tabstop` more than the previous
	  line, it is assumed to be "aligned" rather than "indented", so some tabs
	  are expanded to spaces so the number of tabs is the same between the line
	  and the line before (see examples).
	* Where a line has identical leading whitespace length to the previous, the
	  indent string is copied over.
	* It is assumed that the user already has everything in the right *place*,
	  and only wants messy whitespace to be fixed. This plugin won't (shouldn't)
	  move anything around.

### EXAMPLES

Take this example code with unclean and disparate whitespace. Trailing
whitespace is marked with '_'s, leading tabs are marked with '|-->'s, and
leading spaces are marked with '.'s.

	for ( ulong i = 0 ; i < max ; i ++ ) {
	|-->int    x = i + 3   ;
	....string s = "hello" ;
	....methodcall( i , s ,__
	|-->|-->|-->|-->"some other string" ,_
	|-->............1234 ) ;
	}

We all agree this is horrible yes? Some lines are indented with tabs and others
with spaces, the method arguments moved onto following lines are aligned in
different ways, and some lines have trailing spaces. Let's run the plugin and
see what it does.

	for ( ulong i = 0 ; i < max ; i ++ ) {

This line is untouched as there is nothing wrong with it.

	|-->int    x = i + 3   ;
	|-->string s = "hello" ;

The spaces on the second of these two lines are converted to a tab as it is
being indented. Notice also how none of the whitespace aligning the variable
names or semicolons is touched at all. This plugin attempts to abide to the rule
of "indent with tabs; align with spaces".

	|-->methodcall( i , s ,
	|-->............"some other string" ,
	|-->............1234 ) ;

This is the most interesting bit. The overhanging parameters are aligned, not
indented, so the indent should only go as far as that of the first of these
lines. If the tabstop were to be changed, because the alignment is with spaces,
the parameters will stay lined up rather than being thrown off to the right.

### INSTALLATION

This plugin should install perfectly fine with a plugin manager like Plug
(shown), Pathogen, or Vundle.

	call plug#begin('...')
	" other plugins here
	Plug 'https://gitlab.com/OTheB/tidywhities'
	" other plugins here
	call plug#end()

### USAGE

The plugin exposes just the one function: TidyWhities. Create a binding to the
command. For instance, I have this binding (the second command is from
YouCompleteMe).

	nnoremap <BS> :TidyWhities<CR>:silent! YcmForceCompileAndDiagnostics<CR>

Or if you just want it by itself:

	nnoremap <somekey> :TidyWhities<CR>