Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8474599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:40:19+00:00 2026-06-10T17:40:19+00:00

I am writing a rudimentary Vim template for Java files that creates a bare

  • 0

I am writing a rudimentary Vim template for Java files that creates a bare skeleton class when I create a new file with the .java extension.

Example:

vim Banana.java

Vim creates a file including code like this:

public class TODO {
    public static void main(String[] args) {
    // ...

My objective is to change my default class name, TODO, to the name of the file without the extension so that:

vim Coconut.java

creates:

public class Coconut {

rather than:

public class TODO {

How can I achieve that, please? I have searched the site and there are scripts that extract the name in a variable and perform :substitute in the right place, but I don’t know how to locate the right place and position the filename there.

I read my template files by extension from my .vimrc:

autocmd BufNewFile * silent! 0r $HOME/vimfiles/templates/%:e.vim_template

or:

autocmd BufNewFile * silent! 0r $HOME/.vim/templates/%:e.vim_template

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T17:40:21+00:00Added an answer on June 10, 2026 at 5:40 pm

    I believe that this might help? http://vim.wikia.com/wiki/Insert_current_filename

    With this you can get the current filename:

    expand("%:t:r")
    

    Specifically, you are probably looking for this:

    %s/TODO/\=expand("%:t:r")/g
    

    A full example:

    function! NewFile()
        silent! 0r $HOME/vimfiles/templates/%:e.vim_template
        s/FILENAME/\=expand("%:t:r")
    endfunction
    
    autocmd BufNewFile * call NewFile()
    

    You could also give something like tSkeleton a try, I’ve never tried myself but it seems to solve this problem for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to make a rudimentary FSM in a class, and am writing it
Writing a lexer of .java source files in Java. I have a stream of
Writing a file utility to strip out all non-ASCII characters from files. I have
Writing htaccess that allows me to remove index.php from the URL can confuse search
Writing documentation in html requires some code examples. What to do with characters that
Writing a client application that sends images to a server via a webservice. As
I want to unit test a Java application that fetches mails from an email
Writing some classes for a Framework extension, and I have the following code: public
I'm writing a rudimentary screen scraper tool as an FF add-on (using DOM and
I'm writing an client application that has to query a URL and confirm the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.