Spacemacs cannot create a new file when a file with a similar name exists in the same directory - emacs

In spacemacs, a user can normally create a file using 'Ctrl-x Ctrl-f', and then entering a filename in the minibuffer.
However, if a file with a similar name exists, then spacemacs does not create a new file. It opens the existing file instead.
One workaround is to jump to a terminal and create the new file, then return to spacemacs and open that file.
But this interferes with the workflow.
This isn't how an editor should work, and I can't see how it isn't a bug.
This behaviour does not exist in normal emacs.
Is there a way to disable this behaviour?

It's not a bug... it's a feature of ivy completion. It happens when the file name is a prefix of an existing name, for example if you try to open a new file foo in a directory containing an existing file foobar. You can choose the current input (foo) instead of the current candidate (foobar) with C-M-j, see: https://elpa.gnu.org/devel/doc/ivy.html#Key-bindings-for-single-selection-action-then-exit-minibuffer

Related

How to create a file in VS Code with Vim extension?

Using the VIM extension for VSCode, is there a way to create a file inside the folder you are currently selecting on the explorer tab?
Similar to how it works with NERDTree on NVIM itself where you can press "a" and it lets you write a filename.
Brief example where the cursor would be placed on the "pages" folder.
You can use :e <filename> to create a file and simply use :w to save it.
It creates a file in the directory in which your current file is open. So in the screenshot you provided, if you would be editing _app.tsx, the new file will be created in this directory unless differently stated in your filename.

Visual studio code, how to copy the file name

In the visual studio code, it has commands to Copy Path and Copy Relative Path (Ctrl+Shift+p->File: Copy Path of Active File). Is there a way I could copy the active file name instead of the whole path?
If there is no way copy the active file name. Is there a way I could write a script or something which creating a new command based on existing Copy Path and showing the new command in the Command Palette?
The extension Copy file name works like a charm!
CTRL+ALT+F gives you filename and CTRL+ALT+E gives the filename.extension.
open your file on vscode> select file as active file> Ctrl+Shift+P > Alt+Shift+C
now you can use Ctrl+V to paste this path any where you want.
step1. first install "copy file name" extension from extensions(ctrl+shift+X) in your vscode.
step2. then use ctrl+alt+e for copying the full file_name with file_extension(like .cpp or .py or .java etc..).
or ctrl+alt+f for for copying the file_name
without file_extension.
It is been a while but I found if you want to write a script using the currently opened file, create a new task in task.json and calling some scripts in the task might be a good option.
Basically, ${file}, ${fileBasename} and ${fileDirname} are the variables that can be used in your script file.
Useful reference:
https://code.visualstudio.com/docs/editor/variables-reference
As an alternative, if you see the active file in the "Explorer" view, you can type F2 once you select it.
With VSCode 1.71 (Aug. 2022), you can type F2 and:
1st press => prefix
2nd press => all
3rd press => suffix
4th press => cycles back around to prefix
This has been release to VSCode insider today, for you to test/play with it.
Without using any extensions, here's a combination of key shortcuts you can use to copy the path of the current file. It's a bit cumbersome but with some practice can be faster than doing the same using the mouse.
Ctrl+Shift+E to open and focus the Explorer pane.
The current file will be selected automatically by default.
F2 to start renaming the file.
This will select the file name without file extension.
(optional) Ctrl+A to include the file extension in the selection.
Ctrl+C to copy.
Escape to abort renaming (or just click anywhere).
no need any extensions, Ctrl+K --> Ctrl+Shift+C, then you will get relative path

emacs not picking up my init.el file on windows

I have my emacs.d folder located at:
C:\Users\<loggedin_user>\AppData\Roaming\.emacs.d
In this folder, I have my init.el file but it is not being picked up by emacs.
Is there another step I am missing, do I need to set an environment variable or something?
When I enter C-x d ~/ RET I end up at
C:\Users\<loggedin_user>\AppData\Roaming\
If I move the init.el file there, it is still not picked up. I have a deliberate error in the file that is not causing emacs to crash when it is opened.
Most likely you have an old ~/.emacs file somewhere else which Emacs ends up using in preference to the other one.
You probably want to check the value of user-init-file which will tell you which file Emacs ended up using as "the ~/.emacs file".
I suggest you report this as a bug, requesting that when several files are found as possible init file, Emacs should not just pick the first and ignore the others but should at least emit a warning about the fact that it ignored the others.
This is tricky on Windows 10 but I solved since I was suffering from same issue.
I created an Environment Variable called HOME with the path C:/user/<username> in the box "User variables for " create a new one
Just open with double click any file that is by default opened with Emacs and it will take few seconds to load then take changed on the init.el
create an init.el with just one line of code like:set-background-color "honeydew"
to test this, first before doing something more complex.
Hope That It Helps!
On Windows, Emacs is started with some Properties defined, found when you right-click the executable on your windows system. There you can define the
execution-directory, e.g. "C:\Users\loggedin_user\" (in parantheses)
where emacs executes
and looks for the .xemacs (.emacs) directory, where it find its init.el. (I had to create an .emacs File in my Windows Home Directory, which is defined in the Windows HOME Environment)
And where you can define the startup instructions (like (setenv "HOME" "c:/Users/Username/") ) etc.
If you configure that, the next time, emacs starts from the directory, you defined, with the initialisation-file
Windows 10 and Emacs 27.1 could not find .emacs.d: one more possibility, in my case %HOME% was set like HOME=%HOMEDRIVE%%HOMEPATH%. This redirection seems not to work and emacs was using literally C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH% for searching .emacs.d. I did not dare to edit %HOME% but created link:
C:\Users\username> cd %HOME%
You perhaps need to remove some files in C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH% which emacs already created.
Create link:
C:\Users\<loggedin_user>\%HOMEDRIVE%%HOMEPATH%> mklink /d .emacs.d ..\.emacs.d

Emacs Helm (anything): Desired candidates are excluded for autocompletion. Why?

I have a file in my home directory called .gitconfig. When I try to open this file with Emacs with helm-mode activated, this file is eventually unmatched, as I type it.
In the minibuffer I start typing the path (C-x C-f)
Find file: /home/.g
and it shows me:
.gconf
.gitconfig
.gnome2-private
etc.
However, as soon I type i (i.e. typing /home/.gi to eventually type .gitconfig), Helm removes .gitconfig from the autocompletion list and leaves me with .gnome2-private.
Why does this happen? How can I have Helm never exclude a file from the current directory where I am hoping to open a file?
I cannot reproduce this after recreating the directory structure you specified.
If you clone the helm github repo found here, then execute
./emacs-helm.sh, does it still repro? If not, can you add back your
config until it does? This would be a bug.
Also, it would be best to file a helm issue and discuss it there.

emacs on Windows: .emacs is no valid file name

I've found out where to put my .emacs file, but it seems it can't begin with a ".".
I tried naming it "emacs" or "_emacs", but how can I find out if it is used?
You can always create the file using Emacs itself: C-x C-f ~/.emacs. The ~ represents your home directory, which you can set as environment variable HOME.
Have a look at this page and this one for start up instructions.
If you are creating a file in Explorer, it won't allow you to use a .name (gives this error).
A simple work-around, if you have bash (cygwin, git-bash, or any other variant) installed is to use that to rename the file. It may also work in powershell or command prompt, I've not tested those.
Files can start with '.', this doesn't cause any trouble alone, but explorer won't let you name them with it.
Windows Explorer disallows the creation of filenames starting with a dot. A simple workaround with builtin Windows tools is to create the file with a dummy name (eg. _emacs), then use cmd.exe to rename it:
cd path/to/file
ren _emacs .emacs
Recent versions of windows (e.g. Windows 7) seem to allow creation of a .emacs file using windows explorer. When creating/renaming the file simply enter .emacs. instead of .emacs.
To test if the .emacs that you are editing is the .emacs that is being loaded, you could put the following elisp command in it:
(minibuffer-message "it worked")
Now exit and restart emacs, while watching the minibuffer at the bottom of the screen to see if it appears (it will only appear for 2 seconds).
Windows allows the creation and use of that type of file, but Windows Explorer does not allow a file to be named to that using Windows Explorer. Use another tool (like the command line, or emacs) to create the file with that name.