Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
vim:函数中未定义的变量_Vim - Fatal编程技术网

vim:函数中未定义的变量

vim:函数中未定义的变量,vim,Vim,我的.vimrc文件包括以下几行: let read_path = '/var/www/html/readContent.html' function ReadContentProcess() if (expand('%:p') == read_path) call feedkeys("\<C-A>") call feedkeys("\<C-V>") endif endfunction 为什么??我已经将read\u pa

我的
.vimrc
文件包括以下几行:

let read_path = '/var/www/html/readContent.html'
function ReadContentProcess()
    if (expand('%:p') == read_path)
        call feedkeys("\<C-A>")
        call feedkeys("\<C-V>")
    endif
endfunction

为什么??我已经将
read\u path
定义为一个变量,为什么vim告诉我它不存在?

变量有一个默认范围。在函数外部定义时,它具有全局作用域
g:
。在函数内部,它有一个局部作用域
l:
。因此,您需要通过在
read\u path
前面加
g:

let read_path = '/var/www/html/readContent.html'
function ReadContentProcess()
    if (expand('%:p') == g:read_path)
        call feedkeys("\<C-A>")
        call feedkeys("\<C-V>")
    endif
end function
let read_path = '/var/www/html/readContent.html'
function ReadContentProcess()
    if (expand('%:p') == g:read_path)
        call feedkeys("\<C-A>")
        call feedkeys("\<C-V>")
    endif
end function
global-variable g:var g: Inside functions global variables are accessed with "g:". Omitting this will access a variable local to a function. But "g:" can also be used in any other place if you like. local-variable l:var l: Inside functions local variables are accessed without prepending anything. But you can also prepend "l:" if you like. However, without prepending "l:" you may run into reserved variable names. For example "count". By itself it refers to "v:count". Using "l:count" you can have a local variable with the same name.