Cscope Syntax hightlight search within search - vim

I am using CSCOPE for my project and I have few question.
1) Can I color the search result (mostly when I serach using
":cs f s " i.e. within the open file.
2) Is there a way to search within search? Like I search "ret_val" and it gave 1000 result, instead of going each line, can I search some more like folder name etc?

I am not sure how you use the tool, but generally, the answer is yes.
1) You could either redirect results to file, lets say out.cscope then create syntax file for file type *.csope OR, use a function to run the tool, then locally set up the buffer with adequate hi and match options
2) If you saved search results in a cscope file then you can search it normally. Otherwise you can redir output to new tab/split and again search the buffer (which now doesn't need to have externally associated file. I suggest you to use vim-foldsearch plugin to fold out anything (not) in the match. You can even delete folded sections (with or without any number of context lines) so that only stuff you are interested in finally remains in the buffer (i.e. it behaves like filter). Alternatively you can use unite plugin and it filtering source lines which filters lines as you type the keyword. Actually, I would personally go with that option as it provides most interactive way of working.

Related

How to autocomplete in vim based off partial matching via ctags

Example:
In a file in another directory I have a function defined by the following:
def _generator_function_1(self):
passs
In the file of my current directory, I have typed the following:
def test_generI
where I denotes my cursor position.
I would like to use vim's autocompletion functionality (i.e. via ^n or ^p) to autocomplete the function definition to test_generator_function_1. Is there a way of configuring vim autocompletion to match not based off full-prefixes? Or, is there a way in ctags to generate tags based off keywords instead of full function definitions?
EDIT:
To clarify, I am specifically wondering if keyword-based autocompletion exists. I have autocompletion by tags setting up, so if I typed "_gen", then ^n would complete to give me "_generator_function_1". In my example, however, it is because the string is prefixed by "test" that "test_gener" as the starting typed word does not lead to any autocomplete suggestions. So I am wondering if this can somehow be made possible.
Vim doesn't have "autocompletion functionality". It only has "completion", not "autocompletion". You need a plugin for "autocompletion".
No, there's no way to obtain your desired behavior without some serious vimscripting. See :help complete-functions.

Is there a one-liner to tell vim/ctags autocompletion to search from the middle of a word?

In vim (in Insert mode, after running exuberant ctags), I am using ctrl-x followed by ctrl-] to bring up a dropdown of various possible words/tokens. It's a great feature.
The problem is that by default, this list starts with a bunch of numeric options and automatically inserts the first numeric option, and if I backspace to get rid of the numbers and start typing a part of a word fresh -- with the idea of searching from the middle of the word -- the autocompletion behavior exits entirely.
I know I could type the first letter of the word that I want, then go from there. But that assumes that I know the first letter of the word, which is not necessarily a given.
For example, if I'm working on a pair-programming project with a friend during a long weekend, I might not remember at any given moment whether he called his method promoteRecordStatus(), updateRecordStatus() or boostRecordStatus(). In this example, I would like to type RecordStatus and get the relevant result, which does not seem to be possible at a glance with the current behavior.
So with that scenario in mind: Is there a simple, vim-native way to tell the editor to start its autocompletion without any assumptions, then search all available tokens for my typed string in all parts of each token?
I will of course consider plugin suggestions helpful, but I would prefer a short, vim-native answer that doesn't require any plugins if possible. Ideally, the configuration could be set using just a line or two.
The built-in completions all require a match at the starting position. In some cases, you could drop separator characters from the 'iskeyword' option (e.g. in Vimscript, drop # to be able to complete individual components from foo#bar#BazFunction()), but this won't work for camelCaseWords at all.
Custom :help complete-functions can implement any completion search, though. To be based on the tags database, it would have to use taglist() as a source, and filter according to the completion base entered before triggering the completion. If you do not anchor this pattern match at the beginning, you have your desired completion.

Searching hundreds of org-mode files without loading them into Emacs?

I've compiled hundres of org-mode files in a specific directory.
Is there any way to search these files for specific keywords, or build agendas,
without loading them into Emacs, possibly using external search tools such as `ag'?
You can search them using Icicles. In Icicle minor mode, C-x C-f is bound to a multi-completion command that lets you match against the file name or the file content, or both. You can change the match patterns on the fly. Buffer *Completions* shows you the files that match.
And you can use progressive completion, combining any number of search patterns. Each pattern can itself be a regexp (or a substring), but it is a lot easier to combine several simple patterns than it is to come up with one complex pattern to DTRT. You can also negate patterns (obtain the complement of the match set).
You can visit any of the matching files that you like -- any number of them during the same command invocation. Or you can visit none of them if you like (C-g), and just use the command to locate those that match. You can use C-M-RET, C-M-down, etc. to get information about particular matching files (file type, permissions, size, last access time, creation time, etc.).
You can act on any number of them in some other way than visiting, using an alternate function that you specify: Just bind variable icicle-candidate-alt-action-fn to this function in a command you write that invokes icicle-find-file-of-content. Lots more features --- see Icicles - File-Name Input.

VIM: use incremental search for file replace

I know that the incsearch setting controls how search in vim highlights as you type. I would like to have the same incremental search and highlight when using the replace command (:%s/foo/bar/ )
The easiest way to do that is to do a search like normal, using 'incsearch' to help ensure the pattern is matching what you want. Once you've got that nailed down, you can either
Leave out the search pattern in :%s//bar/. When there's no specified search pattern, the current value of the / register is used, which will be the search you just did.
Insert the search pattern into the :s command using Ctrl+r/ (see :help c_ctrl-r) or Ctrl+rCtrl+o/ (if the search contains control characters, like ^H). This is useful if you want to make some final tweaks to the pattern or if you want to have it in your command history so you can reuse it even after performing another search.
You could add c at the end of your command like that:
:%s/foo/bar/c
It will walk through all the instances of foo and ask for your confirmation (that's what the c stands for) before changing it to bar.
It's not exactly what you are after though.

How do I search through MATLAB command history?

I would like to search for a specific command I've previously used. Is it possible to do a free text search on MATLAB command history?
Yes. Matlab stores your command history in a file called history.m in the "preferences folder," a directory containing preferences, history, and layout files. You can find the preferences folder using the prefdir command:
>> prefdir
ans =
/home/tobin/.matlab/R2010a
Then search the history.m file in that directory using the mechanism of your choice. For instance, using grep on unix:
>> chdir(prefdir)
>> !grep plot history.m
plot(f, abs(tf))
doc biplot
!grep plot history.m
You can also simply use the search function in the command history window if you just want to use the GUI.
If you want to accomplish this in a programmatic and platform-independent manner, you can first use MATLAB's Java internals to get the command history as a character array:
history = com.mathworks.mlservices.MLCommandHistoryServices.getSessionHistory;
historyText = char(history);
Then you can search through the character array however you like, using functions like STRFIND or REGEXP. You can also turn the character array into a cell array of strings (one line per cell) with the function CELLSTR, since they can sometimes be easier to work with.

Resources