如果一个目录包含许多文件,我想要进入以某个字母(或字符串)开头的文件(或子目录),有没有好的方法可以做到这一点?我知道在Far文件管理器中,人们可以按下Alt键并开始输入名称,光标会随着您的输入而移动,我想知道Emacs是否有类似的功能。
如果一个目录包含许多文件,我想要进入以某个字母(或字符串)开头的文件(或子目录),有没有好的方法可以做到这一点?我知道在Far文件管理器中,人们可以按下Alt键并开始输入名称,光标会随着您的输入而移动,我想知道Emacs是否有类似的功能。
emacs
ret,然后使用isearch
查找适当的子字符串(忽略第一个Failing I-search
),或者直接用C-h i进入info,然后用g导航到下面提到的info节点并输入节点名称,最后按ret即可。(emacs) Dired and Find
开始的方法无论是否在dired缓冲区中都可以使用: To search for files with names matching a wildcard pattern use `M-x
find-name-dired'. It reads arguments DIRECTORY and PATTERN, and
chooses all the files in DIRECTORY or its subdirectories whose
individual names match PATTERN.
来自信息节点 (emacs) Dired Navigation
的第二个方法适用于dired缓冲区,但仅适用于当前列出的文件。但请注意,在使用 i 命令之前,您可以列出子目录。
`M-s f C-s' (`dired-isearch-filenames') performs a forward
incremental search in the Dired buffer, looking for matches only
amongst the file names and ignoring the rest of the text in the buffer.
`M-s f M-C-s' (`dired-isearch-filenames-regexp') does the same, using a
regular expression search. If you change the variable
`dired-isearch-filenames' to `t', then the usual search commands also
limit themselves to the file names; for instance, `C-s' behaves like
`M-s f C-s'. If the value is `dwim', then search commands match the
file names only when point was on a file name initially. *Note
Search::, for information about incremental search.
编辑: 要递归地搜索目录,您可以先递归列出它。
您可以通过使用前缀参数调用dired
并将R
添加到开关列表中来递归地列出子目录。
以下用于Emacs初始化文件的代码片段甚至可以简化此任务:
(defun dired-noselect-maybe-recursive (dir-or-list &optional switches)
"Like `dired-noselect' but lists sub-directories when last character is ?/."
(if (and (null switches)
(= (aref dir-or-list (1- (length dir-or-list))) ?/))
(dired-noselect dir-or-list "-alR")
(dired-noselect dir-or-list switches)
))
(setq find-directory-functions (subst 'dired-noselect-maybe-recursive 'dired-noselect find-directory-functions))
如果您在调用没有斜杠结尾的目录时使用find-file(C-x C-f),则可以获得普通的目录列表,如果在结尾处使用斜杠,则可以获得递归列表。
但是要小心。递归目录列表可能需要一些时间。如果感到紧张,您可以随时使用C-g退出。
isearch可以实现这一点。按Control-S,然后开始输入。
由于它是Emacs的通用搜索功能,因此在输入名称的足够信息之前,它可能会匹配缓冲区中的其他内容。
(add-hook
'dired-mode-hook
(lambda()
(define-key dired-mode-map "j" 'ido-find-file)))
显然,这只适用于一个文件,并且它会打开该文件,而不是提供dired可以对文件执行的多种操作,但至少它很快。
C-s
(增量搜索)。没有其他需要补充的。%m
标记与正则表达式匹配的所有文件。一旦标记,您可以对标记的文件集合(或未标记的文件集合)执行各种操作。
projectile
及其find-file-in-project
和find-file-in-directory
函数:https://github.com/bbatsov/projectile - Ehvince