summaryrefslogtreecommitdiffstatshomepage
path: root/nvim/.config/nvim/lua/autocommands.lua
blob: c87fb70e9032b16c722643034a7e62644418a386 (plain)
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
-- to Show whitespace, MUST be inserted BEFORE the colorscheme command
vim.cmd [[
  augroup _general_settings
    autocmd!
    autocmd FileType qf,help,man,lspinfo,spectre_panel nnoremap <silent> <buffer> q :close<CR>
    autocmd TextYankPost * silent!lua require('vim.highlight').on_yank({higroup = 'Visual', timeout = 200})
    autocmd BufWritePre * :%s/\s\+$//e
    autocmd BufWinEnter * :set formatoptions-=cro
    autocmd BufEnter * set fo-=c fo-=r fo-=o
    autocmd FileType qf set nobuflisted
    autocmd CmdWinEnter * quit
    autocmd FileType xml,html,xhtml,css,scss,javascript,lua,dart setlocal shiftwidth=2 tabstop=2
    autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
  augroup end

  augroup format_on_save
    autocmd!
    autocmd BufWritePre * lua vim.lsp.buf.formatting()
  augroup end

  augroup _git
    autocmd!
    autocmd FileType gitcommit setlocal wrap
    autocmd FileType gitcommit setlocal spell
  augroup end

  augroup _markdown
    autocmd!
    autocmd FileType markdown setlocal wrap
    autocmd FileType markdown setlocal spell
    autocmd BufNewFile,BufRead *.mdx set filetype=markdown
  augroup end

  augroup _latex
    autocmd!
    autocmd FileType latex,tex,plaintex setlocal wrap
    autocmd FileType latex,tex,plaintex setlocal spell
    autocmd FileType latex,tex,plaintex setlocal linebreak
  augroup end

  augroup _json
    autocmd!
    autocmd BufEnter *.json set ai expandtab shiftwidth=2 tabstop=2 sta fo=croql
  augroup end

  augroup _auto_resize
    autocmd!
    autocmd VimResized * tabdo wincmd =
  augroup end

  augroup _alpha
    autocmd!
    autocmd User AlphaReady set showtabline=0 | autocmd BufUnload <buffer> set showtabline=2
  augroup end
]]