Emacs Dired - C-x C-f to create a new file gives me suggestions of existing files - emacs

I'm trying to create a file in dired mode in emacs. I am in the right directory and when I press C-x C-f as suggested elsewhere on SO and type 'img' (that's the name of the file I want to create), it tries to find existing files from other directories including the pattern 'img'. Then I'm stuck as if I press enter, it'll open the first suggested file containing the pattern 'img' from other directories, TAB will just go over the suggestions.
Please advise.

You are probably using ido-find-file with which you can interactively select a file by typing a substring of that file name.
If you want to temporarily disable this feature (i.e. for your current search only) just press C-f before typing the name of your new file (i.e. immediatly after C-x C-f).

Related

Emacs will not visit new file but insists on opening a similar one

The problem is quite simple but frustrating. When I try to visit a new file with C-x C-f which is named basis.m emacs keeps visiting the similar named file haarbasis.m which already exists in the same directory. It keeps prompting me for similar names and I am unable to visit a new empty file. I had recently installed elpy for a python IDE if it makes any difference.
How can I force emacs not to visit a file with C-x C-f unless I explicitly state which file to visit?
elpy loads idomenu which in turn loads ido. What you are describing sounds like ido-powered completion of file names. You can disable it after C-x C-f by pressing C-f.
As Alex mentions the string of packages that brought you to ido-mode, this answer depends on the answer to your statement below, which may be why something is happening to you when you do C-x C-f
When I try to visit a new file...
When your pointer/cursor is at the end of a word, idowill look for a file in the current directory with that name. It may even traverse down the relative path too if it's set up like a file directory structure e.g. show/basis.m
The commentor Jon O says, Even if this is happening C-j will create a new file for you.

Emacs Dired rename many files

How to rename from:
VAR1_1F_text.txt
VAR2_1F_text.txt
VAR3_2F_text.txt
to
1F_VAR1_text.txt
1F_VAR2_text.txt
2F_VAR3_text.txt
How to switch parts of filenames?
This can easily be done using dired:
Enter a dired view of your directory
Switch to writable dired mode (wdired-change-to-wdired-mode): C-xC-q
Edit the file names listing as if it were a normal buffer (for example using a keyboard macro or a rectangular selection or query-replace). Here is a regexp-based solution:
C-M-%\(VAR.\)_\(..\)RET\2_\1RET
Finish editing (wdired-finish-edit): C-xC-s or C-cC-c
You're done!
You could also use Magnar Sveen's multiple-cursors from here, github link.
Switch to writable dired, select the files you want to rename, M-x mc/edit-lines.
This should create multiple cursor each with its own kill history.

How to make a link to external file line in Emacs org-mode

I have 2 files:
php file with code
org file with docs
How to create a link to a line in php file from org file? So clicking it will move the cursor to the appropriate line in php file.
Use this notation in the org mode to create a link:
[[/path/to/file.php::line][string-to-display]]
If you want the file name to be displayed, use just
[[/path/to/file.php::line]]
See Hyperlinks in the Org mode Info page for details and other ways to specify links.
If I understand the question right you can do it automatically with two org-mode commands:
Move the point to a line in a php file and M-x org-store-link.
Go to an org file and C-c C-l or M-x org-insert-link and follow the instructions in the minibuffer.
You are done, click the link or C-c C-o when the point is on it to open the link.
I have org-store-link on C-c l and org-insert-link on the default C-c C-l. This makes the process very convenient and fast to execute.
Have fun with org-mode.

When I create one file in Emacs, I can not open the directory

I use C-x C-f and C-X C-s to save a file to directory "test", then I can not open the test directory with "tab", it says "Dired (directory): ~/test.....".
I want to know what is the wrong and the correct method to create a file in emacs, thanks!
Emacs distinguishes between files and buffers. You do all your editing in buffers, which do not necessarily have to be associated with a file (see, e.g., the *scratch* buffer). However, you often want to edit a buffer that is associated with a file. In that case you visit (Emacs lingo for "open") said file with C-x C-f.
Let's say you have a directory "test" in your home directory, and in that directory a single file "foo.txt". If you want to edit the contents of that file, visit it by typing:
C-x C-f ~/test/foo.txt RET
That's easy enough: now you get a new buffer in Emacs which is conveniently named after the file you're visiting ("foo.txt"). If you want to store changes you've made in the buffer back to the associated file, you type C-x C-s, and Emacs will write the contents of the buffer to the file "~/test/foo.txt".
This mechanism also works for files that do not exist when you start editing!
If you type, say,
C-x C-f ~/test/bar.txt RET
You get a buffer associated with a (yet non-existent) file "bar.txt" in the directory "~/test". Again, you can edit that buffer to your liking and then save the buffer with C-x C-s. The first time you do that, a new file is created.
If you want to create a buffer named "baz" that is not associated with any file, type
C-x b baz RET
Since it is not associated with a file yet, typing C-x C-s in that buffer will prompt you to specify a file-name. After saving, the buffer will be associated with the file you specified.
Finally, if you're in a buffer that is associated with a file, but you want to save it to a different file, you can do so with C-x C-w, which will give you the same prompt as in the previous case. Again, the buffer will be associated after saving with the file you provide.
Tab completion does work in all of the commands that ask you for a file name. If you think it doesn't then it might be because the file you think should be completed does not exist (also beware of upper-/lower-case distinctions in file names), or because another file with the same prefix forbids further disambiguation. Tapping TAB twice should list the available completions in a temporary buffer, letting you continue specifying the path name until it is complete.
Dired mode is pretty much orthogonal to all of the above. It is a mode for "editing" directories, i.e., doing file system operations. You invoke it by typing C-x d, which you may have typed accidentally?! It is quite powerful, but also quite complex. See here for its documentation.

Opening multiple files at once in Emacs

In Emacs using ido-mode allows me to open a file from the minibuffer with C-xC-f. This method opens only one file at a time.
How do I open all the files in a directory or specify more than one file to open?
You can just provide * as the file name and press Enter; you'll be asked for a confirmation and if you press Enter a second time, all files in the directory will be opened.
Note that "opening all files in a directory" involves opening dired buffers for all of its subdirectories.
When not using ido-mode -- at the basic Emacs find-file prompt -- you can use the same * to open all files in a directory. When you do use ido-mode to find files, you can always press C-f to drop back to the usual Emacs find-file prompt. (You can use ido to speed up getting to some directory you're interested in first and drop to the basic find-file in there.) That's one way of creating a new file with ido (the other being the C-j binding); also, it gives you another way of using the above mentioned * trick.
File-name groking is nowhere near as useful as more general pattern-matching.
In Icicles file-name completion, you can open any number of files matching any number of patterns, from the same minibuffer. Pattern-matching can be substring, regexp, fuzzy, or prefix, and you can combine patterns using intersection and complementing.
Just as in Ido, in Icicles your minibuffer input dynamically filters the file-name candidates. You can choose individual candidates or choose all that currently match (using C-!).
(You can of course use file-name groking also. As with Emacs file-name input generally, hitting RET on a wildcard (grok) pattern sends it to find-file, which opens all matching files.)