forked from exvim/main
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nvim.lua
650 lines (556 loc) · 22.2 KB
/
nvim.lua
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
--packer
local vim = _G.vim
local execute = vim.api.nvim_command
local fn = vim.fn
local cmd = vim.cmd
local o = vim.o
local g = vim.g
local empty = {}
local function isOSX()
return 0 ~= fn.has('macunix')
end
local function isLinux()
return 0 ~= fn.has('unix') and 0 == fn.has('macunix') and 0 == fn.has('win32unix')
end
local function isWindows()
return 0 ~= fn.has('win32') or 0 ~= fn.has('win64') or 0 ~= fn.has('win16')
end
--global options
--
-- set default encoding to utf-8
o.fileencoding = "utf-8" -- The encoding written to file
-- " Let Vim use utf-8 internally, because many scripts require this
o.encoding = "utf-8"
-- " Windows has traditionally used cp1252, so it's probably wise to
-- " fallback into cp1252 instead of eg. iso-8859-15.
-- " Newer Windows files might contain utf-8 or utf-16 LE so we might
-- " want to try them first.
o.fileencodings = "ucs-bom,utf-8,gbk,gb2312,big5,iso-8859-15,utf-16le" -- The encoding written to file
g.mapleader = ","
g.maplocalleader= ","
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
execute("!git clone https://github.com/wbthomason/packer.nvim " .. install_path)
execute "packadd packer.nvim"
end
--- Check if a file or directory exists in this path
local function require_plugin(plugin)
local plugin_prefix = fn.stdpath("data") .. "/site/pack/packer/opt/"
local plugin_path = plugin_prefix .. plugin .. "/"
-- print('test '..plugin_path)
local ok, err, code = os.rename(plugin_path, plugin_path)
if not ok then
if code == 13 then
-- Permission denied, but it exists
return true
end
end
-- print(ok, err, code)
if ok then vim.cmd("packadd " .. plugin) end
return ok, err, code
end
local function useAndRequire(use,config,plugin)
use(config)
require_plugin(plugin)
end
require("packer").startup(function(use)
-- Packer can manage itself as an optional plugin
use "wbthomason/packer.nvim"
-- Telescope
use {"nvim-lua/popup.nvim", opt = true}
require_plugin("popup.nvim")
use {"nvim-lua/plenary.nvim", opt = true}
require_plugin("plenary.nvim")
use {"nvim-telescope/telescope.nvim", opt = true}
use {"nvim-telescope/telescope-fzy-native.nvim", opt = true}
require_plugin("telescope.nvim")
use {"nvim-telescope/telescope-project.nvim", opt = true}
require_plugin('telescope-project.nvim')
if isLinux() then
use {"nvim-telescope/telescope-media-files.nvim", opt = true}
require_plugin('telescope-media-files.nvim')
end
use {"folke/trouble.nvim", opt = true}
require_plugin('trouble.nvim')
-- Treesitter
useAndRequire(use,{"nvim-treesitter/nvim-treesitter", run = ":TSUpdate"},"nvim-treesitter")
useAndRequire(use,{'andymass/vim-matchup', opt = true},"vim-matchup")
useAndRequire(use,{'nvim-treesitter/playground', opt = true},"playground")
-- ui
useAndRequire(use,{"mhinz/vim-startify", opt = true},"vim-startify")
-- Icons
useAndRequire(use,{"kyazdani42/nvim-web-devicons", opt = true},"nvim-web-devicons")
-- colorscheme
use {"morhetz/gruvbox", opt = true}
end)
-- cmd('filetype plugin indent on') -- filetype detection
cmd('filetype plugin on') -- filetype detection
cmd('syntax on') -- syntax highlighting
-- General
-- Default colorscheme setup
o.background = "dark"
cmd('colorscheme gruvbox')
--fix colorscheme
vim.cmd([[
highlight clear SignColumn " SignColumn should match background
highlight clear LineNr " Current line number row will have same background color in relative mode
"highlight clear CursorLineNr " Remove highlight color from current line number
hi VertSplit ctermbg=NONE guibg=NONE
]])
o.timeout = false
o.backup = false -- make backup file and leave it around
o.swapfile = false
-- set guifont
if isOSX() then
o.guifont = "DejaVuSansMono YaHei NF:h12"
elseif isWindows() then
o.guifont = "DejaVu Sans Mono for Powerline:h11:cANSI:qDRAFT"
else
o.guifont = "DejaVu Sans Mono for Powerline 12"
end
-- Redefine the shell redirection operator to receive both the stderr messages and stdout messages
-- cmd('set shellredir=>%s 2>&1')
o.history=50 -- keep 50 lines of command line history
o.updatetime=1000 -- default = 4000
o.autoread = true -- auto read same-file change ( better for vc/vim change )
o.maxmempattern=1000 -- enlarge maxmempattern from 1000 to ... (2000000 will give it without limit)
o.mouse = "a" -- Enable your mouse
-- Variable settings ( set all )
o.matchtime=0 -- 0 second to show the matching paren ( much faster )
o.scrolloff=7 -- minimal number of screen lines to keep above and below the cursor
o.number = true -- set numbered lines
o.relativenumber = true -- set relative number
o.cursorline = true -- Enable highlighting of the current line
o.wrap = false -- do not wrap text
-- Vim UI
-- o.wildmode=list:longest,full
o.wildmenu = true -- turn on wild menu, try typing :h and press <Tab>
o.showcmd = true-- display incomplete commands
o.cmdheight=1 -- 1 screen lines to use for the command-line
o.ruler = true-- show the cursor position all the time
o.hidden = true-- allow to change buffer without saving
o.shortmess = "aoOtTI" -- shortens messages to avoid 'press a key' prompt
o.lazyredraw = true-- do not redraw while executing macros (much faster)
o.laststatus=2 -- always have status-line
o.titlestring= '%t (%{expand("%:p:.:h")}/)'
cmd('set display+=lastline') -- for easy browse last line with wrap text
cmd('set completeopt-=preview')
-- Text edit {{
o.showfulltag = true -- show tag with function protype.
o.autoindent = true -- autoindent
o.smartindent = true -- smartindent
o.backspace='indent,eol,start' -- allow backspacing over everything in insert mode
-- indent options
-- see help cinoptions-values for more details
cmd('set cinoptions=>s,e0,n0,f0,{0,}0,^0,:0,=s,l0,b0,g0,hs,ps,ts,is,+s,c3,C0,0,(0,us,U0,w0,W0,m0,j0,)20,*30')
o.cindent = true
o.shiftwidth=4 -- set cindent on to autoinent when editing c/c++ file, with 4 shift width
o.tabstop=4 -- set tabstop to 4 characters
o.expandtab = true-- set expandtab on, the tab will be change to space automaticaly
o.ve='block' -- in visual block mode, cursor can be positioned where there is no actual character
cmd('set sessionoptions -=folds')
-- Fold text {{
o.foldmethod='marker'
o.foldmarker='{,}'
o.foldlevel=9999
o.diffopt='filler,context:9999'
o.showmatch = true-- show matching paren
o.incsearch = true-- do incremental searching
o.hlsearch = true-- highlight search terms
o.ignorecase = true-- set search/replace pattern to ignore case
o.smartcase = true-- set smartcase mode on, If there is upper case character in the search patern, the 'ignorecase' option will be override.
-- set this to use id-utils for global search
o.grepprg='lid -Rgrep -s'
o.grepformat='%f:%l:%m'
-- window op
o.listchars='tab:› ,trail:•,extends:↷,precedes:↶,nbsp:.' -- Highlight problematic whitespace
o.errorbells = false
o.visualbell = true
o.t_vb=""
o.fillchars='vert:│,fold:·'
cmd('set nrformats-=octal')
o.splitbelow = true
-- clipboard
if 1 == fn.has('clipboard') then
if 1 == fn.has('unnamedplus') then --When possible use + register for copy-paste
o.clipboard='unnamedplus,unnamed'
else -- On mac and Windows, use * register for copy-paste
o.clipboard='unnamed'
end
end
-- enable true color
o.termguicolors = true -- set term gui colors most terminals support this
local function defineGroup(group_name,definition)
vim.cmd('augroup ' .. group_name)
vim.cmd('autocmd!')
for _, def in pairs(definition) do
local command = table.concat(vim.tbl_flatten {'autocmd', def}, ' ')
vim.cmd(command)
end
vim.cmd('augroup END')
end
-- autocmd
local function defineGroupAll(definitions) -- {{{1
-- Create autocommand groups based on the passed definitions
--
-- The key will be the name of the group, and each definition
-- within the group should have:
-- 1. Trigger
-- 2. Pattern
-- 3. Text
-- just like how they would normally be defined from Vim itself
for group_name, definition in pairs(definitions) do
defineGroup(group_name,definition)
end
end
local Ex = {
{'BufNewFile,BufEnter', '*', 'set cpoptions+=d'}, -- NOTE: ctags find the tags file from the current path instead of the path of currect file
-- when editing a file, always jump to the last known cursor position.
-- don't do it when the position is invalid or when inside an event handler
-- (happens when dropping a file on gvim).
{'BufReadPost', '*', [[if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g`\"" | endif]]},
{'FileType','text','setlocal textwidth=80'},--for all text files set 'textwidth' to 78 characters.
{'FileType','c,cpp,cs,swig','set nomodeline'},-- this will avoid bug in my project with namespace ex, the vim will tree ex:: as modeline.
-- disable auto-comment for c/cpp, lua, javascript, c# and vim-script
{'FileType','c,cpp,java,javascript','set comments=sO:* -,mO:* ,exO:*/,s1:/*,mb:*,ex:*/,f://'},
{'FileType','vim set','comments=sO:" -,mO:" ,eO:"",f:"'},
}
if 1 == fn.has("gui_vimr") then
table.insert(Ex,{'FocusGained', '*', 'checktime'})
end
defineGroupAll({
CursorLine = {
{'VimEnter,WinEnter,BufWinEnter', '*', 'setlocal cursorline'},
{'WinLeave', '*', 'setlocal nocursorline'},
},
Ex = Ex,
})
-- Key Mappings
--
local api = vim.api
local keymap = api.nvim_set_keymap
local noremap_cfg = {noremap = true}
local noremap_silent = {noremap = true,silent = true}
local function map(key,mapcmd,mode,opt)
keymap(mode or "",key,mapcmd or "", opt or empty)
end
-- Don't use Ex mode, use Q for formatting
-- map Q gq
map('Q')
map(';',':','n',noremap_cfg)
map(';',':','v',noremap_cfg)
-- Swap implementations of ` and ' jump to markers
map("'",'`','n',noremap_cfg)
map("`","'",'n',noremap_cfg)
-- copy folder path to clipboard, foo/bar/foobar.c => foo/bar/
map("<leader>y1",[[:let @*=fnamemodify(bufname('%'),":p:h")<CR>]],'n',noremap_silent)
-- copy file name to clipboard, foo/bar/foobar.c => foobar.c
map("<leader>y2",[[:let @*=fnamemodify(bufname('%'),":p:t")<CR>]],'n',noremap_silent)
-- copy full path to clipboard, foo/bar/foobar.c => foo/bar/foobar.c
map("<leader>y3",[[:let @*=fnamemodify(bufname('%'),":p")<CR>]],'n',noremap_silent)
-- When pressing <leader>cd switch to the directory of the open buffer
map('<Leader>cd',":cd %:p:h<CR>:pwd<CR>")
-- Select blocks after indenting
map('<','<gv','x',noremap_cfg)
map('>','>gv|','x',noremap_cfg)
map('>','>>_','n',noremap_cfg)
map('<','<<_','n',noremap_cfg)
-- enhance '<' '>' , do not need to reselect the block after shift it.
map('>','>gv','v',noremap_cfg)
map('<','<gv','v',noremap_cfg)
--Use tab for indenting in visual mode
map('<Tab>','>gv|','x',noremap_cfg)
map('<S-Tab>','<gv','x',noremap_cfg)
-- " Improve scroll, credits: https://github.com/Shougo
vim.cmd([[
nnoremap <expr> zz (winline() == (winheight(0)+1) / 2) ? 'zt' : (winline() == &scrolloff + 1) ? 'zb' : 'zz'
noremap <expr> <C-f> max([winheight(0) - 2, 1]) ."\<C-d>".(line('w$') >= line('$') ? "L" : "H")
noremap <expr> <C-b> max([winheight(0) - 2, 1]) ."\<C-u>".(line('w0') <= 1 ? "H" : "L")
noremap <expr> <C-e> (line("w$") >= line('$') ? "j" : "4\<C-e>")
noremap <expr> <C-y> (line("w0") <= 1 ? "k" : "4\<C-y>")
]])
map('<Space>','<C-e>','n')
map('<S-Space>','<C-y>','n')
map('Y','y$','n',noremap_cfg)
map('<F2>',':set wrap!<BAR>set wrap?<CR>')
map('<F4>',':set relativenumber!<BAR>set relativenumber?<CR>')
map('<F11>',':set cursorline!<BAR>set nocursorline?<CR>')
map('<F12>',':set cursorcolumn!<BAR>set nocursorcolumn?<CR>')
-- register /
vim.cmd([[
function! MakePattern(text)
let pat = escape(a:text, '\')
let pat = substitute(pat, '\_s\+$', '\\s\\*', '')
let pat = substitute(pat, '^\_s\+', '\\s\\*', '')
let pat = substitute(pat, '\_s\+', '\\_s\\+', 'g')
return '\\V' . escape(pat, '\"')
endfunction
vnoremap <silent> <F3> :<C-U>let @/="<C-R>=MakePattern(@*)<CR>"<CR>:set hls<CR>
nnoremap <F3> :let @/='\<\C<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>
function! Del_word_delims()
let reg = getreg('/')
" After * i^r/ will give me pattern instead of \<pattern\>
let res = substitute(reg, '^\\<\(.*\)\\>$', '\1', '' )
if res != reg
return res
endif
" After * on a selection i^r/ will give me pattern instead of \Vpattern
let res = substitute(reg, '^\\V' , '' , '' )
let res = substitute(res, '\\\\' , '\\', 'g')
let res = substitute(res, '\\n' , '\n', 'g')
return res
endfunction
inoremap <silent> <C-R>/ <C-R>=Del_word_delims()<CR>
cnoremap <C-R>/ <C-R>=Del_word_delims()<CR>
]])
-- edit vimrc
vim.cmd([[
function! ExpandFilenameAndExecute(command, file)
execute a:command . " " . expand(a:file, ":p")
endfunction
function! EditVimrc13Config()
call ExpandFilenameAndExecute("tabedit", "$HOME/.vim-self/.vimrc")
execute bufwinnr(".vimrc") . "wincmd w"
endfunction
noremap <Leader>ev :call EditVimrc13Config()<CR>
]])
-- Strip whitespace
vim.cmd([[
function! StripTrailingWhitespace()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" do the business:
%s/\s\+$//e
" clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
nnoremap <leader>ws :call StripTrailingWhitespace()<CR>
]])
-- searching
-- Visual mode pressing
vim.cmd([[
function! VisualSelection() range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", "\\/.*'$^~[]")
let l:pattern = substitute(l:pattern, "\n$", "", "")
let @/ = l:pattern
let @" = l:saved_reg
endfunction
vnoremap <silent> * :<C-u>call VisualSelection()<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> <leader>n :<C-u>call VisualSelection()<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> <leader>h :<C-u>call VisualSelection()<CR>:set hls<CR>
vnoremap <silent> # :<C-u>call VisualSelection()<CR>?<C-R>=@/<CR><CR>
vnoremap <silent> <leader>N :<C-u>call VisualSelection()<CR>?<C-R>=@/<CR><CR>
]])
map('<leader>h',[[:let @/='\<\C<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>]],'n',noremap_cfg)
map('<leader>n','*','n')
map('<leader>N','#','n')
map('<F8>',':let @/=""<CR>','n',noremap_cfg)
map('<leader>/',':let @/=""<CR>','n',noremap_cfg)
-- Navigation in command line
map('<C-a>','<Home>','c',noremap_cfg)
map('<C-b>','<Left>','c',noremap_cfg)
map('<C-f>','<Right>','c',noremap_cfg)
map('w!!','%!sudo tee > /dev/null %','c',noremap_cfg)
-- Fast saving
map('<C-s>',':<C-u>w<CR>','n',noremap_cfg)
map('<C-s>',':<C-u>w<CR>','v',noremap_cfg)
map('<C-s>','<C-u>w<CR>','c',noremap_cfg)
-- Visually select the text that was last edited/pasted
map('gV','`[v`]','',noremap_cfg)
--fold
map('<leader>f0',':set foldlevel=0<CR>','',noremap_cfg)
for i =1,9 do
map('<leader>t' .. i, i .. 'gt','n',noremap_cfg)
map('<leader>' .. i, i .. '<C-W>W','n',noremap_cfg)
map('<leader>f' .. i, ':set foldlevel=' .. i .. '<CR>','',noremap_cfg)
end
map('<leader>if',[[:exec 'normal ,hciw' . expand('%:t:r:r:r') . "\e"<CR>]],'n',noremap_cfg)
map('<leader>ip',':normal "_cib*','n',noremap_cfg)
--Terminal
vim.cmd([[
exe 'tnoremap <silent><C-Right> <C-\><C-n>:<C-u>wincmd l<CR>'
exe 'tnoremap <silent><C-Left> <C-\><C-n>:<C-u>wincmd h<CR>'
exe 'tnoremap <silent><C-Up> <C-\><C-n>:<C-u>wincmd k<CR>'
exe 'tnoremap <silent><C-Down> <C-\><C-n>:<C-u>wincmd j<CR>'
exe 'tnoremap <silent><M-Left> <C-\><C-n>:<C-u>bprev<CR>'
exe 'tnoremap <silent><M-Right> <C-\><C-n>:<C-u>bnext<CR>'
exe 'tnoremap <silent><esc> <C-\><C-n>'
]])
--tab navigation
map('<leader>f0',':set foldlevel=0<CR>','n',noremap_cfg)
map('<leader>tj',':tabfirst<CR>','n',noremap_cfg)
map('<leader>th',':tabnext<CR>','n',noremap_cfg)
map('<leader>tl',':tabprev<CR>','n',noremap_cfg)
map('<leader>tk',':tablast<CR>','n',noremap_cfg)
map('<leader>tn',':tabnew<CR>','n',noremap_cfg)
map('<leader>tc',':tabclose<CR>','n',noremap_cfg)
map('<leader>tm',':tabm<Space>','n',noremap_cfg)
map('<leader>td',':tabclose<CR>','n',noremap_cfg)
map('<leader>to',':tabonly<CR>','n',noremap_cfg)
map('H','gT','n',noremap_cfg)
map('L','gt','n',noremap_cfg)
g.Lasttab = 1
g.Lasttab_backup = 1
defineGroup("TabNam",{
{'TabLeave', '*', 'let g:Lasttab_backup = g:Lasttab | let g:Lasttab = tabpagenr()'},
{'TabClosed', '*', 'let g:Lasttab = g:Lasttab_backup'},
})
map('<Leader>tp',':exe "tabn " . g:Lasttab<cr>','n',noremap_silent)
cmd([[cabbr <expr> %% expand('%:p:h')]])
--plugins
--treesitter
require'nvim-treesitter.configs'.setup {
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
ignore_install = { "javascript" }, -- List of parsers to ignore installing
highlight = {
enable = true, -- false will disable the whole extension
disable = {}, -- list of language that will be disabled
},
textobjects = {
select = {
enable = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
-- Or you can define your own textobjects like this
["iF"] = {
python = "(function_definition) @function",
cpp = "(function_definition) @function",
c = "(function_definition) @function",
java = "(method_declaration) @function",
},
},
},
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "gnn",
node_incremental = "grn",
scope_incremental = "grc",
node_decremental = "grm",
},
},
matchup = {
enable = true, -- mandatory, false will disable the whole extension
-- disable = { "c", "ruby" }, -- optional, list of language that will be disabled
},
indent = {
enable = true
},
playground = {
enable = true,
disable = {},
updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code
persist_queries = false, -- Whether the query persists across vim sessions
keybindings = {
toggle_query_editor = 'o',
toggle_hl_groups = 'i',
toggle_injected_languages = 't',
toggle_anonymous_nodes = 'a',
toggle_language_display = 'I',
focus_language = 'f',
unfocus_language = 'F',
update = 'R',
goto_node = '<cr>',
show_help = '?',
},
},
}
--telescope
local actions = require('telescope.actions')
local trouble = require("trouble.providers.telescope")
-- Global remapping
------------------------------
-- '--color=never',
require('telescope').setup {
defaults = {
find_command = {'rg', '--no-heading', '--with-filename', '--line-number', '--column', '--smart-case'},
prompt_position = "bottom",
-- prompt_prefix = " ",
prompt_prefix = " ",
selection_caret = " ",
entry_prefix = " ",
initial_mode = "insert",
-- initial_mode = "insert",
selection_strategy = "reset",
sorting_strategy = "descending",
layout_strategy = "horizontal",
layout_defaults = {horizontal = {mirror = false}, vertical = {mirror = false}},
file_sorter = require'telescope.sorters'.get_fzy_sorter,
file_ignore_patterns = {},
generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter,
shorten_path = true,
winblend = 0,
width = 0.75,
preview_cutoff = 120,
results_height = 1,
results_width = 0.8,
border = {},
borderchars = {'─', '│', '─', '│', '╭', '╮', '╯', '╰'},
color_devicons = true,
use_less = true,
set_env = {['COLORTERM'] = 'truecolor'}, -- default = nil,
file_previewer = require'telescope.previewers'.vim_buffer_cat.new,
grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new,
qflist_previewer = require'telescope.previewers'.vim_buffer_qflist.new,
-- Developer configurations: Not meant for general override
buffer_previewer_maker = require'telescope.previewers'.buffer_previewer_maker,
mappings = {
i = {
["<C-c>"] = actions.close,
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
["<c-t>"] = trouble.open_with_trouble,
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
-- To disable a keymap, put [map] = false
-- So, to not map "<C-n>", just put
-- ["<c-x>"] = false,
-- ["<esc>"] = actions.close,
-- Otherwise, just set the mapping to the function that you want it to be.
-- ["<C-i>"] = actions.select_horizontal,
-- Add up multiple actions
["<CR>"] = actions.select_default + actions.center
-- You can perform as many actions in a row as you like
-- ["<CR>"] = actions.select_default + actions.center + my_cool_custom_action,
},
n = {
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
["<c-t>"] = trouble.open_with_trouble,
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist
-- ["<C-i>"] = my_cool_custom_action,
}
}
},
extensions = {
fzy_native = {
override_generic_sorter = false,
override_file_sorter = true
},
media_files = {
-- filetypes whitelist
-- defaults to {"png", "jpg", "mp4", "webm", "pdf"}
filetypes = {"png", "webp", "jpg", "jpeg"},
find_cmd = "rg" -- find command (defaults to `fd`)
},
}
}
require'telescope'.load_extension('project')
if isLinux() then
require'telescope'.load_extension('media_files')
end
-- Find files using Telescope command-line sugar.
map('<C-P>',':Telescope find_files<cr>','n',noremap_cfg)
map('<leader>ff',':Telescope find_files<cr>','n',noremap_cfg)
map('<leader>fg',':Telescope live_grep<cr>','n',noremap_cfg)
map('<leader>fb',':Telescope buffers<cr>','n',noremap_cfg)
map('<leader>fh',':Telescope help_tags<cr>','n',noremap_cfg)