Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the content of the current buffer in vim command mode?

Tags:

vim

There is a vim function Send_to_Screen(text) which sends some text to a console screen session. I have a mapping

vmap <F4> "ry :call Send_to_Screen(@r)<CR>

which calls the function with the current selection. Now I want do define another mapping which calls the function with the contents of the whole buffer, but I don't get it to work. I tried

nmap <F5> maggVG"ry`a :call Send_to_Screen(@r)<CR> 

but it doesn't work. So how do I define the mapping with the text of the current buffer?

like image 874
Peter Hoffmann Avatar asked Aug 17 '10 12:08

Peter Hoffmann


1 Answers

How about:

nmap <F5> :call Send_to_Screen(join(getline(1,'$'), "\n"))<CR>

The function getline() returns a list of lines in the selected range (1 is the first line and "$" is the last) and the function join() joins the contents of a list together with the provided separator ("\n" in this case). See:

:help getline()
:help join()
like image 55
DrAl Avatar answered Sep 28 '22 10:09

DrAl