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.