سؤال

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?

هل كانت مفيدة؟

المحلول 2

The expression you want is getline(1). Thus, let x = getline(1).

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top