4

Lets say I have text This is result file output_20DeC. Let's say my cursor is on o. When I use the command gf, it should open output_20Dec.txt file.

So how do I tell vim to add a default extension to the word under my cursor before opening file?

6

To quote the help:

                            *gf* *E446* *E447*
[count]gf       Edit the file whose name is under or after the cursor.
            Mnemonic: "goto file".
            Uses the 'isfname' option to find out which characters
            are supposed to be in a file name.  Trailing
            punctuation characters ".,:;!" are ignored. Escaped
            spaces "\ " are reduced to a single space.
            Uses the 'path' option as a list of directory names to
            look for the file.  See the 'path' option for details
            about relative directories and wildcards.
            Uses the 'suffixesadd' option to check for file names
            with a suffix added.

The key there is the section on 'suffixesadd'; setting to include .txt should do the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.