Skip to content

Instantly share code, notes, and snippets.

@abatkin
Created May 6, 2013 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abatkin/5523093 to your computer and use it in GitHub Desktop.
Save abatkin/5523093 to your computer and use it in GitHub Desktop.
Map \q to quote each line Map \j to join lines with a comma Map \s to quote and join all lines Works in visual mode only Great for taking a list of things and quoting for use in an SQL query
vnoremap <leader>q :<c-u>call <SID>QuoteLines()<cr>
vnoremap <leader>j :<c-u>call <SID>JoinLines()<cr>
vmap <leader>s <leader>qgv<leader>j
function! s:JoinLines()
silent! execute "normal! gv:\<c-u>'<,'>-1s/\\v$/,/g\<cr>gvJ"
endfunction
function! s:QuoteLines()
silent! execute "normal! gv:s/\\v(^\\s*)([^[:space:]].{-})(\\s*$)/\\1'\\2'\\3/\<CR>"
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment