Search current line in ZSH (vi mode)

How do I search / navigate the current line in zsh? For example, if the cursor is at the end of a line.

// [] indicates cursor position user@hostname : vim /etx/apache2/sites-enabled/defaul[t] 

In normal vi mode, I would like to use reverse lookup ( ? ), Type etx and move the cursor like this:

 // [] indicates cursor position user@hostname : vim /[e]tx/apache2/sites-enabled/default 

However / and ? match a story search, not a regular search. I know that I can just dial 9b and get there, but finding a search and moving to a match is easier than counting the number of words for a jump.

Not sure if this was clear, let me know if I need to clarify things.

+4
source share
5 answers

I hope I understood you correctly. You want the zsh command line, move your cursor faster when entering commands.

eg.

 user@hostname : vim /etx/apache2/sites-enabled/defaul[t] 

Do you want to go to the first e

I do not use vi-binding, but f and f are your friends.

In this example, you can 5Fe go back to 5th e . If you do not want to count, you can Fe , then click ; until it moves to the desired position.

check vim help for details:

 :hf :h F 

Also a faster way would be 0fe , for this example. Move the cursor to the beginning, then to e

If I misunderstood your question, please leave a comment, I would delete the answer.

+2
source

Enter v, when you are in the command mode of your shell, you will be taken to the real ViM editor. After saving and exiting, it will be automatically executed.

0
source

This script adds this function to zsh: https://github.com/soheilpro/zsh-vi-search

0
source

Perhaps the ~ / .inputrc file matched these keys with something strange? Or you don’t quite understand how search history works.

Let it start fresh: Remove these keys with bindkey:

 bindkey -M vicmd "?" history-incremental-search-backward bindkey -M vicmd "/" history-incremental-search-forward 

Now when you press 'esc' (for normal vi mode) and '?' you will get bck-i-search command:

 % user@hostname : vim /etx/apache2/sites-enabled/defaul[t] bck-i-search: 

At this point, enter a search type, for example. 'Ext. And the cursor moves to this position on this line. Note: if he does not find this template in this current line, he continues to search for your story. This behavior is considered a feature!

You may notice that you cannot search multiple times (for example, press "N" in vim). In this case, add some search bindings:

 bindkey -M isearch '^N' history-incremental-search-backward bindkey -M isearch '^R' history-incremental-search-forward 

Now pressing the -N button repeats your search, and pressing the control-S button changes the direction of the repeated search (note: the default order for this binding is canceled from the beginning to the opposite, since most often it looks back from the end of the story).

In short: treat the current line as the β€œtop” of your story. Using vicmd '/' or '?' looking for the whole story. "?" searches from top to bottom, while '/' searches where the cursor is in your story at the top. Another way to think about it is to present your story as one large file, and the current line is at the bottom of the file. If this helps you figure it out, can you feel it? more appropriate than "/".

0
source

I had the same problem. I was not able to solve it as such, but I found a suitable working solution: I added a binding for the edit command line function, which translates me into $EDITOR with the current line in the buffer. It’s easy to jump to a given template.

See the / usr / share / zsh / functions / Zle / edit-command line for how to link a function.

0
source

All Articles