Skip to content

Instantly share code, notes, and snippets.

@mhinz
Created October 26, 2013 19:21
Show Gist options
  • Save mhinz/7173477 to your computer and use it in GitHub Desktop.
Save mhinz/7173477 to your computer and use it in GitHub Desktop.
"
" Works in visual line and visual block mode.
"
" Select one character more in visual block mode...
"
function! Transform(prefix, suffix)
let [startcol, endcol ] = [col("'<"), col("'>") ]
let [startline, endline] = [line("'<"), line("'>")]
let startcol = '%'. (startcol ? startcol : 1) .'c'
let endcol = endcol ? ('%'. (endcol) .'c') : '%10c'
execute startline.','.endline.'s/\v'.startcol.'(.*)'.endcol.'/'.a:prefix.'\1'.a:suffix.'/'
endfunction
vnoremap <leader>M :<c-u>call Transform('<% ', ' %>')<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment