I am going screen logs of devstack with following command.
screen -x stack
I find searching in screens very difficult. Currently I start copy mode with
Ctrl A Esc and read all the logs, sometimes it is very irritating to go through all logs while searching for a single word.
Is there a good way for searching a word in screens?
from man screen I found
Searching:
/ Vi-like search forward.
? Vi-like search backward.
C-a s Emacs style incremental search forward.
C-r Emacs style reverse i-search.
but screens do not support vi-like forward search.
Once you are in scrollback mode with Ctrl + A, ESC, you should be able to search backwards through the buffer as described in the manual.
So to search for the word "string", press Ctrl + A, ESC, enter ?string and press Enter. It will take you backwards through the buffer to the word string. Pressing N will go to the next match (backwards) in the buffer.
To search forwards, the cursor should be anywhere but the end of the buffer, then use /string to search down.
In Ubuntu, there is a search button in the menu bar. You can search backwards/forward or even search with regular expressions as well.
Related
This is currently how I copy code from an editor to a search field in VS code using vscodevim.
Select text in editor somehow
Right click to open up the contextual menu (since pressing Ctrl+C does not seem to work on Ubuntu, even when in input mode, and 'p' does not work in the search field) and click copy
Press Ctrl+Shift+F to open the search field
Press Ctrl+V
I'm pretty sure this is not how copying from an editor to search field is intended to work. It it the steps 1 and 2 I would like to change to something better.
What is a more efficient and vim-like sequence?
If you want to search for the word under the cursor
Ctrl-F will do the trick.
Or you can use Vim's * command, which effectively does the same, but jumps to the next occurrence right away by default.
Otherwise
If you need to use the search field for whatever reason, then the standard Vim way to copy stuff to the clipboard works, so you can yank into the * or + registers. The steps will then be:
Select text
"+y (you can create a shortcut for this combination if you want)
Ctrl-Shift-F, Ctrl-V
See also: How to make vim paste from (and copy to) system's clipboard?.
Having said that, the more obvious approach might be to use Vim's built-in search features, so after selecting the text, the remaining steps would be y: (yanking selection to the default register and opening the command-line) then / or ? (search forward or backward), then <C-v> (pasting the yanked selection to the command-line - this works only in the VSCode plugin, while in Vim you should use <C-r>").
I'm new to VIM so there might be a better way using VIM commands but for now this works pretty well.
Go into insert mode with i than select the word you would like to search for (I'm using the mouse) and than just press ctrl + f. Your search window will open as usual containing the selected word in it.
In tmux I'm using vim mode to copy from the terminal buffer. The only thing I cannot accomplish that I usually do on vim is to go into highlight mode and highlight everything from current cursor posistion until the next occurence of a pattern search. For example, in vim if I go into visual mode (v) and then type (/pathern) all the text between the cursor position until the next occurence of pathern is highlighted.
Does anyone has a clue on how to accomplish such functionality?
so far tmux doesn't ship this feature. In copy mode you can use vim/emacs keybindings, but it is not a vim/emacs after all.
v then f/F works though. You can try submitting a feature request.
Or you can cp the buffer into your vim, and do whatever there.
I have incsearch and hlsearch enabled
So I hit / to enter search mode.
Then I type text I want to search for and it finds the first occurrence of the text I typed.
Then I want to jump to next occurrence of the text I typed without exiting search mode so that I could refine my search text later without having to exit to normal mode, then hitting n and then going back to search mode by hitting / again.
If this is possible, how can I do it?
The best thing that I can find that you can do is the following:
Search for your pattern using /blah
Then, hit n or ? until you see what's out there...
Then go back to / and press CTRL-r /
this will bring back the last pattern that you searched for, so you can continue entering more text there...
I'm sure you can remap that combination to some key so that you can quickly go back to the search with the pattern already entered.
I've found a way thanks to bwana147 from #vim irc channel on freenode.net
:cnoremap <c-n> <CR>n/<c-p>
After that typing text in search mode and then hitting ctrl-n goes to next occurrence of that text without exiting search mode
I have incsearch and hlsearch enabled. So I hit / to enter search mode. Then I type text which I want to search for and it finds the first occurrence.
Okey so far ...
Here, I can't quite understand what you're asking.
Then I want to jump to next occurrence of the text I typed without exiting search mode
This is done by pressing n
so that I could refine my search text later without having to exit to normal mode, then hitting n and then going back to search mode by hitting / again.
You got me lost here ... isn't this behaviour exactly what incsearch enables you?
Use Ctrl-g or Ctrl-t for incremental search. When you want to search something hit /some, then hit Ctrl-t this will jump the cursor to first some, but you stay in search mode, you can add "thing" to search, and search pattern will be /something.
To search forward in Vim for cake, I'd type /cake, but the cursor jumps to the first match when I press return. Is there a Vim command analogous to "find next"?
It is n for next and N for previous.
And if you use reverse search with ? (for example, ?cake) instead of /, it is the other way round.
If it is installed on your system, you should try to run vimtutor command from your terminal, which will start a tutorial of the basic Vim commands.
Rob Wells advice about * and # is also very pertinent.
The most useful shortcut in Vim, IMHO, is the * key.
Put the cursor on a word and hit the * key and you will jump to the next instance of that word.
The # key does the same, but it jumps to the previous instance of the word.
It is truly a time saver.
When I was beginning I needed to watch a demo.
How to search in Vim
type /
type search term e.g. "var"
press enter
for next instance press n (for previous N)
You may be looking for the n key.
Typing n will go to the next match.
As discussed, there are several ways to search:
/pattern
?pattern
* (and g*, which I sometimes use in macros)
# (and g#)
plus, navigating prev/next with N and n.
You can also edit/recall your search history by pulling up the search prompt with / and then cycle with C-p/C-n. Even more useful is q/, which takes you to a window where you can navigate the search history.
Also for consideration is the all-important 'hlsearch' (type :hls to enable). This makes it much easier to find multiple instances of your pattern. You might even want make your matches extra bright with something like:
hi Search ctermfg=yellow ctermbg=red guifg=...
But then you might go crazy with constant yellow matches all over your screen. So you’ll often find yourself using :noh. This is so common that a mapping is in order:
nmap <leader>z :noh<CR>
I easily remember this one as z since I used to constantly type /zz<CR> (which is a fast-to-type uncommon occurrence) to clear my highlighting. But the :noh mapping is way better.
If you press Ctrl + Enter after you press something like "/wordforsearch", then you can find the word "wordforsearch" in the current line. Then press n for the next match; press N for previous match.
Can standard mouse input be customized in vim (in my case gvim)? Plugins are acceptable options too.
I'm specifically interested in "overriding" a double-click on a word, so that instead of just highlighting the word, gvim does a search and thus highlights all instances of this word in the file. I've seen this functionality in other editors and found it very useful.
See :help double-click. It should have everything you need. For example from the help page:
An example, for using a double click to jump to the tag under the cursor:
:map <2-LeftMouse> :exe "tag ". expand("<cword>")<CR>
I don't regarding mouse, but you can press */# to search word under cursor forward/backward.