在 Vim 函数中获取没有文件扩展名的文件名 [英] Get the file name without file extension in a Vim function

查看:43
本文介绍了在 Vim 函数中获取没有文件扩展名的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆