Welcome to Vifm Q&A, where you can ask questions about Vifm usage. Registration is optional, anonymous posts are moderated. GitHub or Google logins are enabled.

Pattern to match files with no extentions?

0 votes
asked Oct 5, 2015 in vifm by anonymous
edited Oct 7, 2015 by xaizek

I'm currently running OS X and I'm using filetype * open in the settings to tell vifm to open all the filetypes that have not been explicitly defined in the settings to open with the default program. This a flexible solution, because I don't have to manually enter every single type of file there is and just use what OS X uses by default. The only problem is that I want to open files without extensions with vi, as they are almost always text files in my case. Is there a way of having the best of both worlds?

1 Answer

0 votes
answered Oct 5, 2015 by xaizek

You need to use regular expression patterns for this, they should be specified in slashes. Either explicitly set how to handle files with a dot with vim:

filetype /^[^.]+$/ vim
filetype * open

or use open only for files with dots:

filetype /\\./ open

and a variant that takes hidden files into account:

filetype /[^.].*\\.|^\\..*\\./ open
commented Oct 6, 2015 by anonymous

But they are not always dot files.

commented Oct 6, 2015 by xaizek

Not sure I follow, extension is something that is separated from name part by a dot. So files with a dot are those that have extension (except if they just start with a dot), and files without extension don't have any dot (again, excluding possibly leading dot). Maybe just provide an example where you think above commands won't work as expected.

commented Oct 7, 2015 by anonymous

Oh! My bad. In my first message, by "exceptions" I meant "extensions". Some files have no extension (sometext, as opposed to sometext.txt).

I'd like to open these files with vi, but keep opening files with extensions that are undefined in vimrc with OS X's open.

The problem is that this Regex: filetype * open matches extension-less files too.

commented Oct 7, 2015 by xaizek

I didn't even notice the typo before. Everything is right then. filetype * open uses globs, which are not capable of specifying files without extensions.

filetype /\\./ open

uses open only for files that has dot, e.g. file.ext as well as for .file, while

filetype /[^.].*\\.|^\\..*\\./ open

will use open for .file.ext and file.ext, but not for .file.

The rest of files will be opened according to 'vicmd' option.

commented Oct 7, 2015 by anonymous

Much better ! Thanks.

If you would like to make a bug report or feature request consider using GitHub, SourceForge or e-mail. Posting such things here won't be considered as spam, but this is not a perfect place for it.
...