-   Linux - Newbie (
-   -   How to edit history substitution in [t]csh (

ihowarth 04-26-2017 10:15 AM

How to edit history substitution in [t]csh
I want to recall an old command line (from within the [t]csh), and then edit it before executing.

What i don't want to do: recall, edit, and execute in one go ('cos i can't remember my complicated command line in sufficient detail to trust a 'blind' edit)

Sure, i could just use the up-arrow key and trawl through a million old lines looking for the right one -- but oops, my attention wandered and i missed the line i wanted.

So what i really want is something *like*:
!man : p
(sorry, had to put in some spacing to stop getting an unwanted emoji!), but with the recalled line actually as the command line, waiting for my edit (and not just printed out and returned to the prompt, which is what the above invocation does). I can't see how to do this from the man page, or the threads...but i think i'm probably just missing something obvious....?


norobro 04-26-2017 02:09 PM

I don't use tcsh but it looks like "i-search-back" will do what you want.

From the tcsh man page:

i-search-back (not bound)
Searches backward like history-search-backward, copies the first match into the input buffer with the cursor positioned at the end of the pattern, and prompts with `bck: ' and the first match. Additional characters may be typed to extend the search, i-search-back may be typed to continue searching with the same pattern, wrapping around the history list if necessary, ( i-search-back must be bound to a single character for this to work) or one of the following special characters may be typed:

Appends the rest of the word under the cursor to the search pattern.
delete (or any character bound to backward-delete-char)
Undoes the effect of the last character typed and deletes a character from the search pattern if appropriate.

If the previous search was successful, aborts the entire search. If not, goes back to the last successful search.

Ends the search, leaving the current line in the input buffer.
Note that it is not bound to a key. You could bind it to ctrl+R which is backward search in bash.

bindkey '^R' i-search-back

ihowarth 04-26-2017 04:13 PM

Ah, very helpful pointer....actually, "history-search-backwards" is pretty much what i wanted, i was just looking in the wrong place in the man pages. Thanks!

All times are GMT -5. The time now is 04:52 AM.