How to use wildcards to auto-complete on remote server in zsh? - command-line

One of my favorite features of zsh is auto-complete, especially when I'm completing a filename on a networked machine. But how do you include wildcards (like *) and have it auto-complete on the remote machine?
For instance, say I have file1, file2, and file3 residing on a server; I want to copy all those files to my local machine, so I enter
scp server:~/fi<tab>
zsh then correctly auto-completes to
scp server:~/file
but then when I try to wildcard
scp server:~/file*<tab>
all it does it beep at me (it works correctly if the file paths are local). Is there a set of zsh options that makes this work? I found GLOB_COMPLETE and EXTENDED_GLOB, but the best I could do with any combination of those was to auto-complete a single match, or cycle through all matches, but not expand the auto-complete to all matches (as it does on the local command line). Is that actually possible?
Thanks!
randy

As I've mentioned at superuser: Think setting GLOB_COMPLETE should change this.
setopt GLOB_COMPLETE
From man zshoptions:
GLOB_COMPLETE
When the current word has a glob pattern, do not insert all the words resulting from the expansion but generate matches as for completion and cycle through them like MENU_COMPLETE. The matches are generated as if a ‘*’ was added to the end of the word, or inserted at the cursor when COMPLETE_IN_WORD is set. This actually uses pattern matching, not globbing, so it works not only for files but for any completion, such as options, user names, etc.
Note that when the pattern matcher is used, matching control (for example, case-insensitive or anchored matching) cannot be used. This limitation only applies when the current word contains a pattern; simply turning on the GLOB_COMPLETE option does not have this effect.

Your example works perfectly fine for me. I don't know what makes it work on my system, but here's what I have set:(
alwaystoend
cbases
extendedglob
interactive
interactivecomments
monitor
shinstdin). And my .zshrc has:
zstyle ':completion:*' completer _expand _complete _ignored _correct _approximate
zstyle ':completion:*' max-errors 1 numeric
zstyle ':completion:*' menu select=2
autoload -Uz compinit zsh-mime-setup
compinit

I've the same problem !
I suceed with the follwing command:
scp "user#server:/dir/*" localdir
double quote escapes the completion.

Related

How to skip forward/backward a word at a time when editing postgres command in psql?

In most command line interface "cli" programs the Option-arrow key combinations allows one to move forwards/backwards a word at a time. But in psql both Option-arrow and Control-Arrow actually insert non printable control characters that corrupt the command. In addition in most CLI programs hitting CTL-A goes to the beginning of the command and CTL-E goes to the end of the command. But in psql those combinations do not have any effect.
Navigating a single character at a time is simply too slow: I can not imagine this were an unsolved problem. What is the configuration needed to get one of those key combinations to skip forward/backward by words not characters?
This is an answer containing the response in the comment by by #Marth. The ~/.inputrc does cause the issue.
# want vi to be the default editor for readline
set editing-mode vi
$if mode=vi
# normal mode
set keymap vi-command
set keymap vi-insert
"\C-n": backward-kill-word
"\C-p": history-search-backward
$endif
I have completely removed the ~/.inputrc now.

Add trailing slash in tcsh completion of directory symbolic links

Assume I have a folder ~/Documents
Now when I type /Doc and press tab key, my tcsh would complete the line to /Documents
What I would like to achieve, is to get /Documents/
I found most of the discussions on the Internet is about bash. But here I'm using tcsh. I know this is doable as my previous setup works like this in tcsh.
This is how tcsh should behave by default; but it's controlled with the addsuffix setting; from tcsh(1):
addsuffix (+)
If set, filename completion adds `/' to the end of directories
and a space to the end of normal files when they are matched
exactly. Set by default.

How to use vimgrep to grep work that's high-lighted by vim?

I've installed vimgrep plugin, inside vim, under normal mode I can type:
:vimgrep mywords %
to search "mywords" for the documents under current directory.
But I wish that in normal mode, when I highlight a word using gd, or in visual mode use 'viw' to select a word, I use a hot key to vimgrep. So I add in my .vimrc and restart vim:
vnoremap <F8> :vimgrep expand('<cword>') %<CR>
Well it didn't work for me, when I put focus on one word and select it, I press F8, no response in vim. How to achieve it?
Thanks!
Vimscript is evaluated exactly like the Ex commands typed in the : command-line. There were no variables in ex, so there's no way to specify them. When typing a command interactively, you'd probably use <C-R>= to insert variable contents:
:vimgrep <C-R>=expand('<cword>')<CR> '%'<CR>
... but in a script, :execute must be used. All the literal parts of the Ex command must be quoted (single or double quotes), and then concatenated with the variables:
execute 'vimgrep' expand('<cword>') '%'
Actually, there's a built-in command for inserting the current word into the command-line: :help c_CTRL-R_CTRL-W:
:vimgrep <C-R><C-W>
Your mapping
You could use all three approaches; let's use the last:
vnoremap <F8> :<C-u>vimgrep <C-r><C-w> %<CR>
The <C-u> clears the '<,'> range that is automatically inserted.
What you probably wanted
Using the current word from visual mode is strange. You probably wanted to search for the current selection. There's no expand() for that. Easiest is to yank, as outlined by #ryuichiro's answer:
vnoremap <F8> y:vimgrep /<C-r>"/ %<CR>
Still missing is escaping of the literal text (:vimgrep searches for a regular expression pattern), and of the / delimiter:
vnoremap <F8> y:execute 'vimgrep /\V' . escape(##, '/\') . '/ %'<CR>
Robust plugin solution
Now, if you also want to avoid the clobbering of the default register, it gets really complicated. Have a look at my GrepHere plugin; it provides a {Visual}<A-M> mapping for exactly that.
Try
vnoremap <F8> y:vimgrep "<c-r>"" %<CR>
:h y
:h <C-r>
Recommended reading: Mapping keys in Vim - Tutorial (Part 1)

Emacs filesets: how to run other (elisp, not shell) commands?

There are 5 Elisp commands that can be run on an Emacs fileset, plus the ability to run any shell command. What about all the other Emacs commands? Just to give one example, it would be nice to be able to run M-x occur on a fileset.
I know its possible to mark several files in dired and then run any Emacs command on them (is that true, or am I confused with shell commands?), but it would be very convenient to define a fileset once and then be able to use it like one single file for all kinds of text editing.
Thanks for any advice
The commands that can operate on file sets are specified in the global custom variable "filesets-commands". You can add your own commands to that list. The default value for this variable is:
("Isearch" multi-isearch-files
(filesets-cmd-isearch-getargs))
("Isearch (regexp)" multi-isearch-files-regexp
(filesets-cmd-isearch-getargs))
("Query Replace" perform-replace
(filesets-cmd-query-replace-getargs))
("Query Replace (regexp)" perform-replace
(filesets-cmd-query-replace-regexp-getargs))
("Grep <<selection>>" "grep"
("-n " filesets-get-quoted-selection " " "<<file-name>>"))
("Run Shell Command" filesets-cmd-shell-command
(filesets-cmd-shell-command-getargs)))
The values consist of an association list of names, functions, and an argument list (or a function that returns one) to be run on a filesets' files. So, if you wanted to add a command that does an "occur" command on the file set, you could use the "Isearch" entry as an example to create your own new entry (that you would add to the "filesets-commands" global variable) that would look something like:
("Occur (regexp)" multi-occur-files-regexp
(filesets-cmd-occur-getargs))
You would need to write the "multi-occur-files-regexp" and "filesets-cmd-occur-getargs" functions (you could use the existing "multi-isearch-files-regexp" and "filesets-cmd-isearch-getargs" functions as a basis since they would be similar). The same would apply for any additional Emacs command that you wanted to add to work on file sets.
Dired has several operations on filesets. An example is dired-do-search (bound to A), where you can navigate through search results on several files with M-, just like with tags-search. Similarly, you can query-replace in tagged files (with Q).
The recent posts on irreal.org describe some nice dired features.
With Icicles you can use filesets for anything you might want to do with a set of files and directories. And you can create a fileset from any set of file and directory names in buffer Completions during completion. And you can use substring and regexp matching during completion to get such a set of file names in Completions.
These links might help:
http://www.emacswiki.org/emacs/Icicles_-_Persistent_Completions#Filesets
http://www.emacswiki.org/emacs/Icicles_-_Dired_Enhancements#OpenDiredOnSavedFiles
http://www.emacswiki.org/emacs/Icicles_-_Dired_Enhancements#MarkedFilesAsProject
http://www.emacswiki.org/emacs/Icicles_-_Customization_and_General_Tips#icicle-filesets-as-saved-completion-sets-flag
Dired+ has command diredp-fileset, which opens Dired on an Emacs fileset. You are prompted for the fileset to use.

Emacs command for searching in files

I want to search in all files from the current folder for macro CODE_INIT_PARAMETERS.
I can do Alt + X occur, Return CODE_INIT_PARAMETERS Return, but this shows only entries from open buffers.
Is there a way to search all files from current folder, from Emacs, without switching to M-x shell and then grep? I want to avoid grep, because for some commands (M-x occur) Emacs do jumps to offending code, and I want that too.
You can try M-x rgrep.
It will ask for:
the directory where you want to search recursively
a file pattern for the files you want to include in the search
the pattern you want to search
As an extra, it will exclude source control private directories from your search (like CVS, .svn or .git).
Emacs provides a built-in command:
M-x grep RET CODE_INIT_PARAMETERS *.c
(and 'grep-find to search sub directories)
Though I prefer the interface provided by an external package igrep (which provides the commands igrep and igrep-find).
If you open a folder in dired, and mark all of the files (with 'm') you can run 'dired-do-search ('A' in my bindings). This will search all marked files. To get to the next one, run tags-loop-continue (M-,)
I have set up several ELisp functions to mark various subsets of the files (.h files, .cpp files, etc.) and to create a recursive dired to search a whole tree...
This is an improvement on Trey Jackson's suggestion.
M-x grep
You will see the grep command, e.g. grep -nH -e
Add R to the first set of flags (for recursive), and put your search term after -e
grep -nHR -e CODE_INIT_PARAMETERS
Hit RET. The results will be understandable by Emacs -- you will be able to click or otherwise navigate to them, like M-x occur. You may need to put the search directory at the end of the command:
grep -nHR -e CODE_INIT_PARAMETERS /path/to/root/of/search
M-x find-grep-dired also works similarly as rgrep
In cases where
you may be searching repeatedly; and
etags will work
you might consider using etags and invoking either find-tag (bound to M-. by default) or tags-search (no default binding but can be continued with M-,).
There is as well ack-grep mode for Emacs which uses the ack-grep tool which is specifically designed for ''grepping'' programming languages and IMHO looks nicer than the output of M-x grep.
But as mentioned earlier etags should be the proper way!