The expression you want is getline(1)
. Thus, let x = getline(1)
.
Vim - get output of EX mode into a variable
Domanda
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?
Soluzione 2
Altri suggerimenti
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.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow