How would I go about using a variable in a vim shell command (one done with !
) in a开发者_如何学Python vimscript? For instance, something kind of like this: (just an example, not what I'm really trying to do)
function Ls(dir)
!ls a:dir
endfunction
Use the execute
command. Everything after it is an expression that evaluates to a string, which it then executes like a command you had typed in yourself.
function Ls(dir)
execute '!ls ' . a:dir
endfunction
This says, "Evaluate the expression '!ls ' . a:dir
and then execute it." The variable a:dir
is expanded, the dot concatenates the two strings into '!ls whatever'
and then that is executed as if you had typed it.
精彩评论