Using spacemacs I usually open new files for editing with C-s C-f (for find-file), since that is recommended by this answer.

However I have an issue when the file I wish to open is both new (doesn't yet exist), and is a substring of an existing file. For example: I want to open project/src/Types/List.hs for editing, but there already exists project/src/Types/InfiniteList.hs. So when I type the name of the file I wish to edit it selects the existing file from the list.

I tried also using neo-tree to create the file but it seems like it uses find-file to implement its file creation so the problem continues.

My current solution is to go to my terminal and touch the desired file before opening, but this is pretty annoying to do. Is there some way to do this from within spacemacs? Is there some alternative to find-file that I should be using here?

  • That isn’t the default Emacs behavior, so either you or Spacemacs have enabled something like ido-mode or similar.
    – db48x
    Jun 6 '21 at 11:41
  • @db48x It's definitely not ido-mode. Turning ido mode on switches to ido-find-file which works quite differently (but still does the annoying behavior). I'm working with a fresh spacemacs installation out of the box, so it is possible it is cause by something else but I don't know what. It certainly is default spacemacs behavior. Jun 6 '21 at 12:05
  • ido-mode is just one that I could remember off the top of my head; there are a number of other popular packages that improve Emacs along these lines. You’ll have to dive into the Spacemacs documentation and find out what it is doing.
    – db48x
    Jun 6 '21 at 12:28
  • I believe this is ivy, also called swiper behavior. If so, you might try the keys C-M-j (ivy-immediate-done) Jun 6 '21 at 12:38
  • 1
    @LynHeadley I had this annoyance too and never bothered to look into it until now. I'm using normal Emacs though with counsel-find-file to find files. The C-M-j works for me on your exact example. I have a directory with InfiniteList.hs I launch counsel-find-file (with SPC f f for me), type List.hs. It autocomplete to InfiniteList.hs, but pressing C-M-j ignores the completion and creates List.hs. You should check what function your key binding is bound to. It might not be an ivy function, but a helm one instead (or something else).
    – willbush
    Jun 9 '21 at 6:16

Your Answer

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

Browse other questions tagged or ask your own question.