在 Vim 函数中获取没有文件扩展名的文件名 [英] Get the file name without file extension in a Vim function
问题描述
我想在 Vim 中获取没有文件扩展名的文件名.
我在我的 .vimrc
文件中编写了以下函数来编译和运行 Java 程序:
:函数!JAVA_RUN():!javac %^M:结束函数地图 <F3>:执行JAVA_RUN():source $HOME/.vimrc
如何获取函数内部没有扩展名的文件名?
:help expand()
应该会给你答案,见 expand().
您应该使用 r
修饰符作为 %,使用 %:r
而不是 %
来获取没有扩展名的文件名.>
如果您想编写函数来构建和执行文件,您还应该查看 shellescape
,以防止文件名或路径中出现空格问题.
I want to get the file name without the file extension in Vim.
I wrote the following function in my .vimrc
file to compile and run the Java program:
:function! JAVA_RUN()
:!javac %^M
:endfunction
map <F3> :execute JAVA_RUN()<CR> :source $HOME/.vimrc<CR>
How can I get the file name without the extension inside the function?
:help expand()
should give you the answer, see expand().
You should use the r
modifier for %, with %:r
instead of %
to get the file name without extension.
If you want to write functions to build and execute files, you should also have a look at the documentation for shellescape
, in order to prevent problems with spaces in file name or path.
这篇关于在 Vim 函数中获取没有文件扩展名的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!