开发者

Using variables in a vim shell command

开发者 https://www.devze.com 2023-03-25 04:10 出处:网络
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 tryi

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消