Programmatically execute vim commands?

I'm interested in setting up a TDD environment for developing Vim scripts and rc files. As a simple example, let's say I want vim to insert 8 spaces when I press the tab key. I would install a script that did the following:

  • Launch vim using the isolated .vimrc file.
  • press i
  • click tab
  • press esc
  • click: w test_out
  • claim test_out contains ''

The default config is in vim, this will not work. However, as soon as I add set expandtabto my .vimrc file, the test will pass.

How to programmatically issue these commands? vim -c <commands>close but seems to work only for ex mode commands. Any suggestions? This question seems to be fully protected by Google.

+3
2

vim -S <script in> , , vim -w <script out>.

VIM -s -w.

+4

vim ? , sed .

, vim , ex

#!/bin/sh
# insert a tab as the first character of test_out
ex test_out <<EOF
s/^/^I/
wq
EOF

if [ `od -c test_out | awk 'NR == 1 {print $2}'` != '\t' ] ; then
    echo "assertion failed"; exit 1;
fi

^I a Tab. .

+1

Source: https://habr.com/ru/post/1749838/


All Articles