Replace 'on' and back with one click

    Add to .vimrc:
    function! s:ToggleQuote()
        let q = searchpos("'", 'n', line('.'))
        let qb = searchpos("'", 'bn', line('.'))
        let dq = searchpos('"', 'n', line('.'))
        let dqb = searchpos('"', 'bn', line('.'))
        if q[0] > 0 && qb[0] > 0 && (dq[0] == 0 || dq[0] > q[0])
            execute "normal mzcs'\"`z"
        elseif dq[0] > 0 && dqb[0] > 0
            execute "normal mzcs\"'`z"
        endif
    endfunction
    nnoremap '  :call ToggleQuote()


    If you move the cursor inside the quotation marks and press', then the quotation marks will change to double / single.

    ps. the script uses vim-surround .

    Also popular now: