-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvim-utils.vim
145 lines (127 loc) · 3.84 KB
/
nvim-utils.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"
" Uses ripgrep go search for text. Unlike the default Rg fim fzf command,
" this version allows the use of `--type`. It requires an initial search
" pattern.
"
" Examples:
"
" Searches for ‘Login’ with uppercase “L” (smart-case).
"
" :MRg! -t css Login
"
" The results can be further filtered. That is, type the above
" command followed by other chars, like ‘form’ to further limit the
" search to files which contain ‘Login’ and match files relating
" to ‘form’.
"
command! -bang -nargs=* MRg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.<q-args>, 1,
\ fzf#vim#with_preview('right:50%'), <bang>0)
""
" Open Rg horizontally, on the right! I use this when I have a wide vim
" window, like when vim is fullscreen.
"
" Usage:
"
" :RGH [SEARCH]
"
" Examples:
"
" :RGH<CR> ...then start typing some query...
"
" :RGH query ...then type more to further refine the search...
"
command! -bang -nargs=* RGH
\ call fzf#vim#grep(
\ "rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(<q-args>),
\ 1,
\ fzf#vim#with_preview('right:50%'),
\ <bang>0)
""
" Open Rg vertically, above! I use this when I have a tall, but narrow
" vim window, like when vim is tiled to the left and some other application
" is tiled to the right.
"
" Usage:
"
" :RGV [SEARCH]
"
" Examples:
"
" :RGV<CR> ...then start typing some query...
"
" :RGV query ...then type more to further refine the search...
"
command! -bang -nargs=* RGV
\ call fzf#vim#grep(
\ "rg --column --line-number --no-heading --color=always --smart-case -- ".shellescape(<q-args>),
\ 1,
\ fzf#vim#with_preview('up:50%'),
\ <bang>0)
nnoremap <Leader>rg :MRg! -t
nnoremap <Leader>rh :RGH<CR>
nnoremap <Leader>rv :RGV<CR>
"
" Uses --fixed-strings (or -F) to allow string searches not requiring
" escaping especial characters.
"
command! -bang -nargs=* RGVt
\ call fzf#vim#grep(
\ "rg --column --line-number --no-heading --color=always --smart-case -F -- ".shellescape(<q-args>),
\ 1,
\ fzf#vim#with_preview('up:50%'),
\ <bang>0)
"
" Uses --fixed-strings (or -F) to allow string searches not requiring
" escaping especial characters.
"
command! -bang -nargs=* RGHt
\ call fzf#vim#grep(
\ "rg --column --line-number --no-heading --color=always --smart-case -F -- ".shellescape(<q-args>),
\ 1,
\ fzf#vim#with_preview('right:50%'),
\ <bang>0)
nnoremap <Leader>rht :RGHt
nnoremap <Leader>rvt :RGVt
"
" NOTE on --keep-right
"
" Somtimes it may seem --keep-right is not working, when in fact, the
" pattern being searched for appears far to the left so fzf has to
" keep that pattern visible, thus not showing the right portion of
" the matches.
"
"
" FZF Buffers with --keep-right so lines are trimmed to the left
" instead of to the right when they don't fit on the available space.
" It helps to see the actually filenames and their extensions.
"
command! -bang -nargs=* FZFBuffersKeepRight
\ call fzf#vim#buffers(
\ <q-args>,
\ fzf#vim#with_preview({'options': ['--keep-right']}),
\ <bang>0)
nnoremap <Leader>bb :FZFBuffersKeepRight<CR>
command! -bang -nargs=* FZFGitFilesKeepRight
\ call fzf#vim#gitfiles(
\ <q-args>,
\ fzf#vim#with_preview({'options': ['--keep-right']}),
\ <bang>0)
nnoremap <Leader>gf :FZFGitFilesKeepRight<CR>
command! -bang -nargs=* FZFGitFilesChangesKeepRight
\ call fzf#vim#gitfiles(
\ '?',
\ fzf#vim#with_preview({'options': ['--keep-right']}),
\ <bang>0)
nnoremap <Leader>g? :FZFGitFilesChangesKeepRight<CR>
command! -bang -nargs=* FZFFilesKeepRight
\ call fzf#vim#files(
\ <q-args>,
\ fzf#vim#with_preview({'options': ['--keep-right']}),
\ <bang>0)
nnoremap <Leader>\f :FZFFilesKeepRight<CR>
""
" https://prettier.io/docs/en/vim.html
"
command! -nargs=0 Prettier :call CocAction('runCommand', 'prettier.formatFile')