开发者

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

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 selectio开发者_C百科n. 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?


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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜