3

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

  • Launch vim using a sandboxed .vimrc file
  • press i
  • press tab
  • press esc
  • press :w test_out
  • assert that test_out contains ' '

by the default config in vim, this would fail. However, once I add set expandtab to my .vimrc file, the test will pass.

How do I programmatically issue these commands? vim -c <commands> is close, but seems to only work for ex mode commands. Any suggestions? This question seem to be thoroughly google-proof.

2 Answers 2

5

You can try vim -S <script in> and, for your convenience, the opposite vim -w <script out>.

For more details on these options check VIM's documentation for the -s and -w arguments.

Sign up to request clarification or add additional context in comments.

Comments

1

Is using vim a requirement? If it isn't you are using the wrong tool for the job, sed might be more appropriate.

But if you must, you can do it with vim anyway, just call it 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

Where ^I is actually a Tab. Although this is a very odd approach.

1 Comment

Yes, the idea is to do TDD on vim plugins and the like. I suppose I could do TDD on an external shell script and then map to it from with in Vim, but that's not quite what I want. Largely I'm interested in better understanding what I am lifting from other people's .vimrc files and plugin directories.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.