I am studying A* search in artificial intelligence.
In this Romania map with straight distance line as h(n), I am searching a path from Arad to Bucharest using A* search.
After RV(220+193=413, A -> S-> RV) is expanded, Fagaras is expanded instead of Pittesti.
Why is Fagaras is expanded instead of directly expanding Pittesti?
Related
I want to be able to handle fuzzy search, as well as synonyms at the same time.
I tried it in a several ways, but I cannot get it working.
I have these values in my index:
white
black
light
dark
and this synonym rules:
white,light
black,dark
If I perform the query queryType=full&search=light or queryType=full&search=white, it always returns both values, light and white.
So synonyms are working.
If I perform the query queryType=full&search=light~1, then only light will be returned. But where is white?
Is the combination of fuzzy search and synonyms not possible yet, or am I doing something wrong?
Synonym expansions do not apply to wildcard search terms; prefix, fuzzy, and regex terms aren't expanded.
If you need to do a single query that applies synonym expansion and wildcard, regex, or fuzzy searches, you can combine the queries using the OR syntax.
For example, to combine synonyms with fuzzy search you would need to have query like this:
search=light~1|light
or
queryType=full&search=light OR light~1
if you're using Lucene query syntax
I have a text file with tags (preceded by ©) :
The Louvre is near the Seine (©Paris, ©Museum)
Pergamon Museum is in Museum Insel (©Berlin, ©Museum)
British Museum is near Russell Square (©London, ©Museum)
1) Whenever I want to use Ctrl+N and ©, in order to add a tag, I would like to have :
©Paris
©Berlin
©London
but instead, I get a list of all the different words of the buffer.
2) Better still, I would like that list to be alphabetically ordered :
©Berlin
©London
©Paris
Is there a solution to these two complementary questions ?
Partial answer:
Add character(s) to iskeyword, in current buffer or vimrc
:set iskeyword+=©
I don't think there is a pre-defined setting to sort the completion list. Plugins might be there, not sure.
Ctrlp searches in backward direction (previous matches)
Ctrln searches in forward direction (next matches)
Is there a way in Vim to paste the search register on the command-line, but without the surrounding \< brackets \>? I often find myself doing a search in a buffer, and then wanting to use the matched pattern as an argument to grep (more specifically, ack.vim).
Here's what happens if you search for foo and then enter :Ack '<C-r>/':
:Ack '\<foo\>'
This will fail to find anything. What I want instead is:
:Ack 'foo'
This is of course a simplistic example. Where this would be more valuable is with more complex search results.
I am aware of <C-r><C-w> and <C-r><C-a> for pasting the word/WORD under the cursor, and these often suffice, but not always.
<C-r>/ inserts your search pattern as you typed it: if you did /foo, the search register contains foo.
Note that <C-r>/ inserts the search pattern, not the match: if you search for foo\d, <C-r>/ will insert foo\d, not foo9.
As you found out, \< and \> are added if you used * or # in order to limit the search to whole words. Use g* and g# to not search whole words and thus avoid the \<\>.
Here is a possibly useful mapping:
nnoremap <F6> :Ack '<C-r>=expand("<cword>")<CR>'
Unless you're doing a purely literal search, there's a difference between the search pattern (a regular expression) and the (list of) matches (strings from the buffer).
If you're interested in the latter, my PatternComplete plugin offers insert-mode completion of all matches, and it can also insert the first match of the last search pattern with <C-R>&.
Is there a shortcut in Vim for going to the next word which is the same as the word cursor is on? It should work without typing the word with search command /.
* goes to the next matching word and # goes to the previous matching word. * is so useful it's sometimes called the super star.
* and # are your friends ( forward and backward directions respectively )
While all the answers here are correct, I thought it may be useful to provide a little more info.
What * actually does is perform a forward search for \<word-under-the-cursor\>. Because this is just a search operation, you can then navigate forwards and backwards to the next occurrences using n and N. This also means your previous search is lost. # is exactly the same as * except it performs a reverse search.
The \< and \> in the search string are word boundaries in vim's regex language which is what makes this work so nicely. It's also important to note that what is considered a "word" is determined by the iskeyword option. See :help word for more information.
To search the current word under the cursor use '*'.
to search backwards for current cursor word use '#'
gd and its variants are also very handy. It works slightly differently from *, in that it searches for the local declaration of the word under the cursor (or global declaration if none local exists). You can then search through the results with n like you can with superstar, and it will skip comments. It can be helpful when you're editing code.
:help gd
This question was helpful for getting a count of a certain pattern in Vim, but it would be useful to me to store the count and sum the results so I can echo a concise summary.
I'm teaching a class on basic HTML to some high schoolers, and I'm using this script to be quickly check numbers of required elements throughout all their pages without leaving Vim. It works fine, but when students have more than 10 .html files it gets cumbersome to add up the various sections by hand.
Something like:
img_sum = :bufdo %s/<img>//gen
would be nice. I think I'll write a ruby script to check the pages more thoroughly and check for structure, but for now I'm curious about how to do this in Vim.
The problem can be solved by a counter separate from the one built-in into the
:substitute command: Use Vim-script variable to hold the number of pattern
matches. A convenient way to register every match and modify a particular
variable accordingly, is to take advantage of the substitute with an
expression feature of the :substitute command (see :help sub-replace-\=).
The idea is to use a substitution that evaluates an expression increasing
a counter on every occurrence, and does not change the text it is operating
on.
The first part of the technique cannot be implemented straightforwardly
because it is forbidden to use Ex commands in expressions (including \=
substitute expressions), and therefore it is not possible to use the :let
command to modify a variable. Answering the question "gVim find/replace
with counter", I have proposed a simple trick to overcome that limitation,
which is based on using a single-item list (or dictionary containing a single
key-value pair). Since the map() function transforms a list or a dictionary
in place, that only item could be changed in a constrained expression context.
To do that, one should call the map() function passing an expression
evaluating to the new value along with the list containing the current value.
The second half of the technique is how to avoid changing text when using
a substitution command. In order to achieve that, one can make the pattern
have zero-width by prepending \ze or by appending \zs atoms to it (see
:help /\zs, :help /\ze). In such a way, the modified pattern captures
a string of zero width just before or after the occurrence of the initial
pattern. So, if the replacement text is also empty, substitution does not
cause any change in the contents of a buffer. To make the substitute
expression evaluate to an empty string, one can just extract an empty
substring or sublist from the resulting value of that expression.
The two ideas are put into action in the following command.
:let n=[0] | bufdo %s/pattern\zs/\=map(n,'v:val+1')[1:]/ge
I think that answer above is hard to understand and more pretty way to use external command grep like this:
:let found=0
:bufdo let found=found+(system('grep "<p>" '.expand('%:p') . '| wc -l'))
:echo found