AllenHu
AllenHu

Reputation: 601

In the vim plugin script, how to get the path of the file?

I am writing a vim plugin, how can i get the absolute path according to an file?

for example,

let s:file="/home/ABC/ABC.txt"

how to get the path string /home/ABC?

Upvotes: 2

Views: 258

Answers (1)

romainl
romainl

Reputation: 196456

You can use the fnamemodify() function:

let s:dir = fnamemodify(s:file, ":p:h")

See :help fnamemodify() for details on that function.

See :help filename-modiers for the meaning of :p:h.

See :help file-functions for a list of file-related functions and hit <C-]> on a function name to jump to its documentation. You can do the same for list-functions, buffer-functions and so on. Handy, isn't it?

Upvotes: 3

Related Questions