-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
1026 lines (878 loc) · 27.3 KB
/
init.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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Install packer
local install_path = vim.fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim'
local is_bootstrap = false
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
is_bootstrap = true
vim.fn.system { 'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path }
vim.cmd [[packadd packer.nvim]]
end
-- =================================================
-- ==================Package manager================
-- =================================================
require('packer').startup(function(use)
-- Package manager
use 'wbthomason/packer.nvim'
use {
'svrana/neosolarized.nvim',
requires = { 'tjdevries/colorbuddy.nvim' }
}
-- Statusline
use 'nvim-lualine/lualine.nvim'
-- Common utilities
use 'nvim-lua/plenary.nvim'
-- vscode-like pictograms
use 'onsails/lspkind-nvim'
-- nvim-cmp source for buffer words
use 'hrsh7th/cmp-buffer'
-- nvim-cmp source for neovim's built-in LSP
use 'hrsh7th/cmp-nvim-lsp'
-- Completion
use 'hrsh7th/nvim-cmp'
-- Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua
use 'jose-elias-alvarez/null-ls.nvim'
use {
"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"neovim/nvim-lspconfig",
}
-- LSP UIs
use "glepnir/lspsaga.nvim"
use 'L3MON4D3/LuaSnip'
-- Highlight, edit, and navigate code
use {
'nvim-treesitter/nvim-treesitter',
dependencies = {
'nvim-treesitter/nvim-treesitter-textobjects',
},
config = function()
pcall(require('nvim-treesitter.install').update { with_sync = true })
end,
}
-- File icons
use 'kyazdani42/nvim-web-devicons'
use 'nvim-telescope/telescope.nvim'
use 'nvim-telescope/telescope-file-browser.nvim'
use 'windwp/nvim-autopairs'
use 'windwp/nvim-ts-autotag'
use { 'numToStr/Comment.nvim',
requires = {
'JoosepAlviste/nvim-ts-context-commentstring'
}
}
use 'norcalli/nvim-colorizer.lua'
use 'folke/zen-mode.nvim'
use({
"iamcco/markdown-preview.nvim",
run = function() vim.fn["mkdp#util#install"]() end,
})
use 'akinsho/nvim-bufferline.lua'
use 'lewis6991/gitsigns.nvim'
-- For git blame & browse
use 'dinhhuy258/git.nvim'
-- tmux & split window navigation
use("christoomey/vim-tmux-navigator")
use('mbbill/undotree')
-- Add custom plugins to packer from ~/.config/nvim/lua/custom/plugins.lua
local has_plugins, plugins = pcall(require, 'custom.plugins')
if has_plugins then
plugins(use)
end
if is_bootstrap then
require('packer').sync()
end
end)
-- ==============================================
-- ==================Bootstrap===================
-- ==============================================
-- When we are bootstrapping a configuration, it doesn't
-- make sense to execute the rest of the init.lua.
-- You'll need to restart nvim, and then it will work.
if is_bootstrap then
print '=================================='
print ' Plugins are being installed'
print ' Wait until Packer completes,'
print ' then restart nvim'
print '=================================='
return
end
-- Automatically source and re-compile packer whenever you save this init.lua
local packer_group = vim.api.nvim_create_augroup('Packer', { clear = true })
vim.api.nvim_create_autocmd('BufWritePost', {
command = 'source <afile> | silent! LspStop | silent! LspStart | PackerCompile',
group = packer_group,
pattern = vim.fn.expand '$MYVIMRC',
})
-- =================================================
-- ======================base=======================
-- =================================================
vim.cmd("autocmd!")
vim.scriptencoding = 'utf-8'
vim.opt.encoding = 'utf-8'
vim.opt.fileencoding = 'utf-8'
vim.wo.number = true
vim.opt.title = true
vim.opt.autoindent = true
vim.opt.smartindent = true
vim.opt.hlsearch = true
vim.opt.backup = false
vim.opt.showcmd = true
vim.opt.cmdheight = 1
vim.opt.laststatus = 2
vim.opt.expandtab = true
vim.opt.scrolloff = 10
vim.opt.shell = 'fish'
vim.opt.backupskip = { '/tmp/*', '/private/tmp/*' }
vim.opt.inccommand = 'split'
-- Case insensitive searching UNLESS /C or capital in search
vim.opt.ignorecase = true
vim.opt.smarttab = true
vim.opt.breakindent = true
vim.opt.shiftwidth = 2
vim.opt.tabstop = 2
-- No Wrap lines
vim.opt.wrap = false
vim.opt.backspace = { 'start', 'eol', 'indent' }
-- Finding files - Search down into subfolders
vim.opt.path:append { '**' }
vim.opt.wildignore:append { '*/node_modules/*' }
-- Undercurl
vim.cmd([[let &t_Cs = "\e[4:3m"]])
vim.cmd([[let &t_Ce = "\e[4:0m"]])
-- Turn off paste mode when leaving insert
vim.api.nvim_create_autocmd("InsertLeave", {
pattern = '*',
command = "set nopaste"
})
-- Add asterisks in block comments
vim.opt.formatoptions:append { 'r' }
-- =================================================
-- =================highlights======================
-- =================================================
vim.opt.cursorline = true
vim.opt.termguicolors = true
vim.opt.winblend = 0
vim.opt.wildoptions = 'pum'
vim.opt.pumblend = 2
vim.opt.background = 'dark'
-- highlight yanked text for 200ms using the "Visual" highlight group
vim.cmd [[
augroup highlight_yank
autocmd!
au TextYankPost * silent! lua vim.highlight.on_yank({higroup="Visual", timeout=100})
augroup END
]]
-- =================================================
-- ===================keymaps=======================
-- =================================================
vim.g.mapleader = " "
local keymap = vim.keymap
keymap.set("i", "jj", "<ESC>")
keymap.set('n', 'x', '"_x')
-- cursor in the middle
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
vim.keymap.set("n", "n", "nzzzv")
vim.keymap.set("n", "N", "Nzzzv")
vim.keymap.set("n", "Q", "<nop>")
-- yank to parse
vim.keymap.set("x", "<leader>p", [["_dP]])
-- replace all file word
vim.keymap.set("n", "<leader>s", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])
-- clear search highlights
keymap.set("n", "<leader>nh", ":nohl<CR>")
-- Increment/decrement
keymap.set('n', '+', '<C-a>')
keymap.set('n', '-', '<C-x>')
-- Delete a word backwards
keymap.set('n', 'dw', 'vb"_d')
-- Select all
keymap.set('n', '<C-a>', 'gg<S-v>G')
-- New tab
keymap.set('n', 'te', ':tabedit<Return>')
-- Split window
keymap.set('n', '<leader>ss', ':split<Return><C-w>w')
keymap.set('n', '<leader>sv', ':vsplit<Return><C-w>w')
-- Move window
keymap.set('n', '<Space>', '<C-w>w')
keymap.set('', '<leader>sh', '<C-w>h')
keymap.set('', '<leader>sk', '<C-w>k')
keymap.set('', '<leader>sj', '<C-w>j')
keymap.set('', '<leader>sl', '<C-w>l')
-- Resize window
keymap.set('n', '<C-w><left>', '<C-w><')
keymap.set('n', '<C-w><right>', '<C-w>>')
keymap.set('n', '<C-w><up>', '<C-w>+')
keymap.set('n', '<C-w><down>', '<C-w>-')
-- *************************************************
-- **************neosolarized config****************
-- *************************************************
local n = require('neosolarized')
n.setup({
comment_italics = true,
})
local cb = require('colorbuddy.init')
local Color = cb.Color
local colors = cb.colors
local Group = cb.Group
local groups = cb.groups
local styles = cb.styles
Color.new('white', '#ffffff')
Color.new('black', '#000000')
Group.new('Normal', colors.base1, colors.NONE, styles.NONE)
Group.new('CursorLine', colors.none, colors.base03, styles.NONE, colors.base1)
Group.new('CursorLineNr', colors.yellow, colors.black, styles.NONE, colors.base1)
Group.new('Visual', colors.none, colors.base03, styles.reverse)
local cError = groups.Error.fg
local cInfo = groups.Information.fg
local cWarn = groups.Warning.fg
local cHint = groups.Hint.fg
Group.new("DiagnosticVirtualTextError", cError, cError:dark():dark():dark():dark(), styles.NONE)
Group.new("DiagnosticVirtualTextInfo", cInfo, cInfo:dark():dark():dark(), styles.NONE)
Group.new("DiagnosticVirtualTextWarn", cWarn, cWarn:dark():dark():dark(), styles.NONE)
Group.new("DiagnosticVirtualTextHint", cHint, cHint:dark():dark():dark(), styles.NONE)
Group.new("DiagnosticUnderlineError", colors.none, colors.none, styles.undercurl, cError)
Group.new("DiagnosticUnderlineWarn", colors.none, colors.none, styles.undercurl, cWarn)
Group.new("DiagnosticUnderlineInfo", colors.none, colors.none, styles.undercurl, cInfo)
Group.new("DiagnosticUnderlineHint", colors.none, colors.none, styles.undercurl, cHint)
Group.new("HoverBorder", colors.yellow, colors.none, styles.NONE)
-- *************************************************
-- *****************lualine config******************
-- *************************************************
local lualine = require('lualine')
lualine.setup {
options = {
icons_enabled = true,
theme = 'solarized_dark',
section_separators = { left = '', right = '' },
component_separators = { left = '', right = '' },
disabled_filetypes = {}
},
sections = {
lualine_a = { 'mode' },
lualine_b = { 'branch' },
lualine_c = { {
'filename',
file_status = true, -- displays file status (readonly status, modified status)
path = 0 -- 0 = just filename, 1 = relative path, 2 = absolute path
} },
lualine_x = {
{
'diagnostics',
sources = { "nvim_diagnostic" },
symbols = {
error = ' ',
warn = ' ',
info = ' ',
hint = ' '
}
},
'encoding',
'filetype'
},
lualine_y = { 'progress' },
lualine_z = { 'location' }
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = { {
'filename',
file_status = true, -- displays file status (readonly status, modified status)
path = 1 -- 0 = just filename, 1 = relative path, 2 = absolute path
} },
lualine_x = { 'location' },
lualine_y = {},
lualine_z = {}
},
tabline = {},
extensions = { 'fugitive' }
}
-- *************************************************
-- *****************Mason config********************
-- *************************************************
local mason = require('mason')
local lspconfig = require('mason-lspconfig')
mason.setup({})
lspconfig.setup {
automatic_installation = true
}
-- *************************************************
-- ***************lspconfig config******************
-- *************************************************
local nvim_lsp = require('lspconfig')
local protocol = require('vim.lsp.protocol')
local augroup_format = vim.api.nvim_create_augroup("Format", { clear = true })
local enable_format_on_save = function(_, bufnr)
vim.api.nvim_clear_autocmds({ group = augroup_format, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup_format,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr })
end,
})
end
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client)
client.server_capabilities.hoverProvider = false
end
protocol.CompletionItemKind = {
'', -- Text
'', -- Method
'', -- Function
'', -- Constructor
'', -- Field
'', -- Variable
'', -- Class
'ﰮ', -- Interface
'', -- Module
'', -- Property
'', -- Unit
'', -- Value
'', -- Enum
'', -- Keyword
'', -- Snippet
'', -- Color
'', -- File
'', -- Reference
'', -- Folder
'', -- EnumMember
'', -- Constant
'', -- Struct
'', -- Event
'ﬦ', -- Operator
'', -- TypeParameter
}
-- Set up completion using nvim_cmp with LSP source
local capabilities = require('cmp_nvim_lsp').default_capabilities()
nvim_lsp.flow.setup {
on_attach = on_attach,
capabilities = capabilities
}
nvim_lsp.tsserver.setup {
on_attach = on_attach,
capabilities = capabilities
}
nvim_lsp.sourcekit.setup {
on_attach = on_attach,
capabilities = capabilities,
}
nvim_lsp.lua_ls.setup {
capabilities = capabilities,
on_attach = function(client, bufnr)
on_attach(client, bufnr)
enable_format_on_save(client, bufnr)
end,
settings = {
Lua = {
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = { 'vim' },
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
checkThirdParty = false
},
},
},
}
nvim_lsp.tailwindcss.setup {
on_attach = on_attach,
capabilities = capabilities
}
nvim_lsp.cssls.setup {
on_attach = on_attach,
capabilities = capabilities
}
nvim_lsp.gopls.setup {
on_attach = on_attach,
capabilities = capabilities
}
nvim_lsp.prismals.setup {
on_attach = on_attach,
capabilities = capabilities
}
-- Enable this for vue3 projects
nvim_lsp.volar.setup {
cmd = { "vue-language-server", "--stdio" },
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue', 'json' },
init_options = {
typescript = {
tsdk = '/path/to/.npm/lib/node_modules/typescript/lib'
}
}
}
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
underline = true,
update_in_insert = false,
virtual_text = { spacing = 4, prefix = "●" },
severity_sort = true,
}
)
-- Diagnostic symbols in the sign column (gutter)
local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " }
for type, icon in pairs(signs) do
local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" })
end
vim.diagnostic.config({
virtual_text = {
prefix = '●'
},
update_in_insert = true,
float = {
-- Or "if_many"
source = "always",
},
})
-- *************************************************
-- ***************null-ls config********************
-- *************************************************
local null_ls = require('null-ls')
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
local lsp_formatting = function(bufnr)
vim.lsp.buf.format({
filter = function(client)
return client.name == "null-ls"
end,
bufnr = bufnr,
})
end
null_ls.setup {
sources = {
null_ls.builtins.formatting.prettierd,
null_ls.builtins.diagnostics.fish,
},
on_attach = function(client, bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
lsp_formatting(bufnr)
end,
})
end
end
}
vim.api.nvim_create_user_command(
'DisableLspFormatting',
function()
vim.api.nvim_clear_autocmds({ group = augroup, buffer = 0 })
end,
{ nargs = 0 }
)
-- *************************************************
-- ***************lspkind config********************
-- *************************************************
local lspkind = require('lspkind')
lspkind.init({
-- enables text annotations
--
-- default: true
mode = 'symbol',
-- default symbol map
-- can be either 'default' (requires nerd-fonts font) or
-- 'codicons' for codicon preset (requires vscode-codicons font)
--
-- default: 'default'
preset = 'codicons',
-- override preset symbols
--
-- default: {}
symbol_map = {
Text = "",
Method = "",
Function = "",
Constructor = "",
Field = "ﰠ",
Variable = "",
Class = "ﴯ",
Interface = "",
Module = "",
Property = "ﰠ",
Unit = "塞",
Value = "",
Enum = "",
Keyword = "",
Snippet = "",
Color = "",
File = "",
Reference = "",
Folder = "",
EnumMember = "",
Constant = "",
Struct = "פּ",
Event = "",
Operator = "",
TypeParameter = ""
},
})
-- *************************************************
-- ******************cmp config*********************
-- *************************************************
local cmp = require('cmp')
local function formatForTailwindCSS(entry, vim_item)
if vim_item.kind == 'Color' and entry.completion_item.documentation then
local _, _, r, g, b = string.find(entry.completion_item.documentation, '^rgb%((%d+), (%d+), (%d+)')
if r then
local color = string.format('%02x', r) .. string.format('%02x', g) .. string.format('%02x', b)
local group = 'Tw_' .. color
if vim.fn.hlID(group) < 1 then
vim.api.nvim_set_hl(0, group, { fg = '#' .. color })
end
vim_item.kind = "●"
vim_item.kind_hl_group = group
return vim_item
end
end
vim_item.kind = lspkind.symbolic(vim_item.kind) and lspkind.symbolic(vim_item.kind) or vim_item.kind
return vim_item
end
cmp.setup({
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
-- ['<C-d>'] = cmp.mapping.scroll_docs(-4),
-- ['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true
}),
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'buffer' },
}),
formatting = {
format = lspkind.cmp_format({
maxwidth = 50,
before = function(entry, vim_item)
vim_item = formatForTailwindCSS(entry, vim_item)
return vim_item
end
})
}
})
vim.cmd [[
set completeopt=menuone,noinsert,noselect
highlight! default link CmpItemKind CmpItemMenuDefault
]]
-- *************************************************
-- ****************lspsaga config*******************
-- *************************************************
local saga = require('lspsaga')
saga.setup({
ui = {
-- This option only works in Neovim 0.9
title = false,
-- Border type can be single, double, rounded, solid, shadow.
border = "rounded",
},
})
local opts = { noremap = true, silent = true }
-- Diagnsotic jump can use `<c-o>` to jump back
vim.keymap.set('n', '<Leader><C-j>', '<Cmd>Lspsaga diagnostic_jump_next<CR>', opts)
vim.keymap.set("n", "K", "<cmd>Lspsaga hover_doc<CR>")
vim.keymap.set('n', 'gh', '<cmd>Lspsaga lsp_finder<CR>', opts)
vim.keymap.set("n", "gd", "<cmd>Lspsaga goto_definition<CR>", opts)
vim.keymap.set('n', 'gp', '<cmd>Lspsaga peek_definition<CR>', opts)
vim.keymap.set('n', 'gr', '<cmd>Lspsaga rename<CR>', opts)
vim.cmd('highlight! FinderBorder guifg=yellow guibg=none')
vim.cmd('highlight! FinderPreviewBorder guifg=yellow guibg=none')
vim.cmd('highlight! DefinitionBorder guifg=yellow guibg=none')
vim.cmd('highlight! RenameBorder guifg=yellow guibg=none')
-- DiagnosticBorder
-- code action
local codeaction = require("lspsaga.codeaction")
vim.keymap.set("n", "<leader>ca", function() codeaction:code_action() end, { silent = true })
vim.keymap.set("v", "<leader>ca", function()
vim.fn.feedkeys(vim.api.nvim_replace_termcodes("<C-U>", true, false, true))
codeaction:range_code_action()
end, { silent = true })
-- *************************************************
-- ************nvim-treesitter config***************
-- *************************************************
-- See `:help nvim-treesitter`
require('nvim-treesitter.configs').setup {
-- Add languages to be installed here that you want installed for treesitter
ensure_installed = {
'lua', 'css', 'html', 'typescript', 'tsx', 'javascript', 'vue', 'astro', 'vim', 'markdown',
'markdown_inline', 'prisma'
},
highlight = { enable = true },
indent = { enable = true, disable = { 'python' } },
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<c-space>',
node_incremental = '<c-space>',
scope_incremental = '<c-s>',
node_decremental = '<c-backspace>',
},
},
textobjects = {
select = {
enable = true,
-- Automatically jump forward to textobj, similar to targets.vim
lookahead = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
move = {
enable = true,
-- whether to set jumps in the jumplist
set_jumps = true,
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
swap = {
enable = true,
swap_next = {
['<leader>a'] = '@parameter.inner',
},
swap_previous = {
['<leader>A'] = '@parameter.inner',
},
},
},
}
-- *************************************************
-- **********nvim-web-devicons config***************
-- *************************************************
local icons = require('nvim-web-devicons')
icons.setup {
-- your personnal icons can go here (to override)
-- DevIcon will be appended to `name`
override = {
},
-- globally enable default icons (default to false)
-- will get overriden by `get_icons` option
default = true
}
-- *************************************************
-- ****************telescope config*****************
-- *************************************************
local telescope = require('telescope')
local actions = require('telescope.actions')
local builtin = require("telescope.builtin")
local function telescope_buffer_dir()
return vim.fn.expand('%:p:h')
end
local fb_actions = require "telescope".extensions.file_browser.actions
telescope.setup {
defaults = {
mappings = {
n = {
["q"] = actions.close
},
},
},
extensions = {
file_browser = {
theme = "dropdown",
-- disables netrw and use telescope-file-browser in its place
hijack_netrw = true,
mappings = {
-- your custom insert mode mappings
["i"] = {
["<C-w>"] = function() vim.cmd('normal vbd') end,
},
["n"] = {
-- your custom normal mode mappings
["N"] = fb_actions.create,
["h"] = fb_actions.goto_parent_dir,
["/"] = function()
vim.cmd('startinsert')
end
},
},
},
},
}
telescope.load_extension("file_browser")
vim.keymap.set('n', '<Leader>f',
function()
builtin.find_files({
no_ignore = false,
hidden = true
})
end)
vim.keymap.set('n', '<Leader>r', function()
builtin.live_grep()
end)
vim.keymap.set('n', '\\\\', function()
builtin.buffers()
end)
vim.keymap.set('n', '<Leader>t', function()
builtin.help_tags()
end)
vim.keymap.set('n', '<Leader><Leader>', function()
builtin.resume()
end)
vim.keymap.set('n', ';e', function()
builtin.diagnostics()
end)
vim.keymap.set("n", "sf", function()
telescope.extensions.file_browser.file_browser({
path = "%:p:h",
cwd = telescope_buffer_dir(),
respect_gitignore = false,
hidden = true,
grouped = true,
previewer = false,
initial_mode = "normal",
layout_config = { height = 40 }
})
end)
vim.keymap.set('n', '<Leader>?', builtin.oldfiles, { desc = '[?] Find recently opened files' })
-- *************************************************
-- ****************autopairs config*****************
-- *************************************************
local autopairs = require('nvim-autopairs')
autopairs.setup({
disable_filetype = { "TelescopePrompt", "vim" },
})
-- *************************************************
-- ****************ts-autotag config****************
-- *************************************************
local autotag = require('nvim-ts-autotag')
autotag.setup({})
-- *************************************************
-- ****************Comment config*******************
-- *************************************************
local comment = require('Comment')
comment.setup {
pre_hook = function(ctx)
-- Only calculate commentstring for tsx filetypes
if vim.bo.filetype == 'typescriptreact' then
local U = require('Comment.utils')
-- Determine whether to use linewise or blockwise commentstring
local type = ctx.ctype == U.ctype.linewise and '__default' or '__multiline'
-- Determine the location where to calculate commentstring from
local location = nil
if ctx.ctype == U.ctype.blockwise then
location = require('ts_context_commentstring.utils').get_cursor_location()
elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then
location = require('ts_context_commentstring.utils').get_visual_start_location()
end
return require('ts_context_commentstring.internal').calculate_commentstring({
key = type,
location = location,
})
end
end,
}
-- *************************************************
-- ****************colorizer config*****************
-- *************************************************
local colorizer = require('colorizer')
colorizer.setup({
'*',
})
-- *************************************************
-- ****************zen-mode config******************
-- *************************************************
local zenMode = require('zen-mode')
zenMode.setup {}
vim.keymap.set('n', '<leader>zz', '<cmd>ZenMode<cr>', { silent = true })
-- *************************************************
-- ****************bufferline config****************
-- *************************************************
local bufferline = require('bufferline')
bufferline.setup({
options = {
mode = "tabs",
separator_style = 'slant',
always_show_bufferline = false,
show_buffer_close_icons = false,
show_close_icon = false,
color_icons = true
},
highlights = {
separator = {
fg = '#073642',
bg = '#002b36',
},
separator_selected = {
fg = '#073642',
},
background = {
fg = '#657b83',
bg = '#002b36'
},
buffer_selected = {
fg = '#fdf6e3',
bold = true,
},
fill = {
bg = '#073642'
}
},
})
vim.keymap.set('n', '<Tab>', '<Cmd>BufferLineCycleNext<CR>', {})
vim.keymap.set('n', '<S-Tab>', '<Cmd>BufferLineCyclePrev<CR>', {})
-- *************************************************
-- ****************undotree config******************
-- *************************************************
vim.keymap.set("n", "<leader>u", vim.cmd.UndotreeToggle)
-- *************************************************
-- ****************gitsigns config******************
-- *************************************************
local gitsigns = require('gitsigns')
gitsigns.setup {
}
-- *************************************************
-- *******************git config********************
-- *************************************************