eshell search history - search

I'm using emacs eshell and would like to search back through my command history. In bash you would do C-r then type something and then press C-r repeatedly until you find the command you want. On eshell it seems I have to type M-r and then type part of the command and press enter then type M-r and enter again to get the next match and so on. This means I have to keep doing M-r {enter} M-r {enter} M-r {enter} again and again rather than just pressing C-r again and again without moving my hands, is there a better way? There's not much info out there on eshell.

If the string that you are searching for is in the beginning of the command, then eshell-previous-matching-input-from-input UP, M-p or C-c M-r is much friendlier than eshell-previous-matching-input M-r.
You can type the first few characters of the command and press UP or M-p key and it will cycle only through the matching commands in the history.

Related

When I search in vim and then press “esc” cursor returns to previous position

Something has seemingly happened to my vim install, and I'm not exactly sure what. I'm a long time vim user (although I don't use it as a main editor).
When I search:
/foo
I want to edit the location that it found, so I press ESC (in preparation for getting into insert mode). vim now jumps BACK to where I started from in the file. E.g. if I was on line 0 of a 3000 line file, I search for a particular string, find it at line 1700, and want to edit it - ESC takes me back to line 0.
What's going on? Did I accidentally set some strange mode? Or did I forget a hotkey combination that I should know?
This is the expected behaviour with the incsearch option on:
Note that the match will be shown, but the cursor will return to its
original position when no match is found and when pressing <Esc>. You
still need to finish the search command with <Enter> to move the
cursor to the match.
If incsearch is not on then the cursor doesn't jump to the first match at all, it doesn't move until you press <Enter>.
you said
so I press ESC (in preparation for getting into insert mode).
you don't need to press ESC before you can get to insert mode, you need to press enter (known in vim as <CR> for carriage return).
so if you wanted to find foo and start inserting text, type
/foo<CR>i
remember that <CR> is a single pressing of the enter button.

Linux: VI - When someone say "Command mode key sequence", what are they talking about?

On one of my Linux VI assignment, I'm asked
Delete the first 2 lines in this file using one dd command. What
command mode key sequence did you enter?
I'm having a hard time trying to figure out what it's asking me.
What does it mean when it says "Command mode key sequence" ?
Is it asking me to use dd in the command mode (that's my answer), or is it asking me to do something else?
Yes its asking you to use a dd in command mode.
In Vi editor, when you press [Esc] and type : you are in the command mode, now if you type dd [Enter] whichever line your cursor is on gets deleted.
vi has two basic modes: command-mode and insert-mode. You start in command-mode, and may temporarily be in insert-mode for i (insert), o (open) and similar commands. Type escape to return to command-mode.
There is another way to enter commands, referred to as ex (originally a different program from vi, but integrated for a long time). For that, you temporarily exit visual mode by typing : (colon).
Some command-mode commands are "stuttered" (repeated characters), such as dd. That happens to correspond to the ex-command d (delete line).
Further reading:
Basic vi Commands
Vi Cheat Sheet

Vim :'<,'> When entering command mode

Sometimes in vim I appear to be entering a keymap unintentionally when attempting to enter command mode. For instance, when attempting to write :w I, sometimes, end up with this:
:'<,'>w
Which throws the error E481: No Range Allowed
It's mostly just a minor annoyance, and I'm more wanting to know what am I doing to initiate the command line in this way with the brackets.
:'<,'>w appears when you start a command line while being in visual mode. It allows to apply this command on a portion of your document, e.g. to sort some lines. In your case, you have accidentally hit v before entering your command.
Adding to Vincent's correct answer, if you happen to come upon a command that doesn't support a range and gives you the E481 error (though the given :write does support ranges), you can just remove the '<,'> prefilled content by pressing Ctrl + U, and then start typing the command. This is quicker than Esc and re-triggering command-line mode via :.

How does :normal! /something<cr> relate to incsearch and the / operator?

A few micro-questions regarding normal!, incsearch and the / operator (search). I'm not solving any particular problem here, just trying to understand the relations between the mentioned, so I can put up some sort of analogy in my head.
If I have, set incsearch on, while in normal mode upon pressing /something Vim will jump to the first instance of something even before/without me pressing enter.
Okey, so normal! /something should do the same thing. Why doesn't it?
Similarly, normal! doesn't recognize special characters. So if I have a text file with this text in it,
something<cr>
(that's not a special character in there, but literally typed in text)
`normal! /something<cr>`
should put me up to that text. Why doesn't it?
I like it, but sometimes Vim's inconsistencies are, to put it mildly, most interesting :)
In :help :normal the relevant text is:
{commands} should be a complete command. If
{commands} does not finish a command, the last one
will be aborted as if <Esc> or <C-C> was typed.
The command string you give to normal has to be a complete command, or it aborts. However, normal! /something isn't complete; if you were typing it, Vim would be waiting for you to finish. You could press Esc or Ctrl-C to abort. Or you could complete it by pressing Enter. So the command isn't complete and it aborts, instead of jumping. To get it to complete, give it the Enter it wants (at the command line):
:normal! /something^M
You can get the ^M by typing Ctrl-V and then Enter. (If on Windows and Ctrl-V pastes, use Ctrl-Q.) Then you'll need to press Enter again to finish the whole command. If you were using execute you could do it with:
:execute "normal! /something\<cr>"
Be sure to use double-quotes so the \<cr> will be interpreted correctly.
I believe your second question is the same thing. The literally typed <cr> doesn't affect this situation, you just need to provide the carriage return that will complete the search command, or normal aborts it.
Since you've tagged this question with vimscript, I'm guessing that at least part of your interest is in using this in a script. Getting the literal carriage return into a script and having it work right is kind of a pain. In those cases, I would use execute as shown above, so you can use the double-quote interpretted string method of getting the carriage return.
As for incsearch, it won't have an effect because you can't be partially searching with normal, as we've seen. You can only submit the entire search. It will, however, update the most-recent-search register "/, so highlighting will still update correctly.

mapping shortcut in vim without hanging the cursor

I would like to have vim fill a short sequence of characters into a longer string in insert mode. Example, say I write the word "sub" and it writes "subroutine" as soon as I press space. The problem I find is that when I use :imap sub subroutine, every time I start typing sub, the cursor does not continue moving, but hangs in the same position waiting for more keystrokes in order to decide what to do. I find this behavior annoying, although not wrong (it does what I need).
Is there a way to have vim continue typing single characters, and eventually replace ?
Just try to use abbreviate :ab sub subroutine
Search the web for "vim completion" (or the help for "completion"). The feature is in v7.x, but you may want to change the keystrokes with ìmap.

Resources