I like to have a small window at the top of a tab page for reference. Useful when you want to consult the exact wording of a assignment or task description. This function creates a split with the top window showing the area of your visual mode selection. If more than one window is visible, it reuses the top most. Update (2008-06-18): The script now yields two windows: A “main” one, and the one showing only the selection.
Put something like this in your .vimrc:
vnoremap <M-s> :<C-u>call VisualSplit()<Cr>
function! VisualSplit()
let top = getpos("'<")[1]
let bot = getpos("'>")[1]
let height = bot - top + 1
normal <Esc>
only
split
execute "1 wincmd w"
" position and size the top window
execute "normal '<z" . height . "<Cr>z<Cr>"
" return to 'main' window
execute "normal <C-w>2<C-w>"
endfunction