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
rmodifier for %, with%:rinstead 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.