nvim/.config/nvim/init.vim (view raw)
1" la-ninpre init.vim "
2
3" misc: {{{
4
5if &shell =~# 'fish$'
6 set shell=bash
7endif
8
9" use space as leader key
10let mapleader=" "
11
12" enter new era :D
13set nocompatible
14set encoding=utf-8
15
16" enable hybrid numbers
17set nu rnu
18
19" mouse is bad, but sometimes is useful
20set mouse=a
21
22" this is for better file searching
23set path=.,**
24set wildmenu
25
26" more intuitive splits
27set splitbelow splitright
28
29" search options
30set nohlsearch incsearch ignorecase smartcase showmatch
31
32" ruler
33set rulerformat=%38(%{strftime('%F\ %H:%M')}%=%l/%L\ (%p%%)%=%c%=\ %)
34
35" expand tabs to spaces
36set tabstop=4 softtabstop=4
37set shiftwidth=4
38set expandtab
39
40" use autoindents
41set smartindent
42
43" replace default behaviour with undotree plugin
44set noswapfile nobackup
45set undodir=~/.local/share/nvim/undodir
46set undofile
47
48" actually, i don't remember what is this...
49set hidden
50
51" fix update time
52set updatetime=50
53
54" remind yourself about 80 column rule
55set colorcolumn=81
56
57" this could be used to show unprintable characters
58set listchars=tab:>-,eol:$,space:•,trail:~
59
60" }}}
61" plugins: {{{
62
63" pluggins are installed with vim plug
64call plug#begin('~/.local/share/nvim/plugged')
65"Plug 'ap/vim-css-color'
66Plug 'cespare/vim-toml'
67Plug 'dag/vim-fish'
68Plug 'dense-analysis/ale'
69Plug 'https://tildegit.org/sloum/gemini-vim-syntax'
70Plug 'hrsh7th/nvim-cmp'
71Plug 'hrsh7th/cmp-nvim-lsp'
72Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
73Plug 'junegunn/fzf.vim'
74Plug 'junegunn/goyo.vim'
75Plug 'junegunn/limelight.vim'
76Plug 'karolbelina/uxntal.vim'
77Plug 'L3MON4D3/LuaSnip'
78Plug 'mattn/emmet-vim'
79Plug 'mbbill/undotree'
80Plug 'neovim/nvim-lspconfig'
81Plug 'preservim/nerdcommenter'
82Plug 'saadparwaiz1/cmp_luasnip'
83Plug 'tpope/vim-surround'
84call plug#end()
85filetype plugin indent on
86
87" }}}
88" colorscheme: {{{
89" limelight
90let g:limelight_conceal_ctermfg = 'gray'
91let g:limelight_conceal_ctermfg = 240
92hi ColorColumn ctermbg=grey
93
94" }}}
95" mappings: {{{
96
97" easier navigation in splits
98map <C-H> <C-W><C-H>
99map <C-L> <C-W><C-L>
100map <C-J> <C-W><C-J>
101map <C-K> <C-W><C-K>
102
103" replace all occurencies of the word under the cursor
104nnoremap <leader>su :%s/\<<C-r><C-w>\>/
105
106" show or hide undo tree
107nnoremap <leader>u :UndotreeToggle<CR>
108
109" open helptags
110nnoremap <leader>h :Helptags<CR>
111
112" open file with fzf
113nnoremap <leader>o :Files<CR>
114
115" easy source init.vim
116nnoremap <leader><CR> :so ~/.config/nvim/init.vim<CR>
117" easy open init.vim
118nnoremap <leader>vc :e ~/.config/nvim/init.vim<CR>
119
120" show or hide unprintable characters
121nnoremap <leader>sl :set list<CR>
122nnoremap <leader>sn :set nolist<CR>
123
124" goyo
125nnoremap <leader>go :Goyo<CR>
126
127" actually magick!
128" this moves higlighted block up or down
129vnoremap J :m '>+1<CR>gv=gv
130vnoremap K :m '<-2<CR>gv=gv
131
132" alias for capturing group in command mode (for use with regexps)
133cmap ;( \(\)<Left><Left>
134
135" }}}
136" autocommands: {{{
137
138" disable undofiles for passwords (yikes!)
139au BufWritePre /dev/shm/pass.* setlocal noundofile
140
141" limelight on when goyo
142autocmd! User GoyoEnter Limelight
143autocmd! User GoyoLeave Limelight!
144
145" fix wrong nvim size when starting in alacritty
146autocmd VimEnter * :silent exec "!kill -s SIGWINCH $PPID"
147
148" enable insert mode when entering git commit message
149autocmd VimEnter */COMMIT_EDITMSG exec 'normal 1G' | startinsert
150
151" highlight yanked text (needs nvim 0.5.x)
152augroup highlight_yank
153 autocmd!
154 autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank({timeout = 40})
155augroup END
156
157" }}}
158" lsp: {{{
159lua <<EOF
160
161local capabilities = vim.lsp.protocol.make_client_capabilities()
162capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
163
164local opts = { noremap=true, silent=true }
165vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
166vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
167vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
168vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
169
170-- Use an on_attach function to only map the following keys
171-- after the language server attaches to the current buffer
172local on_attach = function(client, bufnr)
173 -- Enable completion triggered by <c-x><c-o>
174 --vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
175
176 -- Mappings.
177 -- See `:help vim.lsp.*` for documentation on any of the below functions
178 local bufopts = { noremap=true, silent=true, buffer=bufnr }
179 vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, bufopts)
180 vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
181 vim.keymap.set('n', 'K', vim.lsp.buf.hover, bufopts)
182 vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, bufopts)
183 vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, bufopts)
184 vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, bufopts)
185 vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, bufopts)
186 vim.keymap.set('n', '<space>wl', function()
187 print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
188 end, bufopts)
189 vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, bufopts)
190 vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, bufopts)
191 vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, bufopts)
192 vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts)
193 vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, bufopts)
194end
195
196lspconfig = require "lspconfig"
197util = require "lspconfig/util"
198
199lspconfig.clangd.setup {
200 on_attach = on_attach,
201 capabilities = capabilities
202}
203
204lspconfig.pyright.setup {
205 on_attach = on_attach,
206 capabilities = capabilities
207}
208
209lspconfig.gopls.setup {
210 cmd = {"gopls", "serve"},
211 filetypes = {"go", "gomod"},
212 root_dir = util.root_pattern("go.work", "go.mod", ".git"),
213 on_attach = on_attach,
214 capabilities = capabilities,
215 settings = {
216 gopls = {
217 analyses = {
218 unusedparams = true,
219 },
220 staticcheck = true,
221 },
222 },
223}
224lspconfig.hls.setup{
225 on_attach = on_attach,
226 root_dir = vim.loop.cwd,
227 capabilities = capabilities,
228 settings = {
229 rootMarkers = {"./git/"}
230 }
231}
232
233-- luasnip setup
234local luasnip = require 'luasnip'
235
236-- nvim-cmp setup
237local cmp = require 'cmp'
238cmp.setup {
239 snippet = {
240 expand = function(args)
241 luasnip.lsp_expand(args.body)
242 end,
243 },
244 mapping = cmp.mapping.preset.insert({
245 ['<C-d>'] = cmp.mapping.scroll_docs(-4),
246 ['<C-f>'] = cmp.mapping.scroll_docs(4),
247 ['<C-Space>'] = cmp.mapping.complete(),
248 ['<CR>'] = cmp.mapping.confirm {
249 behavior = cmp.ConfirmBehavior.Replace,
250 select = true,
251 },
252 ['<Tab>'] = cmp.mapping(function(fallback)
253 if cmp.visible() then
254 cmp.select_next_item()
255 elseif luasnip.expand_or_jumpable() then
256 luasnip.expand_or_jump()
257 else
258 fallback()
259 end
260 end, { 'i', 's' }),
261 ['<S-Tab>'] = cmp.mapping(function(fallback)
262 if cmp.visible() then
263 cmp.select_prev_item()
264 elseif luasnip.jumpable(-1) then
265 luasnip.jump(-1)
266 else
267 fallback()
268 end
269 end, { 'i', 's' }),
270 }),
271 sources = {
272 { name = 'nvim_lsp' },
273 { name = 'luasnip' },
274 },
275}
276EOF
277" }}}
278" vim: ft=vim fdm=marker: