From 39a3560bdfb0cc3935dfa6b4cd2cdb03a1fc4001 Mon Sep 17 00:00:00 2001 From: Lucas Noki Date: Sun, 15 Dec 2019 22:25:06 +0100 Subject: [PATCH] Load vimrc into memory for safer editing Allow plugins to be installed after initial run --- modules/vim/module.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/vim/module.py b/modules/vim/module.py index 7793f73..13d8593 100644 --- a/modules/vim/module.py +++ b/modules/vim/module.py @@ -40,9 +40,14 @@ class VimModule(IModule): vimrc_exists = os.path.isfile("testfile") if vimrc_exists: - vimrc_file = open("testfile", "a+") - vimrc_file.write("\n" + plugins[selection][1]) - vimrc_file.close() + with open("testfile", "r") as vimrc_in_file: + buf = vimrc_in_file.readlines() + + with open("testfile", "w") as vimrc_out_file: + for line in buf: + if line == "call plug#begin('~/.vim/plugged')\n": + line = line + plugins[selection][1] + "\n" + vimrc_out_file.write(line) else: vimrc_file = open("testfile", "w+")