Reputation: 1459
I'm writing a vim script where I need to get the first line of the current buffer. In Ex mode I can simply type 1
and it shows me the content I want.
How can I put the output of the ex command into a variable in vim?
Upvotes: 2
Views: 736
Reputation: 196516
Chris's answer is the right approach.
Note however, that you can use the :redir
command to capture the output of an Ex command into a variable:
:let myvar = ""
:redir => myvar
:command
:redir END
See :h :redir
for more information.
Upvotes: 4
Reputation: 90742
The expression you want is getline(1)
. Thus, let x = getline(1)
.
Upvotes: 1