summaryrefslogtreecommitdiff
path: root/neovim/.config/nvim/lua/settings.lua
blob: c3807e2a29a87c9b5b1e92aa8d35695091405a3c (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
-- General settings

vim.g.loaded_python_provider = 1
vim.g.python3_host_prog = '/Users/michael/.pyenv/shims/python3'
vim.g.loaded_perl_provider = 0
vim.g.loaded_ruby_provider = 0

vim.opt.rnu = true
vim.opt.number = true
vim.opt.hlsearch = true
vim.opt.incsearch = true
vim.opt.backspace = { 'indent', 'eol', 'start' }
vim.opt.visualbell = true
vim.opt.clipboard:append { 'unnamedplus' }
vim.opt.completeopt = { 'menuone', 'noselect' }
vim.opt.cmdheight = 0
vim.opt.expandtab = true
vim.opt.wrap = false
vim.opt.shiftwidth = 4
vim.opt.softtabstop = 4
vim.opt.smarttab = true
vim.opt.encoding = 'utf-8'
vim.opt.foldenable = false
vim.opt.linebreak = true
vim.opt.showbreak = '↪ '
vim.opt.breakindent = true
vim.opt.termguicolors = true
vim.opt.background = 'light'
vim.cmd[[
syntax on
  filetype on
  filetype plugin on
  filetype plugin indent on
  highlight Comment cterm=italic gui=italic
]]
vim.opt.backup = false
vim.opt.writebackup = false
vim.opt.updatetime = 300
vim.opt.shortmess:append 'c'
vim.opt.signcolumn = 'yes'

vim.keymap.set("", "<A-{>", "<cmd>tabprevious<CR>", { noremap=true })
vim.keymap.set("", "<A-}>", "<cmd>tabnext<CR>", { noremap=true })

-- Autocommands

local indent_rules_augroup = vim.api.nvim_create_augroup('Indents', {})
vim.api.nvim_create_autocmd( { 'FileType' }, {
  pattern = { 'make', 'sh' },
  group = indent_rules_augroup,
  callback = function()
    vim.opt_local.tabstop = 8
    vim.opt_local.shiftwidth = 8
    vim.opt_local.softtabstop = 0
    vim.opt_local.expandtab = false
  end
})
vim.api.nvim_create_autocmd( { 'FileType' }, {
  pattern = { 'go' },
  group = indent_rules_augroup,
  callback = function()
    vim.opt_local.tabstop = 4
    vim.opt_local.shiftwidth = 4
    vim.opt_local.softtabstop = 0
    vim.opt_local.expandtab = false
  end
})
vim.api.nvim_create_autocmd( { 'FileType' }, {
  pattern = { 'javascript', 'lua' },
  group = indent_rules_augroup,
  callback = function()
    vim.opt_local.tabstop = 2
    vim.opt_local.shiftwidth = 2
    vim.opt_local.softtabstop = 2
  end
})

local wrap_rules_augroup = vim.api.nvim_create_augroup('Wrap', {})
vim.api.nvim_create_autocmd( { 'FileType' }, {
  pattern = { 'markdown', 'rst', 'text' },
  group = wrap_rules_augroup,
  callback = function()
    vim.opt_local.wrap = true
  end
})

local terminal_rules_augroup = vim.api.nvim_create_augroup('Terminal', {})
vim.api.nvim_create_autocmd( { 'TermOpen' }, {
  pattern = { '*' },
  group = terminal_rules_augroup,
  callback = function()
    vim.cmd('startinsert')
    vim.opt_local.scrollback = 100000
    vim.opt_local.modified = true
    vim.opt_local.bufhidden = 'hide'
    vim.opt_local.statusline = vim.api.nvim_buf_get_var(0, 'term_title')
    vim.opt_local.number = false
    vim.opt_local.rnu = false
    vim.cmd('match Errormsg ""')
  end
})

-- Terminal
vim.cmd[[
  tnoremap <Esc> <C-\><C-n>
  tnoremap <A-h> <C-\><C-N><C-w>h
  tnoremap <A-j> <C-\><C-N><C-w>j
  tnoremap <A-k> <C-\><C-N><C-w>k
  tnoremap <A-l> <C-\><C-N><C-w>l
  inoremap <A-h> <C-\><C-N><C-w>h
  inoremap <A-j> <C-\><C-N><C-w>j
  inoremap <A-k> <C-\><C-N><C-w>k
  inoremap <A-l> <C-\><C-N><C-w>l
  nnoremap <A-h> <C-w>h
  nnoremap <A-j> <C-w>j
  nnoremap <A-k> <C-w>k
  nnoremap <A-l> <C-w>l

  let g:term_buf = 0
  let g:term_win = 0

  function! Term_toggle(height)
      if win_gotoid(g:term_win)
          hide
      else
          botright new
          exec "resize ". a:height
          try
              exec "buffer " . g:term_buf
          catch
              call termopen($SHELL, {"detach": 0})
              keepalt file Terminal
              let g:term_buf = bufnr("")
          endtry
          let g:term_win = win_getid()
      endif
  endfunction

  nnoremap <Leader>t :call Term_toggle(15)<CR>
]]

-- Tab navigation in gui
if vim.fn.has('gui_running') == 1 then
  vim.keymap.set('n', '<S-D-{>', '<cmd>tabp<CR>', { noremap = true, silent = true })
  vim.keymap.set('v', '<S-D-{>', '<cmd>tabp<CR>', { noremap = true, silent = true })
  vim.keymap.set('i', '<S-D-{>', '<Esc><cmd>tabp<CR>', { noremap = true, silent = true })
  vim.keymap.set('n', '<S-D-}>', '<cmd>tabn<CR>', { noremap = true, silent = true })
  vim.keymap.set('v', '<S-D-}>', '<cmd>tabn<CR>', { noremap = true, silent = true })
  vim.keymap.set('i', '<S-D-}>', '<Esc><cmd>tabn<CR>', { noremap = true, silent = true })
end