How to Solve Error vim :call CompileRunGcc()

Fault description
Modify the ~/.vimrc configuration file to run the py script with one click. The
content of the vimrc configuration file is as follows

map <F5> :call CompileRunGcc()<CR>

func! CompileRunGcc()
    exec "w" 
    if &filetype == 'c' 
        exec '!g++ % -o %<'
        exec '!time ./%<'
    elseif &filetype == 'cpp'
        exec '!g++ % -o %<'
        exec '!time ./%<'
    elseif &filetype == 'python'
        exec '!time python %'
    elseif &filetype == 'sh'
        :!time bash %
    endif                                                                              
endfunc 

vim a.py press F5 as follows

Use script

" <f5> run python programmer
map <f5> :w<cr>:!python %<cr>

Can run normally

In other words, the contents of the function body cannot be executed.

 

The cause of the fault
was resolved on December 23, 2020. The cause of the /etc/profilealias alias vim='/usr/bin/vi, there is an alias in the file , that is, the vim command actually uses vi

Solution
to /etc/profilefile alias vim='/usr/bin/vichange alias vim='/usr/bin/vimcan be.

Here are the solutions to other problems
. The VI in Centos only installs vim-minimal-7.x by default. No matter you enter vi or vim to view the file, the syntax function cannot be enabled normally. Therefore, two other components need to be installed with yum: vim-common-7.x and vim-enhanced-7.x.

#View vim components
[[email protected] ~]# rpm -qa | grep vim
vim-enhanced-7.4.629-7.el7.x86_64
vim-filesystem-7.4.629-7.el7.x86_64
vim-X11-7.4.629-7.el7.x86_64
vim-common-7.4.629-7.el7.x86_64
vim-minimal-7.4.629-7.el7.x86_64

#install vim
yum -y install vim*


Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *