aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/lua/settings.lua
blob: 9e54de8a538ccc3a369f853fc477678be2074550 (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
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
vim.cmd([[
  syntax enable
  filetype plugin indent on
]])

HOME                  = os.getenv("HOME")

vim.g.mapleader       = ' '
vim.g.maplocalleader  = ','

vim.wo.cursorline     = true
vim.opt.termguicolors = true

-- basic settings
vim.o.encoding        = "utf-8"
vim.o.backspace       = "indent,eol,start" -- backspace works on every char in insert mode
vim.o.completeopt     = 'menuone,noselect'
vim.o.history         = 1000
vim.o.dictionary      = '/usr/share/dict/words'
vim.o.startofline     = true

-- Mapping waiting time
vim.o.timeout         = false
vim.o.ttimeout        = true
vim.o.ttimeoutlen     = 100

-- Display
vim.o.showmatch       = true -- show matching brackets
vim.o.scrolloff       = 3 -- always show 3 rows from edge of the screen
vim.o.synmaxcol       = 300 -- stop syntax highlight after x lines for performance
vim.o.laststatus      = 2 -- always show status line

vim.o.list            = false -- do not display white characters
vim.o.foldenable      = false
vim.o.foldlevel       = 4 -- limit folding to 4 levels
vim.o.foldmethod      = 'syntax' -- use language syntax to generate folds
vim.o.wrap            = true --do not wrap lines even if very long
vim.o.eol             = true -- show if there's no eol char
vim.o.showbreak       = '↪' -- character to show when line is broken

vim.opt.clipboard     = 'unnamedplus'

-- title string
vim.opt.title         = true
vim.opt.titlestring   = 'neovim'

-- Sidebar
vim.o.number          = true  -- line number on the left
vim.o.numberwidth     = 3     -- always reserve 3 spaces for line number
vim.o.signcolumn      = 'yes' -- keep 1 column for check
vim.o.modelines       = 0
vim.o.showcmd         = true  -- display command in bottom bar
-- make term better
vim.api.nvim_command('autocmd TermOpen * setlocal nonumber norelativenumber signcolumn=no')
-- do insert on enter term
-- vim.api.nvim_command('autocmd BufWinEnter,WinEnter term://* startinsert')


-- Search
vim.o.incsearch     = true -- starts searching as soon as typing, without enter needed
vim.o.ignorecase    = true -- ignore letter case when searching
vim.o.smartcase     = true -- case insentive unless capitals used in search

vim.o.matchtime     = 2    -- delay before showing matching paren
vim.o.mps           = vim.o.mps .. ",<:>"

-- White characters
vim.o.autoindent    = true
vim.o.smartindent   = true
vim.o.tabstop       = 2    -- 1 tab = 2 spaces
vim.o.shiftwidth    = 2    -- indentation rule
vim.o.formatoptions =
'qnj1'                     -- q  - comment formatting; n - numbered lists; j - remove comment when joining lines; 1 - don't break after one-letter word
vim.o.expandtab     = true -- expand tab to spaces

-- Backup files
vim.o.backup        = true                         -- use backup files
vim.o.writebackup   = false
vim.o.swapfile      = false                        -- do not use swap file
vim.o.undodir       = HOME .. '/.vim/tmp/undo//'   -- undo files
vim.o.backupdir     = HOME .. '/.vim/tmp/backup//' -- backups
vim.o.directory     = '/.vim/tmp/swap//'           -- swap files

vim.cmd([[
  au FileType python                  set ts=4 sw=4
  au BufRead,BufNewFile *.md          set ft=mkd tw=80 syntax=markdown
  au BufRead,BufNewFile *.ppmd        set ft=mkd tw=80 syntax=markdown
  au BufRead,BufNewFile *.markdown    set ft=mkd tw=80 syntax=markdown
  au BufRead,BufNewFile *.slimbars    set syntax=slim
]])

vim.cmd([[
" for debugging colorscheme
function! SynStack()
  if !exists("*synstack")
    return
  endif
  echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
command! Synstack call SynStack()
]])
-- highlights the list of words following "Todo" if they are parsed in what looks like a comment
vim.cmd([[
autocmd Syntax * syntax keyword Todo note NOTE fixme FIXME todo TODO speed SPEED hack HACK safety SAFETY containedin=.*Comment.*
]])


vim.cmd([[
colorscheme yaks
set guicursor=n-v-c:block-Cursor
set guicursor+=i:ver25-iCursor
]])

if not vim.g.neovide then
  vim.cmd([[
  " ### Transparency ###
  hi Normal guibg=none ctermbg=none
  hi LineNr guibg=none ctermbg=none
  hi Folded guibg=none ctermbg=none
  hi NonText guibg=none ctermbg=none
  hi SpecialKey guibg=none ctermbg=none
  hi VertSplit guibg=none ctermbg=none
  hi SignColumn guibg=none ctermbg=none
  hi EndOfBuffer guibg=none ctermbg=none
  ]])
end
-- Commands mode
vim.o.wildmenu = true -- on TAB, complete options for system command
vim.o.wildignore =
'deps,.svn,CVS,.git,.hg,*.o,*.a,*.class,*.mo,*.la,*.so,*.obj,*.swp,*.jpg,*.png,*.xpm,*.gif,.DS_Store,*.aux,*.out,*.toc'

-- sometimes shift is held down for too long while zoomer quitting
vim.api.nvim_create_user_command('Q', 'q', {})
vim.api.nvim_create_user_command('Qa', 'qa', {})
vim.api.nvim_create_user_command('QA', 'qa', {})


-- rust format on save
-- https://sharksforarms.dev/posts/neovim-rust/
local format_sync_grp = vim.api.nvim_create_augroup("Format", {})
vim.api.nvim_create_autocmd("BufWritePre", {
  pattern = { "*" },
  callback = function()
    print(vim.bo.filetype)
    -- idk what's happening but:
    --  https://github.com/sqls-server/sqls/issues/105
    if vim.bo.filetype == 'sql' then
      return
    end

    vim.lsp.buf.format({ timeout_ms = 200 })
  end,
  group = format_sync_grp,
})

-- clear whitespace
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
  pattern = { "*" },
  command = [[%s/\s\+$//e]],
  group = format_sync_grp,
})