tabular icon indicating copy to clipboard operation
tabular copied to clipboard

Expose if there's a last used pattern

Open somini opened this issue 10 years ago • 2 comments

Define a function to check if Tabularize has been called yet, meaning that executing :Tabularize will reuse the last pattern.

The use-case for this is defining a single mapping that either calls Tabularize directly if there's a saved pattern, or prompts you for a pattern. Like this:

function TabularizeThisN()
    if exists('g:tabular_loaded')
        let l:cmd = ':Tabularize'
        if exists('*TabularizeHasPattern') && TabularizeHasPattern()
            " Reuse the last Tabularize command
            let l:cmd .= "\<CR>"
        else
            let l:cmd .= "\<Space>"
        endif
        return l:cmd
    endif
endfunction
nnoremap <expr> <LocalLeader><Tab> TabularizeThisN()

somini avatar Aug 08 '15 08:08 somini

Rebased this to the latest master.

somini avatar May 07 '16 08:05 somini

I like this... sounds like a great addition

scottchiefbaker avatar Jul 17 '20 18:07 scottchiefbaker