I cannot use C-M-j
because that will immediately save the file at ~/scripts
(with no filename), instead of allowing me to continue to type the path I want.
Both vanilla Emacs and Ivy let you save to non-existing files within non-existing directories by specifying literal /-delimited file names without completion.
The problem in this case is that Ivy interprets / specially by default. Namely, typing / during Ivy file name completion will descend into the currently selected directory candidate, if one exists.
Thankfully, Ivy provides a user option to control this behaviour:
ivy-magic-slash-non-match-action is a variable defined in ‘ivy.el’.
Its value is ‘ivy-magic-slash-non-match-cd-selected’
Documentation:
Action to take when a slash is added to the end of a non existing directory.
Possible choices are ’ivy-magic-slash-non-match-cd-selected,
’ivy-magic-slash-non-match-create, or nil
You can customize this variable.
The default, ivy-magic-slash-non-match-cd-selected
, will descend into the currently selected directory candidate, as mentioned above. ivy-magic-slash-non-match-create
will, upon typing /, create a directory with a name corresponding to the current minibuffer input. nil
is like vanilla Emacs in that it does not handle / specially.
So, for example, you can:
(setq ivy-magic-slash-non-match-action nil)
followed by C-xC-s~/scripts/script.py
RETy.
I'm not sure if this problem is Ivy-related or not
It is, as you can confirm by disabling ivy-mode
.
See also https://github.com/abo-abo/swiper/issues/1532.
C-M-j
(ivy-immediate-done
)? See github.com/abo-abo/swiper/wiki/… and(ivy) Key bindings for single selection action then exit minibuffer
. – Basil Aug 31 '18 at 23:43