Created
June 4, 2013 16:30
-
-
Save oelmekki/5707373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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