> I expect it to break with tabs etc in the filename too.
call append(6, map(readfile('/tmp/chosenfiles'), '"Attach:
".substitute(v:val,''\s'',''\\ '',"g")'))
This should handle even tabs. I also replaced the insert line with 6. Here is
the whole thing:
| " mutt: insert attachment with ranger
| fun! RangerMuttAttach()
| if filereadable('/tmp/chosendir')
| silent !ranger --choosefiles=/tmp/chosenfiles
--choosedir=/tmp/chosendir "$(cat /tmp/chosendir)"
| else
| silent !ranger --choosefiles=/tmp/chosenfiles
--choosedir=/tmp/chosendir
| endif
| if filereadable('/tmp/chosenfiles')
| call append(6, map(readfile('/tmp/chosenfiles'), '"Attach:
".substitute(v:val,''\s'',''\\ '',"g")'))
| call system('rm /tmp/chosenfiles')
| endif
| redraw!
| endfun
| map <C-a> :call RangerMuttAttach()<CR>
| imap <C-a> <ESC>:call RangerMuttAttach()<CR>a