Some basic list sources for coc.nvim
Including:
-
files
search files from current cwd. -
mru
most recent used files. -
grep
grep text from current cwd. -
words
search word in current buffer. -
locationlist
items from vim's location list. -
quickfix
items from vim's quickfix list. -
buffers
current buffer list. -
helptags
helptags of vim. -
tags
search tag files. -
filetypes
file types. -
colors
colors schemes. -
marks
marks of vim. -
windows
windows of vim. -
vimcommands
available vim commands. -
maps
key mappings. -
cmdhistory
history of commands. -
searchhistory
history of search.
For snippets list, use coc-snippets.
For git related list, use coc-git.
For yank history, use coc-yank.
- Match for filename would be prefered.
- Match for start character of path segment would be prefered.
- Files are sorted by mru when score is same.
- Grep source use literal string by default.
In your vim/neovim, run command:
:CocInstall coc-lists
Type lists.source
to in coc-settings.json to get available options.
Type ?
on normal mode to get detail help of current list.
mru.validate
remove none exists files from mru list.tags.generate
generate tags of current project (in current cwd).
Q: How to make grep easier?
A: Create custom command like:
command! -nargs=+ -complete=custom,s:GrepArgs Rg exe 'CocList grep '.<q-args>
function! s:GrepArgs(...)
let list = ['-S', '-smartcase', '-i', '-ignorecase', '-w', '-word',
\ '-e', '-regex', '-u', '-skip-vcs-ignores', '-t', '-extension']
return join(list, "\n")
endfunction
Q: How to grep by motion?
A: Create custom keymappings like:
vnoremap <leader>g :<C-u>call <SID>GrepFromSelected(visualmode())<CR>
nnoremap <leader>g :<C-u>set operatorfunc=<SID>GrepFromSelected<CR>g@
function! s:GrepFromSelected(type)
let saved_unnamed_register = @@
if a:type ==# 'v'
normal! `<v`>y
elseif a:type ==# 'char'
normal! `[v`]y
else
return
endif
let word = substitute(@@, '\n$', '', 'g')
let word = escape(word, '| ')
let @@ = saved_unnamed_register
execute 'CocList grep '.word
endfunction
Q: How to grep current word in current buffer?
A: Create kep-mapping like:
nnoremap <silent> <space>w :exe 'CocList -I --normal --input='.expand('<cword>').' words'<CR>
MIT