Skip to content

Instantly share code, notes, and snippets.

@3N4N
Created April 2, 2019 02:55
Show Gist options
  • Save 3N4N/dcb97927119626d5d93c0c4f029fd8d5 to your computer and use it in GitHub Desktop.
Save 3N4N/dcb97927119626d5d93c0c4f029fd8d5 to your computer and use it in GitHub Desktop.
com! -bar -range=% RemoveTabs call s:remove_tabs(<line1>,<line2>)
fu! s:remove_tabs(line1, line2) abort
let view = winsaveview()
let mods = 'sil keepj keepp'
let range = a:line1 . ',' . a:line2
let pat = '\%(^\s*\)\@!\&\(.\)\t'
let l:Rep = {-> submatch(1) . repeat(' ', strdisplaywidth("\t", col('.') == 1 ? 0 : virtcol('.') ))}
let g = 0
while search("\t", 'n') && g < 999
exe mods . ' ' . range .'s/' . pat . '/\=l:Rep()/ge'
let g += 1
endwhile
call winrestview(view)
endfu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment