Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
131 lines (109 loc) · 3.45 KB
/
Copy pathinit.lua
File metadata and controls
131 lines (109 loc) · 3.45 KB
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
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
-- Relative line number
vim.wo.relativenumber = true
vim.opt.number = true
vim.o.cmdheight = 1
vim.o.cursorline = true
vim.api.nvim_set_hl(0, "CursorLineNr", { fg = "#ffffff", bold = true })
-- Remove default context menu
vim.cmd('aunmenu PopUp')
-- Save with Control + S
vim.api.nvim_set_keymap('n', '<C-s>', ':w<CR>', { noremap = true, silent = true })
-- Tab size
-- vim.o.expandtab = true
-- vim.o.tabstop = 4 -- A TAB character looks like 4 spaces
-- vim.o.shiftwidth = 4 -- Number of spaces inserted when indenting
-- copy to OSC 52 but paste via internal clipboard. OSC 52 sucks for pasting
function my_paste(reg)
return function(lines)
local content = vim.fn.getreg('"')
return vim.split(content, '\n')
end
end
vim.opt.clipboard:append("unnamedplus")
vim.g.clipboard = {
name = 'OSC 52',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
["+"] = my_paste("+"),
["*"] = my_paste("*"),
},
}
-- Get lazy plugin manager running
require("config.lazy")
-- Nice cursor smear
require("smear_cursor").setup()
-- Automatically disable italics on theme change
vim.api.nvim_create_autocmd("ColorScheme", {
callback = function()
local hl_groups = vim.api.nvim_get_hl(0, {})
for key, hl_group in pairs(hl_groups) do
if hl_group.italic then
vim.api.nvim_set_hl(0, key, vim.tbl_extend("force", hl_group, { italic = false }))
end
end
end,
})
-- theme
vim.cmd 'colorscheme kanso-zen'
-- lsp magic
vim.lsp.config('luals', {})
vim.lsp.config('gopls', {})
require("mason").setup()
require("mason-lspconfig").setup {
ensure_installed = { "lua_ls", "gopls", "ansiblels" },
}
vim.lsp.enable('ansiblels')
-- autoformat on save
local buffer_autoformat = function(bufnr)
local group = 'lsp_autoformat'
vim.api.nvim_create_augroup(group, { clear = false })
vim.api.nvim_clear_autocmds({ group = group, buffer = bufnr })
vim.api.nvim_create_autocmd('BufWritePre', {
buffer = bufnr,
group = group,
desc = 'LSP format on save',
callback = function()
-- note: do not enable async formatting
vim.lsp.buf.format({ async = false, timeout_ms = 10000 })
end,
})
end
vim.api.nvim_create_autocmd('LspAttach', {
callback = function(event)
local bufnr = event.buf
local filetype = vim.bo[bufnr].filetype
if filetype == "go" then
return -- skip .go files
end
local id = vim.tbl_get(event, 'data', 'client_id')
local client = id and vim.lsp.get_client_by_id(id)
if client == nil then
return
end
-- make sure there is at least one client with formatting capabilities
if client.supports_method('textDocument/formatting') then
buffer_autoformat(bufnr)
end
end
})
-- go files
local format_sync_grp = vim.api.nvim_create_augroup("GoFormat", {})
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = "*.go",
callback = function()
require('go.format').goimports()
end,
group = format_sync_grp,
})
require('go').setup()
-- autoformat on save end
vim.o.updatetime = 300
-- Show errors and warnings in a floating window
vim.api.nvim_create_autocmd("CursorHold", {
callback = function()
vim.diagnostic.open_float(nil, { focusable = false, source = "if_many" })
end,
})