[autocmd] Cleanup and created functions for repetitive tasks

Change-Id: I6a4b08c08cddac804a2615a3984a198be9ec41d5