Vim Search with "Current Occurrence / Total Occurrences" Shown at the Bottom [duplicate] - vim

This question already has answers here:
Show Count of Matches in Vim
(11 answers)
Closed 8 years ago.
I am always using */# to search for the next/previous occurrence of the variable or function under cursor. Is there a way to display the current occurrence and the total occurrences of my the search result at the bottom of Vim. For example, it could be something like 1 of 5 when you search a word in Chrome.
It doesn't need to list all the occurrences in a window, but I guess it should be able to know all the occurrences in the background.

You can use vimgrep that will open the list in the bottom
:vimgrep foo %
:copen
:cclose to close the list.
You can use :cnext or :cprevious to navigate in the list of results.
% is an alias for current file name & path.
You can also use the option grepprg and the command :grep to use system grep.
As mentioned by sehe, lgrep or lvimgrp is another possible variable.(with associated lopen, lclose,...)
Have a look at :help grep to see what options are better for you.

Related

How to trace a word back to where it was declared across multiple files in vim? [duplicate]

This question already has answers here:
Jump to function definition
(11 answers)
Closed 7 years ago.
When reading through a person's code, I may be looking through a program that comprises 10+ files. I would like the ability to search for where an object/struct/type def have been declared.
Does vim allow you to do this kind of search? If so how?
You can use the CTRL-] command to "Jump to the definition of the keyword under the cursor." (see :h ctrl-]).
For this to work, you will need to create a tags file, for example with a program like ctags. The manual has more on this, see :h tag.
Sounds like you could use lvim to grep a word across multiple files.
From the documentation :
to search for the words "house" or "home" in all .txt files in the
current directory, use:
:lvim /\<\(house\|home\)\>/gj *.txt
:lw
You can also integrate external programs, like grep or findstr into vim for faster searching, but those will depend on your OS: http://vim.wikia.com/wiki/Find_in_files_within_Vim#Using_external_programs_for_fast_searches

How do I open files from my oldfiles list in vim?

In vim, I can type :oldfiles to see a list of files I've previously edited. Awesome feature!
But now I want to open one or more files from that list into a buffer. How can I do that?
Once you are at the bottom of the list you are supposed to press : and issue a command, using this "weird" notation:
:command #<91
where command could be any edit-like command (:edit, :tabedit, :split, :vsplit, :next, :args, etc.) and #< means "old file number…".
To edit entry 91, use:
:e #<91
To edit entries 18, 42 and 93, use:
:args #<18 #<42 #<93
If you use :help oldfiles, you will find the command :browse oldfiles which should do what you want.
:bro[wse] ol[dfiles][!]
List file names as with |:oldfiles|, and then prompt
for a number. When the number is valid that file from
the list is edited.
If you get the |press-enter| prompt you can press "q"
and still get the prompt to enter a file number.
Use ! to abandon a modified buffer. |abandon|
{not when compiled with tiny or small features}
Nearly 8 years later I stumbled on this old question and thought I'd update with what I do now (which is miles ahead of where this question ended).
I use fzf.vim and just type :History and then get an awesome fuzzy search over :oldfiles !

Get how many times a given pattern are matched in vim [duplicate]

This question already has answers here:
Show Count of Matches in Vim
(11 answers)
Closed 8 years ago.
I an use /pattern to match patterns in the current file, is there a way to show many many matches there are after I hit enter for previous search command? Then I will have a sense that how many navigation to do to go through all of them.
You can define a simple mapping that prints the number of matches:
:nnoremap <A-n> :%s///gn<CR>
41 matches on 17 lines
My SearchPosition plugin provides a more elaborate variant of this:
1 match after cursor in this line, 8 following, 2 in previous lines;
total 10 within 11,42 for /\<SearchPosition\>/
There's also the IndexedSearch plugin, which integrates the reporting with the n / N commands.
As an alternative to /pattern, you could use:
:vim /pattern % | cw
to open a list of matches in the quickfix window.
You can also use:
:il[ist] /pattern/
and choose from the list with:
:{line number}

How to move to a certain character from right to left of line in Vim [duplicate]

This question already has answers here:
Vim - Delete til last occurrence of character in line
(5 answers)
Closed 8 years ago.
This is a sentence
If the cursor is on s of This, I want to move the cursor on n of sentence
I can do $Fn
But this can't be used combining with other command like delete
e.g If the cursor is on s of This, and delete all between cursor and n of sentence
d$Fn doesn't work
Anyone knows how to do this?
Assume that you have trouble with deleting words between s and the second n in "sentence". You can do it by
d2fn
And as #kev mentioned, easymotion is a good choice, with easymotion you can do it in a more intuitive way like
d<Leader><Leader>fn
the above command will highlight n in the line and let you choose.
My JumpToLastOccurrence plugin extends the built-in f/F/t/T motions with counterparts that move to the last occurrence of {char} in the line. Your example would be d,fn.
Vim plugin easymotion can help you.
As others have said, you can use the search command / in combination with the d command to delete up to a pattern match.
But, you can also make use of search offsets to place the cursor anywhere you want in relation to that search. See :help search-offset for details, but in your case:
d/senten/e will delete up to and including the second 'n' in "sentence".
You could also use d/sentence/e-2 to do the same thing but limit the match even more.
This is very powerful in combination with incremental search and search highlighting, because then you can see exactly what you're acting on before you hit <Enter> to finish the command, or <Esc> or <C-C> to cancel the whole thing.
You could use visual mode: v$Fnd
My Vim plugin ft_improved can also help. You simply keep on typing until the match is unique.
I don’t know which “n” in “sentence” is referred to here, but you can indeed use d to do this. Simply combine it with search (/):
d/n
Or, if you want to delete up to the second “n” in “sentence”, you could make the search pattern one character more specific:
d/nc

How to get highlighting from interactive regex search in emac to remain highlight until deactivated? [duplicate]

This question already has an answer here:
emacs isearch lazy highlight for whole buffer
(1 answer)
Closed 8 years ago.
How to get highlighting from interactive regex search in emac to remain highlight until deactivated? For instance, with the text provided and running M-C-s (Regexp I-Search) with input 'file' will highlight the 3 'file' words in the text below.
;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.
Regexp I-Search %> file
But, once I start to edit the file the highlighting will disappear. I'd like to keep the highlighting for a while -- until I run another command to turn it off. How could I do this?
If you set the variable lazy-highlight-cleanup to nil, then the highlight remains until the next search:
(setq lazy-highlight-cleanup nil)
Or, until you manually call M-x lazy-highlight-cleanup.
You're looking for highlight-regexp bound to M-s h r. M-s h u unhighlights.
highlight-symbol provides a nice wrapper around this.

Resources