vim + CtrlP plugin - case insensitive search? - vim

does anybody know how to perform a case insensitive file search with vim's plugin CtrlP? I can't seem to find that in the instructions anywhere. Ideally it would replace the standard CTRL+P shortcut.
Thank you!

The file search relies on the match function in VIM. To make the search case insensitive, simply issue the following command:
:set ignorecase
If you want this to be the default behaviour, you can add the command to your .vimrc file.

Related

Force Case sensitive search in vim [duplicate]

I'd like to search for an upper case word, for example COPYRIGHT in a file. I tried performing a search like:
/copyright/i # Doesn't work
but it doesn't work. I know that in Perl, if I give the i flag into a regex it will turn the regex into a case-insensitive regex. It seems that Vim has its own way to indicate a case-insensitive regex.
You can use the \c escape sequence anywhere in the pattern. For example:
/\ccopyright or /copyright\c or even /copyri\cght
To do the inverse (case sensitive matching), use \C (capital C) instead.
As well as the suggestions for \c and ignorecase, I find the smartcase very useful. If you search for something containing uppercase characters, it will do a case sensitive search; if you search for something purely lowercase, it will do a case insensitive search. You can use \c and \C to override this:
:set ignorecase
:set smartcase
/copyright " Case insensitive
/Copyright " Case sensitive
/copyright\C " Case sensitive
/Copyright\c " Case insensitive
See:
:help /\c
:help /\C
:help 'smartcase'
You can set the ic option in Vim before the search:
:set ic
To go back to case-sensitive searches use:
:set noic
ic is shorthand for ignorecase
You can issue the command
:set ignorecase
and after that your searches will be case-insensitive.
You can use in your vimrc those commands:
set ignorecase - All your searches will be case insensitive
set smartcase - Your search will be case sensitive if it contains an uppercase letter
You need to set ignorecase if you want to use what smartcase provides.
I wrote recently an article about Vim search commands (both built in command and the best plugins to search efficiently).
To switch between case sensitive and insensitive search I use this mapping in my .vimrc
nmap <F9> :set ignorecase! ignorecase?
As others suggested:
:set ic
But the cool stuff is You can toggle such modes with:
:set ic!
The good old vim[grep] command..
:vimgrep /example\c/ &
\c for case insensitive
\C for case sensitive
% is to search in the current buffer
By default, all searches in vi are case-sensitive. To do a case-insensitive search, go into command mode (press Escape), and type-
:set ignorecase
You can also type -
:set ic as an abbreviation.
To change back to case-sensitive mode, type-
:set noignorecase or :set noic in command mode
put this command in your vimrc file
set ic
always do case insensitive search
I prefer to use \c at the end of the search string:
/copyright\c
As #huyz mention sometimes desired behavior is using case-insensitive searches but case-sensitive substitutions. My solution for that:
nnoremap / /\c
nnoremap ? ?\c
With that always when you hit / or ? it will add \c for case-insensitive search.
Vim have 2 modes
1.edit mode
normal mode( Esc )
Search will work for normal mode
/\c for case sensitive
/\csearch
You can set ignorecase by default, run this in shell
echo "set ic" >> ~/.vimrc
Note it is a difference where you place modifiers such as "\c" in your expresion:
You can use the \c escape sequence anywhere in the pattern
Regardless from the accepted answers, which states that it is no difference of where to place modyfier in a regex pattern, its looks like it actually does matter.
example text:
asdasdasdasdasd wiktor asdasdasdasd
adasdasdasd wiktor asdasda ahjkjlkhjkl
asdasd asd asdasdasdasd iuuuu -
asdjkkkkkkkaopbsdasda
wiktor ----(---------------------)--
Match
\c^.*A?.*$
^\c.*A?.*$
^.*\cA?.*$
^.*A\c?.*$
will output:
No match
^.\c*A?.*$
^.*A?\c.*$
^.*A?.\c*$
^.*A?.*$\c
will output:
vim -version VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Jun 1 2020 06:42:35)
Included patches: 1-869
Some important information, if u want to find out more about the commands of vim, as mentioned below u can give a try the following steps :
invoke the command "help" follow by a space and then complete the word with TAB key, once u find the right command press return key.
:help ignorecase
information like the following will be displayed :
you will be able to move forward and backward and also watch the short command, such as the case of "ignorecase" ( 'ic' ). In addition, another short example could be the case of 'smartcase' ('scs' and some more) :
In order to leave of the documentation just type ":q" as usual and you will return to "command mode" .
:q
I really hope the information provided would be helpful for someone.
Best regards,

How do I search in all files of my project using VIM?

There are a couple of things I do not yet understand the VIM way.
One of these is searching in a project like so (using VIM in Atom):
I use CtrlP currently for file names, but what about the contents?
How can I search with a string, and then look through a list of all occurrences using VIM and/or VIM plugins?
I've found an even better solution for this: FZF
It simply searches through everything in your project asynchronously using the :Ag command.
Use :grep or :vimgrep to search file contents. The results are put onto the "location list" which you can open by typing :cw Enter.
Syntax for :grep is, by default, the same as the grep(1) command:
:grep 'my pattern.*' /path/to/dir
By default it will search the current directory (:pwd). I added set autochdir to my .vimrc so my PWD always follows the file I'm editing.
The major difference between :grep and :vimgrep is that :vimgrep (:vim for short) uses Vim-compatible regular expressions, whereas :grep uses whatever regular expressions your &grepprg uses.
You can use a custom program by setting &grepprg to something different. I personally like ack which uses Perl-compatible regex.
Apart from fzf, there are also other excellent plugins for fuzzy finding.
telescope.nvim (neovim only): after install, just use Telescope live_grep to search through your project.
Leaderf: another fuzzy finder with good performance. After install, use Leaderf rg to search through your project.
To open a file, I highlight the row (Shift-v) in the location list and hit Enter.

How to highlight search words in vim permanently?

I want to highlight the search keyword in Vim. Mainly I use vim to debug the logs.
I always have to use :se hlsearch to highlight the search keyword.
So, I want the solution that it should set command permanently, and I should not use the command always when vim starts.
Set the command in .vimrc.
Use the following commands:
Open ~/.vimrc file (or create it if it didn't exist).
Add set hlsearch in the file.
Save the file.
Now your search will always be highlighted in vim.
For single time use, just use :set hlsearch in vim, which will be in effect for that instance only.
If you want to highlight multiple searches (in parallel, with different colors), check out my Mark plugin; it also allows to persist the highlightings across Vim sessions through the viminfo file; cp. :help mark-persistence.
For those wanting to visually keep highlighted their search:
:syn match stupid "ctrl + /"
:hi stupid ctermbg=Red guibg=Red
Explanation:
The first line add your regex to a syntax type called "stupid" (note that ctrl + / means you must press ctrl+R then / to get the content of the search registry).
The second line gives a red color to the "stupid" syntax regex.
My SelX plugin allows you to highlight and search for many different things at once on a per-tab basis, with different colours. The highlight config can be saved to a vim session
https://www.vim.org/scripts/script.php?script_id=5875

How to autocomplete file paths in Vim, just like in zsh?

In Zsh, I can use filename completion with slashes to target a file deep in my source tree. For instance if I type:
vim s/w/t/u/f >TAB<
zsh replaces the pattern with:
vim src/wp-contents/themes/us/functions.php
What I'd like is to be able to target files the same way at the Vim command line, so that typing
:vi s/w/t/u/f >TAB<
will autocomplete to:
:vi src/wp-contents/themes/us/functions.php
I'm trying to parse the Vim docs for wildmode, but I don't see what settings would give me this. It's doing autocompletion for individual filenames, but not file paths. Does Vim support this natively? Or how can I customize the autocomplete algorithm for files?
Thanks for any advice!
-mykle-
I couldn't find a plugin to do this, so I wrote one. It's called vim-zsh-path-completion. It does what you're looking for, although via <C-s> rather than <Tab>. You can use it with <Tab> for even more control over what matches, though.
It's got bugs, but for basic paths without spaces/special characters, it should work. I think it's useful enough in its current state to be helpful. I hope to iron out the bugs and clean up the code, but I figured I'd start soliciting feedback now.
Thanks for the idea!
Original (wrong) answer, but with some useful information about Vim's wildmode.
Put the following in your .vimrc:
set wildmenu
set wildmode=list:longest
That will complete to the longest unique match on <Tab>, including appending a / and descending into directories where appropriate. If there are multiple matches, it will show a list of matches for what you've entered so far. Then you can type more characters and <Tab> again to complete.
I prefer the following setting, which completes to the first unique match on <Tab>, and then pops up a menu if you hit <Tab> again, which you can navigate with the arrow keys and hit enter to select from:
set wildmode=list:longest,list:full
Check out :help wildmenu and :help wildmode. You might also want to set wildignore to a list of patterns to ignore when completing. I have mine as:
set wildignore=.git,*.swp,*/tmp/*
Vim doesn't have such a feature by default. The closest buil-in feature is the wildmenu/wildmode combo but it's still very different.
A quick look at the script section of vim.org didn't return anything but I didn't look too far: you should dig further. Maybe it's there, somewhere.
Did you try Command-T, LustyExplorer, FuzzyFinder, CtrlP or one of the many similar plugins?
I use CtrlP and fuzzy matching can be done on filepath or filename. When done on filepath, I can use the keysequence below to open src/wp-contents/themes/us/functions.php (assuming functions.php is the only file under us that starts with a f):
,f " my custom mapping for the :CtrlP command
swtuf<CR>
edit
In thinking about a possible solution I'm afraid I was a little myopic. I was focused on your exact requirements but Vim has cool tricks when it comes to opening files!
The :e[dit] command accepts two types of wildcards: * is like the * you would use in your shell and ** means "any subdirectory".
So it's entirely possible to do:
:e s*/w*/t*/u*/f*<Tab>
or something like:
:e **/us/f<Tab>
or even:
:e **/fun<Tab>
Combined with the wildmode settings in Jim's answer, I think you have got a pretty powerful file navigation tool, here.

vim automated replacement

I have an automatic replacement done by my vim setup, which systematically replaces all occurences of "sql" in command line by "SQL".
So when I type:
:e myfile.sql
it is translated in
:e myfile.SQL
and when I search
/sql
it is tranlasted in
/SQL
There's probably some parameters in the .vimrc, or some file sourced by .vimrc that generates this behaviour (I do not have control of everything that the .vimrc does since there's some amount of corporate .vimrc involved here), but I find myself unable to localize the part of setup that does this, or to desactivate it retroactively.
Can somebody who knows vim well help?
I have vim 7.1, running on Linux
Thanks
Probably an abbreviation set as follows:
abbrev sql SQL
The Vim documentation tells you how to determine the last location where an abbreviation was defined:
:abbreviate-verbose
When 'verbose' is non-zero, listing an abbreviation will also display where it
was last defined. Example:
:verbose abbreviate
! teh the
Last set from /home/abcd/vim/abbr.vim
So typing :verbose abbreviate should help you locate the SQL abbreviation.
cmap sql SQL
maybe?

Resources