How do I run a vim script that alters the current buffer?
Posted
by
Dan
on Stack Overflow
See other posts from Stack Overflow
or by Dan
Published on 2011-02-27T22:32:44Z
Indexed on
2011/02/27
23:25 UTC
Read the original article
Hit count: 302
I'm trying to write a beautify.vim script that makes C-like code adhere to a standard that I can easily read.
My file contains only substitution commands that all begin with %s/...
However, when I try to run the script with my file open, in the manner :source beautify.vim
, or :runtime beautify.vim
, it runs but all the substitute commands state that their pattern wasn't found (patterns were tested by entering them manually and should work).
Is there some way to make vim run the commands in the context of the current buffer?
beautify.vim:
" add spaces before open braces
sil! :%s/\%>1c>\s\@<!{/ {/g
" beautify for
sil! :%s/for *( *\([^;]*\) *; *\([^;]*\) *; *\([^;]*\) *)/for (\1; \2; \3)/
" add spaces after commas
sil! :%s/,\s\@!/, /g
In my tests the first :s command should match (it matches when applied manually).
© Stack Overflow or respective owner