Skip to content

Instantly share code, notes, and snippets.

@HeLiBloks
Created May 12, 2016 13:24
Show Gist options
  • Save HeLiBloks/77299deaa6768edc452e907b263b6e9c to your computer and use it in GitHub Desktop.
Save HeLiBloks/77299deaa6768edc452e907b263b6e9c to your computer and use it in GitHub Desktop.
different vim functions
"returns visual selection
function! s:get_visual_selection()
" Why is this not a built-in Vim script function?!
let [lnum1, col1] = getpos("'<")[1:2]
let [lnum2, col2] = getpos("'>")[1:2]
let lines = getline(lnum1, lnum2)
let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][col1 - 1:]
return join(lines, "\n")
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment