aboutsummaryrefslogtreecommitdiff
path: root/.config/nvim/init.lua
blob: 4e254b3ddd8ad0f9760eeb502e185c2990c6ea67 (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
-- init.lua

-- Use System Clipboard
-- vim.opt.clipboard = "unnamedplus"

-- Basic run commands
vim.cmd("colorscheme tender")
vim.cmd("filetype plugin on")
vim.cmd("syntax on")
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.cursorline = true
vim.cmd("highlight Cursorline cterm=bold ctermbg=black")
vim.cmd("filetype indent on")
vim.opt.mouse = "a"
vim.opt.hlsearch = true
vim.opt.autochdir = true

-- Enable smartcase search sensitivity
vim.opt.ignorecase = true
vim.opt.smartcase = true

-- Indentation using spaces
-- tabstop: width of tab character
-- softtabstop: fine tunes the amount of whitespace to be added
-- shiftwidth: determines the amount of whitespace to add in normal mode
-- expandtab: when on use space instead of tab
-- textwidth: text wrap width
-- autoindent: autoindent in new line
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.shiftwidth = 4
-- vim.opt.textwidth = 79
vim.opt.expandtab = true
vim.opt.autoindent = true

-- Show the matching part of pairs [] {} and ()
vim.opt.showmatch = true

-- Remove trailing whitespace from Python and Fortran files
vim.api.nvim_exec([[
  autocmd BufWritePre *.py :%s/\s\+$//e
  autocmd BufWritePre *.f90 :%s/\s\+$//e
  autocmd BufWritePre *.f95 :%s/\s\+$//e
  autocmd BufWritePre *.for :%s/\s\+$//e
]], false)

if vim.fn.has('gui_running') == 1 then
  vim.opt.t_Co = 256
  vim.opt.guifont = "JetBrains Mono 11"
  vim.opt.guioptions:remove("m")
  vim.opt.guioptions:remove("T")
  vim.opt.guioptions:remove("r")
  vim.opt.guioptions:remove("L")
  vim.cmd("colorscheme tender")
end

-- Enable true colors support
vim.opt.termguicolors = true

if vim.env.TERM == "alacritty" then
  vim.opt.ttymouse = "sgr"
end

-- Keybinds for x clipboard
vim.cmd [[
  vnoremap <C-c> "+y
  vmap <C-x> "+x
  map <C-p> "+p
  map <Leader>p "+P
]]

-- Vertical Motions Mappings
vim.api.nvim_set_keymap("n", "<C-d>", "<C-d>zz", { noremap = true })
vim.api.nvim_set_keymap("n", "<C-u>", "<C-u>zz", { noremap = true })
vim.api.nvim_set_keymap("n", "n", "nzzzv", { noremap = true })
vim.api.nvim_set_keymap("n", "N", "Nzzzv", { noremap = true })

-- NERDTree Keybinds
vim.api.nvim_set_keymap("n", "<leader>n", ":NERDTreeFocus<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<C-n>", ":NERDTree<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<C-t>", ":NERDTreeToggle<CR>", { noremap = true })
vim.api.nvim_set_keymap("n", "<C-f>", ":NERDTreeFind<CR>", { noremap = true })

-- Plugin manager (vim-plug)
vim.cmd [[
  call plug#begin()
  Plug 'https://github.com/preservim/nerdtree', { 'on': 'NERDTreeToggle' }
  " Plug 'LunarWatcher/auto-pairs'
  Plug 'tmsvg/pear-tree'
  Plug 'https://github.com/adelarsq/vim-matchit'
  Plug 'neoclide/coc.nvim', {'branch': 'release'}
  Plug 'tpope/vim-surround'
  Plug 'sbdchd/neoformat'
  Plug 'ThePrimeagen/vim-be-good'
  Plug 'junegunn/fzf'
  call plug#end()
]]

-- Use a line cursor within insert mode and a block cursor everywhere else.
-- Reference chart of values:
--   Ps = 0  -> blinking block.
--   Ps = 1  -> blinking block (default).
--   Ps = 2  -> steady block.
--   Ps = 3  -> blinking underline.
--   Ps = 4  -> steady underline.
--   Ps = 5  -> blinking bar (xterm).
--   Ps = 6  -> steady bar (xterm).
vim.g.t_SI = "\27[6 q"
vim.g.t_EI = "\27[2 q"

-- Fix the cursor change timeout between insert and normal mode (see function above)
vim.opt.ttimeout = true
vim.opt.ttimeoutlen = 1
vim.opt.listchars = { tab = ">-", trail = "~", extends = ">", precedes = "<", space = "." }
vim.opt.ttyfast = true

-- Tab Autocompletion for COC.NVIM
vim.cmd [[
function! CheckBackspace() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

inoremap <silent><expr> <TAB>
      \ coc#pum#visible() ? coc#pum#next(1) :
      \ CheckBackspace() ? "\<Tab>" :
      \ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
]]

-- COC.NVIM colors
vim.cmd("highlight CocFloating ctermbg=0")
vim.cmd("highlight CocErrorFloat ctermfg=15")

-- Customize split dividers
vim.opt.fillchars = vim.opt.fillchars + {
  vert = "█",
  fold = "█",
  diff = "█",
  stl = "=",
  stlnc = "=",
  stl = "="
}
vim.cmd("highlight VertSplit ctermfg=235 guifg=#3c3836")
vim.cmd("highlight StatusLine ctermfg=black ctermbg=lightgray")
vim.cmd("highlight StatusLineNC ctermfg=darkgray ctermbg=lightgray")