Search code examples
bashvimautocmd

bash script "ignores" .vimrc


I have a problem as follows:

I have a script which copies a log file from remote machine, does some modification on it and then opens it in vim, problem is vim doesn't auto recognize the file type (which outside of the script id does) – I need this for coloring the log.

Script as follows:

/usr/bin/rcp 14.1.61.10$node:/output/LocalLog_IPNode$node.log /export/home/fpd/tmp/tmp_local_log

chmod 777 /export/home/fpd/tmp/tmp_local_log/*

sed -i 's/[A-Z]\{4,8\}.*[oigus][kbdct][sel]\//---/g' /export/home/fpd/tmp/tmp_local_log/LocalLog_IPNode$node.log
vi  /export/home/fpd/tmp/tmp_local_log/LocalLog_IPNode$node.log

My .vimrc:

au BufNewFile,BufReadPost LocalLog* set filetype=local_log

Note that the files opens in vim (if it helps the manual command ":set syntax=local_log" doesn't work either).

After exiting the script and manually opening the log everything works fine =(


Solution

  • Your problem is that the autocommand option is only availaible in vim and not vi.

    So if this is available on your system, you should replace the last command line by :

     vim  /export/home/fpd/tmp/tmp_local_log/LocalLog_IPNode$node.log
    

    Vim stands for "Vi Improved" and many options are only available in the latter.

    To be sure you can do:

    :help autocommand
    

    It is always mentioned if the feature is vi or vim compatible.