-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.lua
172 lines (134 loc) · 4.81 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
if vim.g.vscode then
else
local o = vim.o
local g = vim.g
o.clipboard = "unnamedplus"
o.number = true
vim.opt.numberwidth = 1
o.swapfile = false
require("plugins")
local time = os.date("*t")
if time.hour < 6 or time.hour >= 18 then
vim.cmd([[set background=dark]])
else
vim.cmd([[set background=light]])
end
require("catppuccin").setup({background = {dark = "frappe"}})
vim.cmd.colorscheme "catppuccin"
vim.cmd([[
function! s:build_quickfix_list(lines)
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
copen
cc
endfunction
let g:fzf_action = {
\ 'ctrl-q': function('s:build_quickfix_list'),
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
let $FZF_DEFAULT_OPTS = '--bind ctrl-a:select-all'
function! RipgrepFzf(query, fullscreen)
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case --fixed-strings -- %s || true'
let initial_command = printf(command_fmt, shellescape(a:query))
let reload_command = printf(command_fmt, '{q}')
let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction
command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)
]])
local builtin = require("telescope.builtin")
vim.keymap.set("n", "<leader>ff", builtin.git_files, {})
vim.api.nvim_set_keymap("n", "<Leader><Leader>",
":call ElixirAlternateFile()<CR>",
{noremap = true, silent = true})
vim.cmd([[
let g:test#echo_command = 0
let test#python#runner = 'pytest'
if exists('$TMUX')
let g:test#preserve_screen = 1
let g:test#strategy = 'vimux'
endif
nmap <silent> <leader>t :TestNearest<CR>
nmap <silent> <leader>T :TestFile<CR>
nmap <silent> <leader>a :TestSuite<CR>
nmap <silent> <leader>l :TestLast<CR>
nmap <silent> <leader>g :TestVisit<CR>
]])
g.markdown_fenced_languages = {"python", "elixir", "bash", "dockerfile"}
require("refactoring").setup()
vim.keymap.set("x", "<leader>rv", function()
require('refactoring').refactor('Extract Variable')
end)
vim.keymap.set({"n", "x"}, "<leader>ri", function()
require('refactoring').refactor('Inline Variable')
end)
local lsp = require("lsp-zero")
lsp.on_attach(function(client, bufnr)
lsp.default_keymaps({buffer = bufnr})
end)
require('mason').setup({})
require('mason-lspconfig').setup({
handlers = {
lsp.default_setup,
lua_ls = function()
local lua_opts = lsp.nvim_lua_ls()
require('lspconfig').lua_ls.setup(lua_opts)
end
},
ensure_installed = {
"dockerls", "jsonls", "elixirls", "yamlls", "lua_ls", "ltex",
"clangd"
}
})
lsp.setup()
require"lsp_signature".setup()
require("gitsigns").setup {
on_attach = function(bufnr)
local gs = package.loaded.gitsigns
local function map(mode, l, r, opts)
opts = opts or {}
opts.buffer = bufnr
vim.keymap.set(mode, l, r, opts)
end
-- Navigation
map("n", "]c", function()
if vim.wo.diff then return "]c" end
vim.schedule(function() gs.next_hunk() end)
return "<Ignore>"
end, {expr = true})
map("n", "[c", function()
if vim.wo.diff then return "[c" end
vim.schedule(function() gs.prev_hunk() end)
return "<Ignore>"
end, {expr = true})
-- Actions
map({"n", "v"}, "<leader>hs", ":Gitsigns stage_hunk<CR>")
map({"n", "v"}, "<leader>hr", ":Gitsigns reset_hunk<CR>")
map("n", "<leader>hS", gs.stage_buffer)
map("n", "<leader>hu", gs.undo_stage_hunk)
map("n", "<leader>hR", gs.reset_buffer)
map("n", "<leader>hp", gs.preview_hunk)
map("n", "<leader>hb", function()
gs.blame_line {full = true}
end)
map("n", "<leader>tb", gs.toggle_current_line_blame)
map("n", "<leader>hd", gs.diffthis)
map("n", "<leader>hD", function() gs.diffthis("~") end)
map("n", "<leader>td", gs.toggle_deleted)
-- Text object
map({"o", "x"}, "ih", ":<C-U>Gitsigns select_hunk<CR>")
end
}
require"gitlinker".setup()
require("Comment").setup()
local cmp = require("cmp")
cmp.setup({
sources = {{name = "nvim_lsp"}},
mapping = {
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = false
})
}
})
end