I want to conveniently remove an accidentally placed tab while using vim. The solution that jumped out to me is making an insert-mode mapping to the following vim function:
function DeleteTab()
redir => l:numSpaces "captures output of set
set tabstop?
redir END
"Strip off non-numerical output of 'set tabstop?'
let l:numSpaces = substitute(l:numSpaces, "tabstop=", "", "")
let l:numSpaces = substitute(l:numSpaces, " ", "", "g")
"all echom lines are for debugging purposes
echom "1"
if l:numSpaces > 0
echom "2"
while 1:numSpaces > 0
execute "normal i<bs>"
let l:numSpaces = l:numSpaces - 1
endwhile
endfunction
In addition to not doing what I intended, the result of calling this function is "1" in my messages, but not "2". This means that l:numSpaces is not being interpreted as a number. How do I do the equivalent of casting in vimscript. Also, am I missing a more easy approach?