too*_*php 212
:g//p
Run Code Online (Sandbox Code Playgroud)
在更长的形式:
:global/regular-expression/print
Run Code Online (Sandbox Code Playgroud)
您可以省略模式/正则表达式,Vim将重复使用上一个搜索词.
花絮:在grep的工具是这个命令序列命名.
fre*_*eeo 33
刚刚学会了一个新的:Location List!
键入:lvim foo %要foo在当前文件中搜索,并输入包含foo在位置列表中的所有匹配项.
键入:lopen以在quickfix窗口中打开位置列表,该窗口可以像往常一样完全导航.
使用:lnext/ :lprevious来完成列表(使用tpope/unmpaired映射获得最佳体验)
dek*_*ard 15
另一种可能性是使用包含文件搜索命令.
[I
Run Code Online (Sandbox Code Playgroud)
这将列出光标下所有出现的单词.它可能比您需要的多,因为它还将搜索当前文件中包含的任何文件.
但是这个命令的好处是搜索结果显示还显示了匹配数的计数,以及每个匹配的行号.
:help include-search
Run Code Online (Sandbox Code Playgroud)
看到很多变种.
关于
:g//p
Run Code Online (Sandbox Code Playgroud)
这可以进一步减少到
:g//
Run Code Online (Sandbox Code Playgroud)
因为,正如其他人所说,p(rint)是默认动作.
Kev*_*vin 10
使用:set hlsearch将突出显示黄色的所有匹配,允许您轻松扫描文件以进行匹配.在搜索之后,这可能不是你想要的:g // p会给你列出的匹配
详细说明......而不是
/example
:g//p
Run Code Online (Sandbox Code Playgroud)
你也可以直接写
:g/example/p
Run Code Online (Sandbox Code Playgroud)
或者,由于p(rint)是:g(lobal)命令的默认操作,因此可以缩短为
:g/example
Run Code Online (Sandbox Code Playgroud)
而不是p(rint),其他动作也是可能的,例如d(elete).请参阅:help:global
你可以得到一个漂亮的quickfix窗口,匹配形成你当前的搜索模式
:vim // %
:copen
Run Code Online (Sandbox Code Playgroud)
如果您之前使用just制作了复杂的搜索模式,则非常方便 /pattern
编辑:刚刚发现这也适用于所有打开的缓冲区
:bufdo vimgrepadd // %
:copen
Run Code Online (Sandbox Code Playgroud)
g/pattern
Run Code Online (Sandbox Code Playgroud)
如果有:set number,上面的命令也会显示行号.
如果你还没有:set number,那么
g/pattern/#
Run Code Online (Sandbox Code Playgroud)
将显示行号.
" put in your ~/.vimrc file
" START search related configs and helps
"
" ignore case when searching
set ignorecase
" search as characters are entered, as you type in more characters, the search is refined
set incsearch
" highlight matches, in normal mode try typing * or even g* when cursor on string
set hlsearch
" yank those cheat commands, in normal mode type q: than p to paste in the opened cmdline
" how-to search for a string recursively
" :grep! "\<doLogErrorMsg\>" . -r
"
" how-to search recursively , omit log and git files
" :vimgrep /srch/ `find . -type f \| grep -v .git \| grep -v .log`
" :vimgrep /srch/ `find . -type f -name '*.pm' -o -name '*.pl'`
"
" how-to search for the "srch" from the current dir recursively in the shell
" vim -c ':vimgrep /srch/ `find . -type f \| grep -v .git \| grep -v .log`'
"
" how-to highlight the after the search the searchable string
" in normmal mode press g* when the cursor is on a matched string
" how-to jump between the search matches - open the quick fix window by
" :copen 22
" how-to to close the quick fix window
" :ccl
" F5 will find the next occurrence after vimgrep
map <F5> :cp!<CR>
" F6 will find the previous occurrence after vimgrep
map <F6> :cn!<CR>
" F8 search for word under the cursor recursively , :copen , to close -> :ccl
nnoremap <F8> :grep! "\<<cword>\>" . -r<CR>:copen 33<CR>
" omit a dir from all searches to perform globally
set wildignore+=**/node_modules/**
" use perl regexes - src: http://andrewradev.com/2011/05/08/vim-regexes/
noremap / /\v
"
" STOP search related configs and helps
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37042 次 |
| 最近记录: |