740 lines
22 KiB
Lua
740 lines
22 KiB
Lua
|
-- Do fast startup if we can
|
||
|
do
|
||
|
local ok, _ = pcall(require, 'impatient')
|
||
|
if not ok then vim.notify('impatient unavailable') end
|
||
|
end
|
||
|
|
||
|
---- Built in settings ----
|
||
|
-- Create a convenient aliases
|
||
|
local o = vim.o
|
||
|
local g = vim.g
|
||
|
local fn = vim.fn
|
||
|
local opt = vim.opt
|
||
|
|
||
|
-- Define functions for keymaps
|
||
|
local function noremap(mode, key, mapping)
|
||
|
-- no recursion, silent
|
||
|
local opts = { noremap = true, silent = true }
|
||
|
vim.api.nvim_set_keymap(mode, key, mapping, opts)
|
||
|
end
|
||
|
local function inoremap(key, mapping) noremap('i', key, mapping) end
|
||
|
function nnoremap(key, mapping) noremap('n', key, mapping) end
|
||
|
|
||
|
-- Set font
|
||
|
if fn.hostname() == 'sharpy' then
|
||
|
o.guifont = 'Iosevka Term Slab,Iosevka:h10'
|
||
|
else
|
||
|
o.guifont = 'Iosevka Term Slab Extended,Iosevka:h9'
|
||
|
end
|
||
|
if fn.hostname() == 'tappy' then
|
||
|
g.neovide_refresh_rate = 144
|
||
|
end
|
||
|
opt.guicursor:append('a:blinkon1000') -- Blink cursor once a second for all modes
|
||
|
o.mouse = 'a' -- Enable mouse input
|
||
|
o.termguicolors = true -- Enable 24bit terminal colors
|
||
|
g.neovide_confirm_quit = 1 -- Confirm closing neovide window when changes are unsaved
|
||
|
|
||
|
-- Other interface settings
|
||
|
o.clipboard = 'unnamedplus' -- Use system clipboard by default
|
||
|
o.hidden = true -- Allow buffers to not be attached to a window
|
||
|
o.linebreak = true -- Enable word-wrapping at the end of visual lines
|
||
|
o.breakindent = true -- preserve indentention on lines continuing from a wrap
|
||
|
o.hlsearch = false -- Don't highlight search results
|
||
|
o.scrolloff = 5 -- Margin between cursor and screen top/bottom
|
||
|
o.showmatch = true -- Highlight matching brackets
|
||
|
o.splitright = true -- Open new windows below
|
||
|
o.splitbelow = true -- Open new windows to the right
|
||
|
o.title = true -- Set title of terminal window
|
||
|
o.updatetime = 300 -- Write swap file every 300 ms (supposedly reduces delays)
|
||
|
o.foldlevel = 99 -- Keep all folds open
|
||
|
o.foldlevelstart = 99
|
||
|
o.conceallevel = 2 -- Hide concealed text, use replacement if defined
|
||
|
opt.listchars = { -- Symbols for whitespace chars when 'list' is enabled
|
||
|
tab = '🭰 ',
|
||
|
trail = '-',
|
||
|
nbsp = '+'
|
||
|
}
|
||
|
|
||
|
o.tabstop = 4 -- A physical tab is 4 characters wide
|
||
|
o.shiftwidth = 4 -- A unit of indentention is 4 levels wide
|
||
|
o.wrapmargin = 0 -- Disable hard line wrapping
|
||
|
o.textwidth = 0 -- Comments lines should wrap at 100 chars
|
||
|
-- Set <Leader> key
|
||
|
g.mapleader = ' '
|
||
|
vim.cmd 'filetype plugin indent on'
|
||
|
|
||
|
-- Enable persistent undo
|
||
|
if fn.has('persistent_undo') then
|
||
|
o.undodir = fn.expand('~/.local/share/nvim/undo')
|
||
|
o.undofile = true
|
||
|
end
|
||
|
|
||
|
-- Use rg as grep program
|
||
|
if fn.executable('rg') then
|
||
|
o.grepprg = 'rg --vimgrep --smart-case --hidden'
|
||
|
o.grepformat = '%f:%l:%c:%m'
|
||
|
end
|
||
|
|
||
|
-- Convenience keybindings
|
||
|
require'which-key'.register{['<C-w>!'] = {'<Cmd>copen<CR>', 'Quickfix window'}}
|
||
|
require'which-key'.register{['<F2>'] = {'<Cmd>set number! relativenumber!<CR>', 'Toggle relative numbers'}}
|
||
|
require'which-key'.register{['<F3>'] = {'<Cmd>set number!<CR>', 'Toggle line numbers'}}
|
||
|
|
||
|
require'which-key'.register{['<A-h>'] = {'<C-w>h', 'Go to the left window'}}
|
||
|
require'which-key'.register{['<A-l>'] = {'<C-w>l', 'Go to the right window'}}
|
||
|
require'which-key'.register{['<A-n>'] = {'<C-w>n', 'Go to the up window'}}
|
||
|
require'which-key'.register{['<A-e>'] = {'<C-w>e', 'Go to the down window'}}
|
||
|
|
||
|
-- Do workman remappings
|
||
|
noremap('', 'n', 'gj')
|
||
|
noremap('', 'j', 'n')
|
||
|
noremap('', 'e', 'gk')
|
||
|
noremap('', 'k', 'e')
|
||
|
|
||
|
-- Commands
|
||
|
vim.cmd [[
|
||
|
command! Light colorscheme base16-atelier-sulphurpool-light
|
||
|
command! Dark colorscheme nord
|
||
|
]]
|
||
|
|
||
|
-- Autocommands
|
||
|
vim.cmd [[
|
||
|
augroup vimrc
|
||
|
au!
|
||
|
|
||
|
" Restore file position from previous session
|
||
|
au BufReadPost *
|
||
|
\ if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit'
|
||
|
\ | exe "normal! g`\""
|
||
|
\ | endif
|
||
|
|
||
|
" Highlight yanked text
|
||
|
au TextYankPost * silent! lua vim.highlight.on_yank()
|
||
|
|
||
|
au User StartifyReady noremap <buffer> n gj| noremap <buffer> e gk
|
||
|
|
||
|
" Recompile plugin config cache when vimrc is updated
|
||
|
au BufWritePost */.config/nvim/init.lua source <afile> | PackerCompile
|
||
|
|
||
|
augroup END
|
||
|
]]
|
||
|
--local au = vim.api.nvim_create_augroup
|
||
|
--local augroup = vim.api.nvim_create_augroup('luarc', {clear = true})
|
||
|
--au('User', { pattern = 'StartifyReady', group = augroup, callback = function(cmd)
|
||
|
-- vim.keymap.set('', 'n', 'gj', {silent = true, buffer = true})
|
||
|
-- vim.keymap.set('', 'e', 'gk', {silent = true, buffer = true})
|
||
|
--end})
|
||
|
--au('BufWritePost', {
|
||
|
-- pattern = '*/.config/nvim/init.lua',
|
||
|
-- group = augroup,
|
||
|
-- command = 'source <afile> | PackerCompile'
|
||
|
--})
|
||
|
--au('TextYankPost', { pattern = '*', group = augroup, callback = vim.highlight.on_yank })
|
||
|
--au('BufWritePost', { pattern = '*/.config/nvim/init.lua', command = 'source <afile> | PackerCompile' })
|
||
|
--au('BufReadPost', { pattern = '*', group = augroup, command = function()
|
||
|
-- local line = vim.fn.line
|
||
|
-- if line[['\"]] > 1 && line[['\"]] <= line'$' && o.ft ~= 'commit' then
|
||
|
-- vim.cmd'normal g`"'
|
||
|
-- end
|
||
|
--end })
|
||
|
|
||
|
-- Diagnostics
|
||
|
vim.diagnostic.config {
|
||
|
-- Configure underlining diagnostics
|
||
|
underline = {
|
||
|
-- Only underline warnings and up
|
||
|
severity = vim.diagnostic.severity.WARN
|
||
|
}
|
||
|
}
|
||
|
|
||
|
-- netrw
|
||
|
-- Set special URL handler
|
||
|
g.netrw_browsex_viewer = 'xdg-open'
|
||
|
|
||
|
|
||
|
---- Plugins ----
|
||
|
-- Automatically download packer if not installed
|
||
|
local packer_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'
|
||
|
local packer_bootstrap = nil
|
||
|
if fn.empty(fn.glob(packer_path)) > 0 then
|
||
|
if fn.executable('git') ~= 1 then
|
||
|
vim.notify('You must install git to manage plugins')
|
||
|
return
|
||
|
end
|
||
|
vim.notify('Downloading plugin manager with git')
|
||
|
packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', packer_path})
|
||
|
end
|
||
|
|
||
|
require'packer'.startup(function(use)
|
||
|
use 'wbthomason/packer.nvim'
|
||
|
-- Themes --
|
||
|
use {'arcticicestudio/nord-vim', branch = 'main'}
|
||
|
use 'chriskempson/base16-vim'
|
||
|
use 'folke/tokyonight.nvim'
|
||
|
use {'catppuccin/nvim', as = 'catppuccin', config = function ()
|
||
|
vim.g.catppuccin_flavour = 'latte'
|
||
|
require'catppuccin'.setup {
|
||
|
integrations = {
|
||
|
barbar = true,
|
||
|
nvimtree = {
|
||
|
enabled = true,
|
||
|
show_root = true,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
end}
|
||
|
|
||
|
-- Filetype plugins --
|
||
|
use 'rhysd/vim-crystal'
|
||
|
use 'editorconfig/editorconfig-vim'
|
||
|
use 'mboughaba/i3config.vim'
|
||
|
use 'plasticboy/vim-markdown'
|
||
|
use 'mracos/mermaid.vim'
|
||
|
use 'ajouellette/sway-vim-syntax'
|
||
|
use 'cespare/vim-toml'
|
||
|
use 'rust-lang/rust.vim'
|
||
|
|
||
|
-- Editing --
|
||
|
use 'jiangmiao/auto-pairs'
|
||
|
use 'ojroques/nvim-bufdel'
|
||
|
use 'yuttie/comfortable-motion.vim'
|
||
|
use {'mizlan/iswap.nvim', config = function()
|
||
|
require'iswap'.setup{}
|
||
|
require'which-key'.register{['<Leader>s'] = {'<Cmd>ISwapWith<CR>','Swap'}}
|
||
|
end}
|
||
|
use 'bfredl/nvim-luadev' -- lua scratchpad
|
||
|
use 'vim-scripts/ReplaceWithRegister' -- gr replace with register
|
||
|
use 'tpope/vim-sleuth'
|
||
|
-- spellsitter: syntax aware spellchecking
|
||
|
use {'lewis6991/spellsitter.nvim', config = function() require'spellsitter'.setup() end}
|
||
|
use 'tpope/vim-surround'
|
||
|
use {'vim-test/vim-test', config = function ()
|
||
|
vim.g['test#neovim#term_position'] = 'vert'
|
||
|
vim.g['test#strategy'] = 'neovim'
|
||
|
end}
|
||
|
use {'julian/vim-textobj-variable-segment', requires = {'kana/vim-textobj-user'}}
|
||
|
use {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate'} -- TODO: upgrade parsers on update
|
||
|
use 'hrsh7th/vim-vsnip'
|
||
|
|
||
|
-- LSP --
|
||
|
use 'neovim/nvim-lspconfig'
|
||
|
use 'hrsh7th/nvim-cmp'
|
||
|
use 'hrsh7th/cmp-nvim-lsp'
|
||
|
use 'hrsh7th/cmp-buffer'
|
||
|
use 'hrsh7th/cmp-path'
|
||
|
use 'hrsh7th/cmp-cmdline'
|
||
|
use 'simrat39/rust-tools.nvim'
|
||
|
use {'jose-elias-alvarez/null-ls.nvim', requires = {'nvim-lua/plenary.nvim'}, config = function ()
|
||
|
local null_ls = require'null-ls'
|
||
|
null_ls.setup {
|
||
|
sources = {
|
||
|
null_ls.builtins.code_actions.shellcheck,
|
||
|
null_ls.builtins.diagnostics.shellcheck,
|
||
|
}
|
||
|
}
|
||
|
end}
|
||
|
|
||
|
-- UI elements --
|
||
|
use 'vim-airline/vim-airline'
|
||
|
use 'vim-airline/vim-airline-themes'
|
||
|
use 'romgrk/barbar.nvim'
|
||
|
use {'MattesGroeger/vim-bookmarks', config = function()
|
||
|
vim.g.bookmark_save_per_working_dir = 1
|
||
|
end}
|
||
|
use 'j-hui/fidget.nvim'
|
||
|
use 'tpope/vim-fugitive'
|
||
|
use 'tpope/vim-rhubarb'
|
||
|
use 'shumphrey/fugitive-gitlab.vim'
|
||
|
use 'lewis6991/gitsigns.nvim'
|
||
|
use 'junegunn/goyo.vim'
|
||
|
use 'kosayoda/nvim-lightbulb'
|
||
|
use {'https://git.sr.ht/~whynothugo/lsp_lines.nvim', config = function()
|
||
|
require'lsp_lines'.register_lsp_virtual_lines()
|
||
|
vim.diagnostic.config { virtual_text = false }
|
||
|
end}
|
||
|
use {'rcarriga/nvim-notify', after = 'telescope.nvim', config = function ()
|
||
|
require'notify'.setup {
|
||
|
stages = 'fade'
|
||
|
}
|
||
|
vim.notify = require'notify'
|
||
|
require'telescope'.load_extension('notify')
|
||
|
end}
|
||
|
use {'luukvbaal/stabilize.nvim', config = function()
|
||
|
require'stabilize'.setup()
|
||
|
end}
|
||
|
use 'mhinz/vim-startify'
|
||
|
use {'nvim-telescope/telescope.nvim', after = 'which-key.nvim', config = function()
|
||
|
require'telescope'.setup {
|
||
|
defaults = {
|
||
|
sorting_strategy = 'ascending',
|
||
|
mappings = {
|
||
|
n = {
|
||
|
n = 'move_selection_next',
|
||
|
e = 'move_selection_previous',
|
||
|
},
|
||
|
i = {
|
||
|
['<C-h>'] = 'which_key',
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
extensions = {
|
||
|
fzf = {
|
||
|
override_generic_sorter = true,
|
||
|
override_file_sorter = true,
|
||
|
},
|
||
|
file_browser = {
|
||
|
hijack_netrw = false,
|
||
|
respect_gitignore = false,
|
||
|
},
|
||
|
project = {
|
||
|
-- TODO; check if this is right
|
||
|
full_path = true,
|
||
|
},
|
||
|
['ui-select'] = {
|
||
|
require'telescope.themes'.get_dropdown({layout_strategy = 'cursor'})
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
require'which-key'.register {
|
||
|
["<Leader>f"] = {
|
||
|
name = 'Telescope',
|
||
|
["<Space>"] = {'<Cmd>Telescope<CR>', 'List pickers'},
|
||
|
f = {'<Cmd>Telescope find_files<CR>', 'Files'},
|
||
|
d = {'<Cmd>Telescope find_files find_command=fd,--type,d,-I<CR>', 'Directories'},
|
||
|
r = {'<Cmd>Telescope oldfiles<CR>', 'Recent files'},
|
||
|
g = {'<Cmd>Telescope live_grep<CR>', 'Grep'},
|
||
|
b = {'<Cmd>Telescope buffers<CR>', 'Buffers'},
|
||
|
e = {'<Cmd>Telescope diagnostics<CR>', 'Diagnostics'},
|
||
|
h = {'<Cmd>Telescope help_tags<CR>', 'Help page'},
|
||
|
p = {'<Cmd>Telescope project<CR>', 'Projects'},
|
||
|
s = {'<Cmd>Telescope lsp_dynamic_workspace_symbols<CR>', 'Symbols'},
|
||
|
n = {'<Cmd>Telescope notify<CR>', 'Notifications'},
|
||
|
[':'] = {'<Cmd>Telescope commands<CR>', 'Commands'},
|
||
|
}
|
||
|
}
|
||
|
end}
|
||
|
use {'nvim-telescope/telescope-fzf-native.nvim', run = 'make', config = function()
|
||
|
require'telescope'.load_extension('fzf')
|
||
|
end}
|
||
|
use {'nvim-telescope/telescope-file-browser.nvim', config = function ()
|
||
|
require'telescope'.load_extension('file_browser')
|
||
|
end}
|
||
|
use {'nvim-telescope/telescope-project.nvim', config = function ()
|
||
|
require'telescope'.load_extension('project')
|
||
|
end}
|
||
|
use {'nvim-telescope/telescope-ui-select.nvim', config = function ()
|
||
|
require'telescope'.load_extension('ui-select')
|
||
|
end}
|
||
|
use 'kyazdani42/nvim-tree.lua'
|
||
|
use 'simrat39/symbols-outline.nvim'
|
||
|
use {'folke/which-key.nvim', config = function() require'which-key'.setup() end}
|
||
|
|
||
|
-- Utility and libraries
|
||
|
use 'nvim-lua/plenary.nvim'
|
||
|
use 'ryanoasis/vim-devicons'
|
||
|
use 'kyazdani42/nvim-web-devicons'
|
||
|
use 'antoinemadec/FixCursorHold.nvim'
|
||
|
use 'lewis6991/impatient.nvim' -- speeds up load times
|
||
|
|
||
|
-- Finish bootstrap if we just cloned
|
||
|
if packer_bootstrap then
|
||
|
require('packer').sync()
|
||
|
vim.notify('Bootstrapped plugin manager, you may need to restart neovim')
|
||
|
end
|
||
|
end)
|
||
|
|
||
|
|
||
|
---- airline ----
|
||
|
-- Permit spaces after tabs but not in between when doing mixed indent checking
|
||
|
-- (mainly for multiline /* */ style comments)
|
||
|
g['airline#extensions#whitespace#mixed_indent_algo'] = 2
|
||
|
-- truncate leading branch paths, i.e. agraven/foo → a/foo
|
||
|
g['airline#extensions#branch#format'] = 2
|
||
|
g['airline#extensions#c_like_langs'] = {'typescript'}
|
||
|
-- Hide encoding section
|
||
|
g['airline#extensions#default#layout'] = {{'a', 'b', 'c'}, {'x', 'z', 'warning', 'error'}}
|
||
|
g.airline_detect_spell = 1 -- Show if 'spell' is enabled
|
||
|
g.airline_detect_spelllang = 1 -- Display what language spell is using if enabled
|
||
|
g.airline_inactive_collapse = 1 -- Show only filename in inactive windows
|
||
|
g.airline_highlighting_cache = 1 -- Improves performance
|
||
|
g.airline_theme = 'ayu_mirage' -- Airline's theme
|
||
|
g.airline_powerline_fonts = 1 -- Enable symbols from the powerline font patch
|
||
|
|
||
|
-- This doesn't work in lua for some reason
|
||
|
vim.cmd [[
|
||
|
if !exists('g:airline_symbols')
|
||
|
let g:airline_symbols = {} " Initialize the table of symbols
|
||
|
endif
|
||
|
let g:airline_symbols.linenr = ' ' " Symbol before line number
|
||
|
let g:airline_symbols.maxlinenr = '' " Symbol after max line number
|
||
|
let g:airline_symbols.colnr = ' ' " Symbol before column number
|
||
|
let g:airline_symbols.dirty = '+' " Symbol on modified branch
|
||
|
let g:airline_symbols.notexists = '?' " Symbol for untracked file
|
||
|
]]
|
||
|
|
||
|
|
||
|
---- autopairs ----
|
||
|
vim.g.AutoPairsMultilineClose = 0
|
||
|
|
||
|
|
||
|
---- barbar ----
|
||
|
require'which-key'.register {
|
||
|
['<A-,>'] = {'<Cmd>BufferPrevious<CR>', 'Next buffer'},
|
||
|
['<A-.>'] = {'<Cmd>BufferNext<CR>', 'Previous buffer'},
|
||
|
['<A-b>'] = {'<Cmd>BufferPick<CR>', 'Pick buffer'},
|
||
|
['<A-p>'] = {'<Cmd>BufferPin<CR>', 'Pin buffer'},
|
||
|
['<A-d>'] = {'<Cmd>BufferClose<CR>', 'Delete buffer'},
|
||
|
['<A-<>'] = {'<Cmd>BufferMovePrevious<CR>', 'Move buffer left'},
|
||
|
['<A->>'] = {'<Cmd>BufferMoveNext<CR>', 'Move buffer right'},
|
||
|
}
|
||
|
|
||
|
|
||
|
---- devicons ----
|
||
|
require'nvim-web-devicons'.setup { default = true }
|
||
|
|
||
|
|
||
|
---- editorconfig ----
|
||
|
g.EditorConfig_exclude_patterns = {'fugitive://.*'}
|
||
|
|
||
|
|
||
|
---- fidget ----
|
||
|
require'fidget'.setup {}
|
||
|
|
||
|
|
||
|
---- fugitive ----
|
||
|
require'which-key'.register {['<Leader>g'] = {'<Cmd>vert Git<CR>', 'Git information'}}
|
||
|
|
||
|
|
||
|
---- gitsigns ----
|
||
|
require'gitsigns'.setup {}
|
||
|
|
||
|
|
||
|
---- goyo ----
|
||
|
g.goyo_height = '95%'
|
||
|
|
||
|
|
||
|
---- lightbulb ----
|
||
|
g.lightbulb_cfg = {
|
||
|
sign = {
|
||
|
enabled = false,
|
||
|
},
|
||
|
virtual_text = {
|
||
|
enabled = true,
|
||
|
text = "🛈",
|
||
|
}
|
||
|
}
|
||
|
--vim.cmd [[
|
||
|
-- highlight link LightBulbVirtualText Comment
|
||
|
-- autocmd CursorHold,CursorHoldI * lua require'nvim-lightbulb'.update_lightbulb(vim.g.lightbulb_cfg)
|
||
|
--]]
|
||
|
|
||
|
|
||
|
---- lsp: cmp ----
|
||
|
local feedkey = function(key, mode)
|
||
|
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
|
||
|
end
|
||
|
local cmp = require'cmp'
|
||
|
cmp.setup {
|
||
|
preselect = cmp.PreselectMode.None,
|
||
|
snippet = {
|
||
|
expand = function(args)
|
||
|
vim.fn['vsnip#anonymous'](args.body)
|
||
|
end,
|
||
|
},
|
||
|
mapping = {
|
||
|
-- Next item, or expand or jump snippet, or fallback
|
||
|
['<Tab>'] = cmp.mapping(function(fallback)
|
||
|
if cmp.visible() then
|
||
|
cmp.select_next_item()
|
||
|
elseif vim.fn['vsnip#available'](1) == 1 then
|
||
|
feedkey('<Plug>(vsnip-expand-or-jump)', '')
|
||
|
else
|
||
|
fallback()
|
||
|
end
|
||
|
end, {'i', 's'}),
|
||
|
-- Prev item, or jump snippet back, or fallback
|
||
|
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||
|
if cmp.visible() then
|
||
|
cmp.select_prev_item()
|
||
|
elseif vim.fn['vsnip#available'](-1) == 1 then
|
||
|
feedkey('<Plug>(vsnip-jump-prev)', '')
|
||
|
else
|
||
|
fallback()
|
||
|
end
|
||
|
end, {'i', 's'}),
|
||
|
-- Complete common substring
|
||
|
['<C-l>'] = cmp.mapping(cmp.mapping.complete_common_string(), {'i', 'c'}),
|
||
|
-- Complete
|
||
|
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), {'i', 'c'}),
|
||
|
-- Confirm
|
||
|
['<CR>'] = cmp.mapping(cmp.mapping.confirm { select = false }, {'i', 'c'}),
|
||
|
},
|
||
|
sources = {
|
||
|
{ name = 'path' },
|
||
|
{ name = 'nvim_lsp' },
|
||
|
{ name = 'vsnip' },
|
||
|
},
|
||
|
-- Experimental features
|
||
|
experimental = {
|
||
|
-- Show completion result as virtual text
|
||
|
ghost_text = true,
|
||
|
},
|
||
|
}
|
||
|
local capabilities = require'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
||
|
|
||
|
---- lsp: language servers ----
|
||
|
--- Performs keymaps and other setup specific to buffers with LSP enabled
|
||
|
--- @param bufnr number
|
||
|
local function on_attach(_client, bufnr)
|
||
|
-- keybinding settings
|
||
|
local opts = { noremap = true, silent = true }
|
||
|
-- keybinding shorthand
|
||
|
local function bufmap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
|
||
|
|
||
|
require'which-key'.register({
|
||
|
g = {
|
||
|
d = {'<Cmd>lua vim.lsp.buf.definition()<CR>', 'Goto definition'},
|
||
|
D = {'<Cmd>lua vim.lsp.buf.implementation()<CR>', 'Goto implementation'},
|
||
|
a = {'<Cmd>lua vim.lsp.buf.code_action()<CR>', 'Code action'},
|
||
|
R = {'<Cmd>lua vim.lsp.buf.rename()<CR>', 'Rename'},
|
||
|
y = {'<Cmd>lua vim.lsp.buf.type_definition()<CR>', 'Type definition'},
|
||
|
},
|
||
|
[']'] = {
|
||
|
g = {'<Cmd>lua vim.diagnostic.goto_next()<CR>', 'Next diagnostic'},
|
||
|
e = {'<Cmd>lua vim.diagnostic.goto_next { severity = vim.diagnostic.severity.ERROR }<CR>', 'Next error'},
|
||
|
w = {'<Cmd>lua vim.diagnostic.goto_next { severity = vim.diagnostic.severity.WARN }<CR>', 'Next warning'},
|
||
|
q = {'<Cmd>lua vim.diagnostic.setqflist()<CR>', 'Quickfix diagnostics'},
|
||
|
},
|
||
|
['['] = {
|
||
|
g = {'<Cmd>lua vim.diagnostic.goto_prev()<CR>', 'Previous diagnostic'},
|
||
|
e = {'<Cmd>lua vim.diagnostic.goto_prev { severity = vim.diagnostic.severity.ERROR }<CR>', 'Previous error'},
|
||
|
w = {'<Cmd>lua vim.diagnostic.goto_prev { severity = vim.diagnostic.severity.WARN }<CR>', 'Previous warning'},
|
||
|
}
|
||
|
}, {buffer = bufnr})
|
||
|
-- Hover
|
||
|
bufmap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
||
|
bufmap('n', '<c-k>', '<Cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||
|
bufmap('i', '<M-k>', '<Cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||
|
|
||
|
vim.bo.tagfunc = 'v:lua.vim.lsp.tagfunc'
|
||
|
end
|
||
|
|
||
|
-- Enable language servers
|
||
|
local default = {
|
||
|
capabilities = capabilities,
|
||
|
on_attach = on_attach,
|
||
|
}
|
||
|
|
||
|
local runtime_path = vim.split(package.path, ';')
|
||
|
table.insert(runtime_path, 'lua/?.lua')
|
||
|
table.insert(runtime_path, 'lua/?/init.lua')
|
||
|
require'lspconfig'.sumneko_lua.setup {
|
||
|
capabilities = capabilities,
|
||
|
on_attach = on_attach,
|
||
|
settings = {
|
||
|
Lua = {
|
||
|
runtime = {
|
||
|
version = 'LuaJIT',
|
||
|
path = runtime_path,
|
||
|
},
|
||
|
diagnostics = {
|
||
|
globals = {'vim'},
|
||
|
},
|
||
|
workspace = {
|
||
|
library = vim.api.nvim_get_runtime_file('', true),
|
||
|
},
|
||
|
telemetry = {
|
||
|
enable = false,
|
||
|
},
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
require'lspconfig'.bashls.setup(default)
|
||
|
require'lspconfig'.clangd.setup(default)
|
||
|
require'lspconfig'.tsserver.setup(default)
|
||
|
require'lspconfig'.vimls.setup(default)
|
||
|
|
||
|
-- Completion menu bahevior
|
||
|
vim.opt.completeopt:append({'menuone', 'noinsert', 'noselect'})
|
||
|
|
||
|
|
||
|
---- markdown ----
|
||
|
g.vim_markdown_folding_disabled = 1
|
||
|
g.vim_markdown_conceal = 1
|
||
|
g.tex_conceal = ""
|
||
|
g.vim_markdown_math = 1
|
||
|
|
||
|
|
||
|
---- rust ----
|
||
|
-- Don't use recommended style (space indent, textwidth=99)
|
||
|
g.rust_recommended_style = 0
|
||
|
-- Format with rustfmt on save
|
||
|
g.rustfmt_autosave = 1
|
||
|
-- Use nigtly rustfmt for unstable settings
|
||
|
g.rustfmt_command = 'rustup run nightly rustfmt'
|
||
|
|
||
|
-- use cargo-lints if available
|
||
|
local checkOnSave = {};
|
||
|
if fn.executable('cargo-lints') == 1 then
|
||
|
checkOnSave = {
|
||
|
overrideCommand = {"cargo", "lints", "clippy", "--workspace", "--message-format=json", "--all-targets"}
|
||
|
}
|
||
|
else
|
||
|
checkOnSave = {
|
||
|
-- Use clippy for error checking
|
||
|
command = "clippy",
|
||
|
-- Also run checks for tests
|
||
|
allTargets = true,
|
||
|
}
|
||
|
end
|
||
|
---- rust-tools ----
|
||
|
require'rust-tools'.setup {
|
||
|
tools = {
|
||
|
-- Automatically set inlay hints
|
||
|
autoSetHints = true,
|
||
|
-- Don't replace hover handler
|
||
|
hover_with_actions = false,
|
||
|
-- Configure inlay hints
|
||
|
inlay_hints = {
|
||
|
-- Only show hints for the current line
|
||
|
only_current_line = true,
|
||
|
-- AutoCmd to use for updating hints. CursorMove is more responsive but expensive.
|
||
|
only_current_line_autocmd = 'CursorMoved',
|
||
|
},
|
||
|
},
|
||
|
server = {
|
||
|
-- Enable standalone file (i.e. no cargo) support
|
||
|
standalone = true,
|
||
|
capabilities = capabilities,
|
||
|
on_attach = on_attach,
|
||
|
settings = {
|
||
|
['rust-analyzer'] = {
|
||
|
cargo = {
|
||
|
-- Load OUT_DIR when running check on save, needed for proc macros
|
||
|
loadOutDirsFromCheck = true,
|
||
|
},
|
||
|
checkOnSave = checkOnSave,
|
||
|
diagnostics = {
|
||
|
-- Disable diagnostics with false positives
|
||
|
disabled = {'unresolved-import'};
|
||
|
},
|
||
|
procMacro = {
|
||
|
-- Enable proc macro support
|
||
|
enable = true,
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
---- startify ----
|
||
|
g.startify_change_to_dir = 0 -- Don't change working directory when opening files
|
||
|
g.startify_change_to_vcs_root = 1 -- Change working dir to version control root
|
||
|
g.startify_fortune_use_unicode = 1 -- Enable unicode box drawing in fortune message
|
||
|
-- Items to show on the startup screen
|
||
|
g.startify_lists = {
|
||
|
{ type = 'dir', header = {' Recently used '.. fn.getcwd()} },
|
||
|
{ type = 'files', header = {' Recently used'} },
|
||
|
{ type = 'sessions', header = {' Sessions'} },
|
||
|
{ type = 'bookmarks', header = {' Bookmarks'} },
|
||
|
{ type = 'commands', header = {' Commands'} },
|
||
|
}
|
||
|
|
||
|
|
||
|
---- symbols-outline ----
|
||
|
vim.g.symbols_outline = {
|
||
|
-- Don't display preview automatically
|
||
|
auto_preview = false,
|
||
|
-- Don't highlight the hovered item
|
||
|
highlight_hovered_item = false,
|
||
|
-- Width should be in colums, not percent
|
||
|
relative_width = false,
|
||
|
-- width of the symbols window
|
||
|
width = 30,
|
||
|
}
|
||
|
require'which-key'.register({['<Leader>o'] = {'<Cmd>SymbolsOutline<CR>', 'Symbols outline'}})
|
||
|
|
||
|
|
||
|
---- tree ----
|
||
|
require('nvim-tree').setup {
|
||
|
actions = {
|
||
|
open_file = {
|
||
|
window_picker = {
|
||
|
exclude = {
|
||
|
filetype = {'Outline'},
|
||
|
},
|
||
|
}
|
||
|
},
|
||
|
},
|
||
|
-- Don't disable netrw
|
||
|
disable_netrw = false,
|
||
|
-- Show LSP diagnostics in the sign column
|
||
|
diagnostics = {
|
||
|
enable = true,
|
||
|
},
|
||
|
git = {
|
||
|
-- Don't hide .gitignore'd files by default
|
||
|
ignore = false,
|
||
|
},
|
||
|
-- Reload the tree when its window is focused
|
||
|
reload_on_bufenter = true,
|
||
|
-- Appeareance settings
|
||
|
renderer = {
|
||
|
-- highlight git status (unstaged, staged, clean)
|
||
|
highlight_git = true,
|
||
|
-- Highlight open files
|
||
|
highlight_opened_files = 'name',
|
||
|
-- Don't hightlight files as spceial
|
||
|
special_files = {},
|
||
|
-- Icon settings
|
||
|
icons = {
|
||
|
-- Hide git attribute icons
|
||
|
show = {
|
||
|
git = false,
|
||
|
folder = true,
|
||
|
file = true,
|
||
|
folder_arrow = true,
|
||
|
},
|
||
|
-- Change icons
|
||
|
glyphs = {
|
||
|
-- Set a default icon so entries are aligned
|
||
|
default = '🗋'
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
-- Open on startup
|
||
|
open_on_setup = true,
|
||
|
-- Match tree cwd to vim's cwd
|
||
|
update_cwd = true,
|
||
|
-- When a file is BufEnter'ed, focus it in the tree
|
||
|
update_focused_file = {
|
||
|
enable = true,
|
||
|
ignore_list = {'fugitive'}
|
||
|
}
|
||
|
}
|
||
|
vim.cmd'highlight NvimTreeOpenedFile guifg=NONE gui=italic'
|
||
|
|
||
|
require'which-key'.register{['<Leader>t'] = {'<Cmd>NvimTreeToggle<CR>', 'Nvim Tree'}}
|
||
|
|
||
|
|
||
|
---- treesitter ----
|
||
|
require'nvim-treesitter.configs'.setup {
|
||
|
-- Configure the nvim-ts-autotag plugin
|
||
|
autotag = {
|
||
|
enable = true,
|
||
|
},
|
||
|
-- TODO; Pick list manually
|
||
|
ensure_installed = {'lua', 'html', 'c', 'cpp', 'nix', 'vim', 'rust'},
|
||
|
highlight = { enable = true, disable = 'rust' },
|
||
|
incremental_selection = { enable = true },
|
||
|
}
|
||
|
|
||
|
g.nord_italic = 1
|
||
|
g.nord_italicize_comments = 1
|
||
|
g.nord_underline = 1
|
||
|
vim.cmd [[
|
||
|
colorscheme nord
|
||
|
]]
|