Toggle between single and double quotes

4 Points

Jakub Miziołek Jakub Miziołek

10 years ago

Sometimes you have by mistake used wrong type of quotes. With this mapping you can use ' to change between single and double quotes.

nnoremap <leader>' ""yls<c-r>={'"': "'", "'": '"'}[@"]<cr><esc>

uksza

uksza 10 years ago

Of course there is a plugin for that: Surround.vim
cs"'
and
cs'"

Jakub Miziołek

Jakub Miziołek 10 years ago

Yes, but with this line you don't have to think from which quotes to which quotes. And double quotes require pressing Shift to insert :D

Florian Beer

Florian Beer 10 years ago

That's what Vim is about: Less thinking, less typing :)

yang-ling

yang-ling 10 years ago

This snippet is different from my expectation. I thought it will change the quotes surrounding the words, just like surround.vim, but it only changes the quote under the cursor, which is like r' or r"

It will be much better and helpful if you can improve it.

My expectation:

1 "hello <cursor>world"

2 type <leader>'

3 Become 'hello <cursor>world'

Rom Grk

Rom Grk 8 years ago

For the record, this https://gist.github.com/romgrk/dc871a06975b787d70bc40e2cd7feeae is a little more than a snippet but it adds the possibility to exchange the surrounding simple/double quotes on cs''. Otherwise delegates to surround.vim.