diff options
Diffstat (limited to 'nvim/lua/config/autocmds.lua')
| -rw-r--r-- | nvim/lua/config/autocmds.lua | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/nvim/lua/config/autocmds.lua b/nvim/lua/config/autocmds.lua new file mode 100644 index 0000000..e11b231 --- /dev/null +++ b/nvim/lua/config/autocmds.lua | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | -- https://github.com/nvim-treesitter/nvim-treesitter/blob/main/doc/nvim-treesitter.txt | ||
| 2 | vim.api.nvim_create_autocmd('FileType', { | ||
| 3 | pattern = { "c", "cpp", "lua", "typescript" }, | ||
| 4 | callback = function() | ||
| 5 | vim.treesitter.start() | ||
| 6 | vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()' | ||
| 7 | vim.wo.foldmethod = 'expr' | ||
| 8 | vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" | ||
| 9 | end, | ||
| 10 | }) | ||
| 11 | |||
| 12 | -- https://github.com/nvim-tree/nvim-tree.lua/wiki/Open-At-Startup | ||
| 13 | vim.api.nvim_create_autocmd("VimEnter", { | ||
| 14 | callback = function(data) | ||
| 15 | -- buffer is a real file on the disk | ||
| 16 | local real_file = vim.fn.filereadable(data.file) == 1 | ||
| 17 | |||
| 18 | -- buffer is a [No Name] | ||
| 19 | local no_name = data.file == "" and vim.bo[data.buf].buftype == "" | ||
| 20 | |||
| 21 | if not real_file and not no_name then | ||
| 22 | return | ||
| 23 | end | ||
| 24 | |||
| 25 | -- open the tree, find the file but don't focus it | ||
| 26 | require("nvim-tree.api").tree.toggle({ focus = false, find_file = true, }) | ||
| 27 | end | ||
| 28 | }) | ||
| 29 | |||
| 30 | -- https://github.com/nvim-tree/nvim-tree.lua/wiki/Auto-Close | ||
| 31 | vim.api.nvim_create_autocmd("QuitPre", { | ||
| 32 | callback = function() | ||
| 33 | local invalid_win = {} | ||
| 34 | local wins = vim.api.nvim_list_wins() | ||
| 35 | |||
| 36 | for _, w in ipairs(wins) do | ||
| 37 | local bufname = vim.api.nvim_buf_get_name(vim.api.nvim_win_get_buf(w)) | ||
| 38 | if bufname:match("NvimTree_") ~= nil then | ||
| 39 | table.insert(invalid_win, w) | ||
| 40 | end | ||
| 41 | end | ||
| 42 | |||
| 43 | if #invalid_win == #wins - 1 then | ||
| 44 | -- Should quit, so we close all invalid windows. | ||
| 45 | for _, w in ipairs(invalid_win) do vim.api.nvim_win_close(w, true) end | ||
| 46 | end | ||
| 47 | end | ||
| 48 | }) | ||
| 49 | |||
| 50 | vim.api.nvim_create_autocmd("LspAttach", { | ||
| 51 | callback = function(event) | ||
| 52 | local client = vim.lsp.get_client_by_id(event.data.client_id) | ||
| 53 | local keymaps = require("config.keymaps") | ||
| 54 | keymaps.lsp(event.buf, client) | ||
| 55 | end, | ||
| 56 | }) | ||
