Tuesday, June 23, 2015

Re: vim replace a string when a change occurred in another place

Erik,
Thanks for your detailed answer. I have choose python (so that it can be called from vim's ftplugin.)

I have checked the standalone python code, which works. But, I put the python code inside vim as:

function! Edname()
python<<EOF
import vim
import fileinput
with open("i.f90") as inp:
for line in inp:
if line.startswith("Program"):
var = line.rsplit(' ', 1)[-1].strip()
if line.startswith("End Program"):
v2 = line.strip()
print v2
inp.close()
STR="End Program "+var
print STR
for line in fileinput.input("i.f90", inplace=True):
print line.replace(v2, STR).strip()
EOF
endfunction

Now it is not working. It is printing the v2 and STR properly, but the file is NOT getting updated.
Any clue?

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment