Skip to content

Instantly share code, notes, and snippets.

@oelmekki
Created June 4, 2013 16:30
Show Gist options
  • Save oelmekki/5707373 to your computer and use it in GitHub Desktop.
Save oelmekki/5707373 to your computer and use it in GitHub Desktop.
" File: replace_quotes.vim
" Author: Olivier El Mekki
" Email: olivier@el-mekki.com
" Description: quick replace of quotes you're inside
" Usage:
" :QuotesToDouble - replaces outer single quotes with double quotes
" :QuotesToSingle - replaces outer double quotes with single quotes
if exists('replace_quotes_plugin')
finish
endif
let replace_quotes_plugin = 1
function! s:QuotesTo( type )
let l:pos = getpos( '.' )
if a:type == 'single'
let l:from = '"'
let l:to = "'"
else
let l:from = "'"
let l:to = '"'
endif
if search( l:from, 'bc', l:pos[1] )
execute 'normal r' . l:to . '<cr>'
call search( l:from, 'c', l:pos[1] )
execute 'normal r' . l:to . '<cr>'
endif
call setpos( '.', l:pos )
endfunction
command! QuotesToDouble call s:QuotesTo( 'double' )
command! QuotesToSingle call s:QuotesTo( 'single' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment