Vim Tips Wiki
We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 4: Line 4:
 
|previous=843
 
|previous=843
 
|next=846
 
|next=846
|created=2005
+
|created=January 5, 2005
 
|complexity=basic
 
|complexity=basic
 
|author=Anders Thøgersen
 
|author=Anders Thøgersen
|version=6.0
+
|version=5.7
 
|rating=1/7
 
|rating=1/7
 
|category1=
 
|category1=
Line 22: Line 22:
 
nnoremap wq :silent! normal mpeld bhd `ph<CR>
 
nnoremap wq :silent! normal mpeld bhd `ph<CR>
 
</pre>
 
</pre>
 
==See also==
 
*{{script|id=1697|text=surround.vim}} plugin to surround text with brackets, quotes; much more
 
   
 
==Comments==
 
==Comments==
Line 40: Line 37:
 
vmap <silent> <Leader>qs :call Quote("'")<CR>
 
vmap <silent> <Leader>qs :call Quote("'")<CR>
 
vmap <silent> <Leader>qd :call Quote('"')<CR>
 
vmap <silent> <Leader>qd :call Quote('"')<CR>
function! Quote(quote)
+
function! Quote(quote) " {{{
 
let save = @"
 
let save = @"
 
silent normal gvy
 
silent normal gvy
Line 46: Line 43:
 
silent normal gvp
 
silent normal gvp
 
let @" = save
 
let @" = save
endfunction
+
endfunction " }}}
 
</pre>
 
</pre>
   
Line 53: Line 50:
 
<pre>
 
<pre>
 
" Quote a word consisting of letters from iskeyword.
 
" Quote a word consisting of letters from iskeyword.
 
fun! Quote(quote)
nnoremap <silent> qw :call Quote('"')<CR>
 
nnoremap <silent> qs :call Quote("'")<CR>
 
nnoremap <silent> wq :call UnQuote()<CR>
 
function! Quote(quote)
 
 
normal mz
 
normal mz
 
exe 's/\(\k*\%#\k*\)/' . a:quote . '\1' . a:quote . '/'
 
exe 's/\(\k*\%#\k*\)/' . a:quote . '\1' . a:quote . '/'
 
normal `zl
 
normal `zl
  +
endfun
endfunction
 
   
function! UnQuote()
+
fun! UnQuote()
 
normal mz
 
normal mz
 
exe 's/["' . "'" . ']\(\k*\%#\k*\)[' . "'" . '"]/\1/'
 
exe 's/["' . "'" . ']\(\k*\%#\k*\)[' . "'" . '"]/\1/'
 
normal `z
 
normal `z
  +
endfun
endfunction
 
  +
 
nnoremap <silent> qw :call Quote('"')<CR>
 
nnoremap <silent> qs :call Quote("'")<CR>
 
nnoremap <silent> wq :call UnQuote()<CR>
 
</pre>
 
</pre>
   
 
----
 
----
 
*{{script|id=1697|text=surround.vim}} includes this functionality
Surround current word or visually selected text with double quotes:
 
  +
<pre>
 
  +
----
nnoremap <Leader>" ciw"<C-r>""<Esc>
 
vnoremap <Leader>" c"<C-r>""<Esc>
 
</pre>
 
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel Editing help (opens in new window)