Now if I select something in visual mode, is there some way to get the selected area without having to yank it to some register?I looked through :h functions but didn't find anything.
Way to get content of Visual Selection?
cut copy paste;visual mode;functions
If you really want to avoid the registers, you can use the visual marks to figure out byte positions of the selected text:function! s:pos2byte(pos) abort    return line2byte(a:pos[1]) + a:pos[2]endfunctionfunction! s:get_visual_text() abort    let b1 = s:pos2byte(getpos('<))    let b2 = s:pos2byte(getpos('>))    let text = ''    while b1 < b2        let l = byte2line(b1)        let lb = line2byte(l)        let line = strpart(getline(l), b1 - lb - 1)        let text .= line        let b1 += len(line)    endwhile    return strpart(text, 0, len(text) - (b1 - b2) + 1)endfunctionIt works well enough, but there's something about it that I don't trust.  I think it might need more checks to make sure an infinite loops doesn't happen, and it won't work on visual blocks.I prefer using the temporary register method because I don't have to think too hard about what's going to happen.  This is the proper way to do it if you want to leave the buffer state undisturbed:function! s:get_visual_text() abort     Save the window's view because `gv` may change the scroll position.    let view = winsaveview()     Preserve the yank/change marks    let m1 = getpos('[)    let m2 = getpos('])     Preserve the 'a' register, as well as what kind of register it is.    let reg_val = getreg('a')    let reg_type = getregtype('a')     Yank text into the 'a' register and get the text    normal! gvay    let text = getreg('a')     Restore the 'a' register    call setreg('a', reg_val, reg_type)     Restore the yank/change marks    call setpos('[, m1)    call setpos('], m2)     Restore the window's view    call winrestview(view)    return textendfunction