began nvim migration to lua
This commit is contained in:
parent
01a46e588f
commit
5ea3f3c345
6 changed files with 513 additions and 0 deletions
5
.config/nvim/init.lua
Normal file
5
.config/nvim/init.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
-- basic settings: ~/.config/nvim/lua/settings.lua
|
||||
require('settings')
|
||||
-- plugins and plugin settings: ~/.config/nvim/lua/plugins.lua
|
||||
require('plugins')
|
||||
|
150
.config/nvim/lua/lsp.lua
Normal file
150
.config/nvim/lua/lsp.lua
Normal file
|
@ -0,0 +1,150 @@
|
|||
local M = {}
|
||||
|
||||
-- lsp_signature
|
||||
M.signature = function()
|
||||
cfg = {
|
||||
Gse_lspsaga = true
|
||||
}
|
||||
end
|
||||
|
||||
-- lspinstall
|
||||
M.lspinstall = function()
|
||||
local function setup_servers()
|
||||
require'lspinstall'.setup()
|
||||
local servers = require'lspinstall'.installed_servers()
|
||||
for _, server in pairs(servers) do
|
||||
require'lspconfig'[server].setup{}
|
||||
end
|
||||
end
|
||||
|
||||
setup_servers()
|
||||
|
||||
-- Automatically reload after `:LspInstall <server>` so we don't have to restart neovim
|
||||
require'lspinstall'.post_install_hook = function ()
|
||||
setup_servers() -- reload installed servers
|
||||
vim.cmd("bufdo e") -- this triggers the FileType autocmd that starts the server
|
||||
end
|
||||
end
|
||||
|
||||
-- treesitter
|
||||
M.treesitter = function ()
|
||||
require'nvim-treesitter.configs'.setup {
|
||||
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
|
||||
--ignore_install = { "javascript", "java" }, -- List of parsers to ignore installing
|
||||
highlight = {
|
||||
enable = true, -- false will disable the whole extension
|
||||
-- disable = { "c", "rust" }, -- list of language that will be disabled
|
||||
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
|
||||
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
|
||||
-- Using this option may slow down your editor, and you may see some duplicate highlights.
|
||||
-- Instead of true it can also be a list of languages
|
||||
additional_vim_regex_highlighting = false,
|
||||
},
|
||||
indent = {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
-- lspkind
|
||||
M.lspkind = function()
|
||||
require('lspkind').init({
|
||||
-- enables text annotations
|
||||
--
|
||||
-- default: true
|
||||
with_text = true,
|
||||
|
||||
-- default symbol map
|
||||
-- can be either 'default' (requires nerd-fonts font) or
|
||||
-- 'codicons' for codicon preset (requires vscode-codicons font)
|
||||
--
|
||||
-- default: 'default'
|
||||
preset = 'codicons',
|
||||
|
||||
-- override preset symbols
|
||||
--
|
||||
-- default: {}
|
||||
symbol_map = {
|
||||
Text = "",
|
||||
Method = "",
|
||||
Function = "",
|
||||
Constructor = "",
|
||||
Field = "ﰠ",
|
||||
Variable = "",
|
||||
Class = "ﴯ",
|
||||
Interface = "",
|
||||
Module = "",
|
||||
Property = "ﰠ",
|
||||
Unit = "塞",
|
||||
Value = "",
|
||||
Enum = "",
|
||||
Keyword = "",
|
||||
Snippet = "",
|
||||
Color = "",
|
||||
File = "",
|
||||
Reference = "",
|
||||
Folder = "",
|
||||
EnumMember = "",
|
||||
Constant = "",
|
||||
Struct = "פּ",
|
||||
Event = "",
|
||||
Operator = "",
|
||||
TypeParameter = ""
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
-- lspconfig
|
||||
M.lspconfig = function()
|
||||
local nvim_lsp = require('lspconfig')
|
||||
|
||||
-- Use an on_attach function to only map the following keys
|
||||
-- after the language server attaches to the current buffer
|
||||
local on_attach = function(client, bufnr)
|
||||
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
|
||||
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
||||
|
||||
-- Enable completion triggered by <c-x><c-o>
|
||||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
|
||||
-- Mappings.
|
||||
local opts = { noremap=true, silent=true }
|
||||
|
||||
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
||||
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
||||
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
||||
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
||||
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
|
||||
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
||||
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
|
||||
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
|
||||
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
|
||||
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
|
||||
buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
||||
|
||||
end
|
||||
|
||||
-- Use a loop to conveniently call 'setup' on multiple servers and
|
||||
-- map buffer local keybindings when the language server attaches
|
||||
local servers = { 'pyright', 'rust_analyzer', 'tsserver' }
|
||||
for _, lsp in ipairs(servers) do
|
||||
nvim_lsp[lsp].setup {
|
||||
on_attach = on_attach,
|
||||
flags = {
|
||||
debounce_text_changes = 150,
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
-- vim:expandtab:tabstop=3:sw=3
|
||||
|
86
.config/nvim/lua/other.lua
Normal file
86
.config/nvim/lua/other.lua
Normal file
|
@ -0,0 +1,86 @@
|
|||
local M = {}
|
||||
|
||||
-- nvimtree
|
||||
M.nvimtree = function ()
|
||||
local tree_cb = require'nvim-tree.config'.nvim_tree_callback
|
||||
-- default mappings
|
||||
vim.g.nvim_tree_bindings = {
|
||||
{ key = {"<CR>", "o", "<2-LeftMouse>"}, cb = tree_cb("edit") },
|
||||
{ key = {"<2-RightMouse>", "<C-]>"}, cb = tree_cb("cd") },
|
||||
{ key = "<C-v>", cb = tree_cb("vsplit") },
|
||||
{ key = "<C-x>", cb = tree_cb("split") },
|
||||
{ key = "<C-t>", cb = tree_cb("tabnew") },
|
||||
{ key = "<", cb = tree_cb("prev_sibling") },
|
||||
{ key = ">", cb = tree_cb("next_sibling") },
|
||||
{ key = "P", cb = tree_cb("parent_node") },
|
||||
{ key = "<BS>", cb = tree_cb("close_node") },
|
||||
{ key = "<S-CR>", cb = tree_cb("close_node") },
|
||||
{ key = "<Tab>", cb = tree_cb("preview") },
|
||||
{ key = "K", cb = tree_cb("first_sibling") },
|
||||
{ key = "J", cb = tree_cb("last_sibling") },
|
||||
{ key = "I", cb = tree_cb("toggle_ignored") },
|
||||
{ key = "H", cb = tree_cb("toggle_dotfiles") },
|
||||
{ key = "R", cb = tree_cb("refresh") },
|
||||
{ key = "a", cb = tree_cb("create") },
|
||||
{ key = "d", cb = tree_cb("remove") },
|
||||
{ key = "r", cb = tree_cb("rename") },
|
||||
{ key = "<C-r>", cb = tree_cb("full_rename") },
|
||||
{ key = "x", cb = tree_cb("cut") },
|
||||
{ key = "c", cb = tree_cb("copy") },
|
||||
{ key = "p", cb = tree_cb("paste") },
|
||||
{ key = "y", cb = tree_cb("copy_name") },
|
||||
{ key = "Y", cb = tree_cb("copy_path") },
|
||||
{ key = "gy", cb = tree_cb("copy_absolute_path") },
|
||||
{ key = "[c", cb = tree_cb("prev_git_item") },
|
||||
{ key = "]c", cb = tree_cb("next_git_item") },
|
||||
{ key = "-", cb = tree_cb("dir_up") },
|
||||
{ key = "s", cb = tree_cb("system_open") },
|
||||
{ key = "q", cb = tree_cb("close") },
|
||||
{ key = "g?", cb = tree_cb("toggle_help") },
|
||||
}
|
||||
end
|
||||
|
||||
-- toggleterm
|
||||
M.toggleterm = function()
|
||||
require("toggleterm").setup{
|
||||
-- size can be a number or function which is passed the current terminal
|
||||
-- size = 20 | function(term)
|
||||
-- if term.direction == "horizontal" then
|
||||
-- return 15
|
||||
-- elseif term.direction == "vertical" then
|
||||
-- return vim.o.columns * 0.4
|
||||
-- end
|
||||
-- end,
|
||||
open_mapping = [[<c-\>]],
|
||||
toggleterm_terminal_mapping = '<Leader>t',
|
||||
hide_numbers = true, -- hide the number column in toggleterm buffers
|
||||
shade_filetypes = {},
|
||||
shade_terminals = true,
|
||||
shading_factor = '1', -- the degree by which to darken to terminal colour, default: 1 for dark backgrounds, 3 for light
|
||||
start_in_insert = true,
|
||||
insert_mappings = true, -- whether or not the open mapping applies in insert mode
|
||||
persist_size = true,
|
||||
direction = 'vertical', -- | 'horizontal' | 'window' | 'float',
|
||||
close_on_exit = true, -- close the terminal window when the process exits
|
||||
-- shell = vim.o.shell, -- change the default shell
|
||||
-- This field is only relevant if direction is set to 'float'
|
||||
float_opts = {
|
||||
-- The border key is *almost* the same as 'nvim_open_win'
|
||||
-- see :h nvim_open_win for details on borders however
|
||||
-- the 'curved' border is a custom border type
|
||||
-- not natively supported but implemented in this plugin.
|
||||
border = 'single',
|
||||
width = 120,
|
||||
height = 32,
|
||||
winblend = 3,
|
||||
highlights = {
|
||||
border = "Normal",
|
||||
background = "Normal",
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
-- vim:expandtab:tabstop=3:sw=3
|
125
.config/nvim/lua/plugins.lua
Normal file
125
.config/nvim/lua/plugins.lua
Normal file
|
@ -0,0 +1,125 @@
|
|||
-- Load plugins
|
||||
-- Bootstrap packer if needed
|
||||
local fn = vim.fn
|
||||
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
|
||||
if fn.empty(fn.glob(install_path)) > 0 then
|
||||
fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
|
||||
vim.cmd 'packadd packer.nvim'
|
||||
end
|
||||
|
||||
return require('packer').startup(function()
|
||||
-- Packer
|
||||
use { -- plugins
|
||||
'wbthomason/packer.nvim'
|
||||
}
|
||||
|
||||
-- Colors
|
||||
use { -- syntax highlighting
|
||||
'nvim-treesitter/nvim-treesitter', run = ':TSUpdate',
|
||||
config = function()
|
||||
require("lsp").treesitter()
|
||||
end,
|
||||
}
|
||||
use { -- onedark theme
|
||||
'navarasu/onedark.nvim',
|
||||
config = function()
|
||||
vim.cmd 'colorscheme onedark'
|
||||
end
|
||||
}
|
||||
use { -- color tag highlighter
|
||||
'norcalli/nvim-colorizer.lua'
|
||||
}
|
||||
|
||||
-- IDE features
|
||||
---- LSP
|
||||
use { -- lsp installer
|
||||
"kabouzeid/nvim-lspinstall",
|
||||
-- opt = true,
|
||||
-- setup = function()
|
||||
-- require("other").packer_lazy_load "nvim-lspinstall"
|
||||
-- -- reload the current file so lsp actually starts for it
|
||||
-- vim.defer_fn(function()
|
||||
-- vim.cmd "silent! e %"
|
||||
-- end, 0)
|
||||
-- end,
|
||||
}
|
||||
use { -- Default LSP configs
|
||||
"neovim/nvim-lspconfig",
|
||||
after = "nvim-lspinstall",
|
||||
config = function()
|
||||
require("lsp").lspconfig()
|
||||
end
|
||||
}
|
||||
use { -- function parameter previews
|
||||
"ray-x/lsp_signature.nvim",
|
||||
after = "nvim-lspconfig",
|
||||
config = function()
|
||||
require("lsp").signature()
|
||||
end,
|
||||
}
|
||||
use { -- Use the % key for more things
|
||||
"andymass/vim-matchup",
|
||||
-- setup = function()
|
||||
-- require("other").packer_lazy_load "vim-matchup"
|
||||
-- end,
|
||||
}
|
||||
use 'dense-analysis/ale'
|
||||
|
||||
---- Other IDE fratures
|
||||
use { -- git integration
|
||||
'lewis6991/gitsigns.nvim',
|
||||
requires = {
|
||||
'nvim-lua/plenary.nvim'
|
||||
},
|
||||
-- config = function()
|
||||
-- require('other').gitsigns()
|
||||
-- end
|
||||
}
|
||||
use { -- file manager
|
||||
'kyazdani42/nvim-tree.lua',
|
||||
requires = 'kyazdani42/nvim-web-devicons',
|
||||
config = function()
|
||||
require('other').nvimtree()
|
||||
end
|
||||
}
|
||||
use { -- terminal
|
||||
"akinsho/toggleterm.nvim",
|
||||
config = function()
|
||||
require('other').toggleterm()
|
||||
end
|
||||
}
|
||||
|
||||
-- Conveniences
|
||||
use { -- Undo tree
|
||||
'mbbill/undotree',
|
||||
}
|
||||
use { -- Quote pairing
|
||||
'jiangmiao/auto-pairs'
|
||||
}
|
||||
use { -- Alignment
|
||||
'junegunn/vim-easy-align',
|
||||
}
|
||||
use { -- Quote/parenthesis changing
|
||||
'tpope/vim-surround'
|
||||
}
|
||||
-- use { -- Some sensible defaults
|
||||
-- 'tpope/vim-sensible'
|
||||
-- }
|
||||
use { -- Comments
|
||||
'tpope/vim-commentary'
|
||||
}
|
||||
-- use { -- Comments (lua)
|
||||
-- "terrortylor/nvim-comment",
|
||||
-- require('conveniences').nvim_comment()
|
||||
-- }
|
||||
use { -- git integration
|
||||
'tpope/vim-fugitive'
|
||||
}
|
||||
use { -- Repeatability for various tpope plugins
|
||||
'tpope/vim-repeat',
|
||||
}
|
||||
|
||||
end)
|
||||
|
||||
-- vim:fdm=marker:fmr={,}:expandtab:tabstop=3:sw=3
|
||||
|
147
.config/nvim/lua/settings.lua
Normal file
147
.config/nvim/lua/settings.lua
Normal file
|
@ -0,0 +1,147 @@
|
|||
vim.cmd [[
|
||||
set suffixes+=.aux,.bbl,.blg,.brf,.cb,.dvi,.idx,.ilg,.ind,.inx,.jpg,.log,.out,.png,.toc
|
||||
set suffixes-=.h
|
||||
set suffixes-=.obj
|
||||
|
||||
set tabstop=3 softtabstop=3
|
||||
set shiftwidth=3
|
||||
set expandtab
|
||||
set smartindent
|
||||
" set foldmethod=indent
|
||||
" set foldlevel=0
|
||||
|
||||
set undodir=~/.vim/undo
|
||||
set undofile
|
||||
|
||||
set guifont=SauceCodePro\ NF\ Regular
|
||||
|
||||
set hlsearch
|
||||
set hidden
|
||||
set ignorecase
|
||||
set smartcase
|
||||
set wrap
|
||||
set linebreak
|
||||
" set guicursor= " always use the block cursor
|
||||
syntax on
|
||||
set redrawtime=1000 " max syntax highlight time
|
||||
set number relativenumber
|
||||
set noerrorbells
|
||||
set encoding=UTF-8
|
||||
set cursorline
|
||||
set mouse=a
|
||||
set incsearch
|
||||
set scrolloff=6
|
||||
" set wildmenu
|
||||
" set wildmode=full
|
||||
" TextEdit might fail if hidden is not set.
|
||||
set hidden
|
||||
set cmdheight=1 " Give more space for displaying messages.
|
||||
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
|
||||
" delays and poor user experience.
|
||||
set updatetime=300
|
||||
" Don't pass messages to |ins-completion-menu|.
|
||||
set shortmess+=c
|
||||
" Spell check!
|
||||
set spell spelllang=en_us
|
||||
" spell check in git commits
|
||||
autocmd Filetype gitcommit setlocal spell
|
||||
set showcmd
|
||||
set signcolumn=yes
|
||||
" disable spell check in help files
|
||||
autocmd FileType help setlocal nospell
|
||||
filetype plugin on
|
||||
" Macro for opening a new terminal with spell check off
|
||||
command! Term tabnew | setlocal nospell | term
|
||||
autocmd FileType help setlocal nospell
|
||||
" test whitespace ->
|
||||
" more test whitespace ->
|
||||
" Indented text
|
||||
" even more test whitespace ->
|
||||
|
||||
" Key bindings
|
||||
let mapleader = " "
|
||||
" *sigh*...
|
||||
command! Q q
|
||||
command! W w
|
||||
command! Wq wq
|
||||
command! WQ wq
|
||||
" nnoremap ; :
|
||||
" vnoremap ; :
|
||||
" Press Alt h to toggle highlighting on/off, and show current value.
|
||||
noremap <M-h> :set hlsearch! hlsearch?<CR>
|
||||
" Escape to enter normal mode in the terminal
|
||||
tnoremap <Esc> <C-\><C-n>
|
||||
" Replace with alt S
|
||||
nnoremap <M-s> :%s//g<Left><Left>
|
||||
" Wrapped line movement (hold ctrl to move like a word processor)
|
||||
nmap <C-h> h
|
||||
nmap <C-j> gj
|
||||
nmap <C-k> gk
|
||||
nmap <C-l> l
|
||||
" nmap <C-4> g$
|
||||
nmap <C>$ g$
|
||||
nmap <C-6> g^
|
||||
nmap <C-^> g^
|
||||
nmap <C-0> g^
|
||||
vmap <C-h> h
|
||||
vmap <C-j> gj
|
||||
vmap <C-k> gk
|
||||
vmap <C-l> l
|
||||
vmap <C-4> g$
|
||||
vmap <C>$ g$
|
||||
vmap <C-6> g^
|
||||
vmap <C-^> g^
|
||||
vmap <C-0> g^
|
||||
" " Hold ctrl to move between windows, shift to reorder the windows
|
||||
" nmap <C-h> <C-w>h
|
||||
" nmap <C-j> <C-w>j
|
||||
" nmap <C-k> <C-w>k
|
||||
" nmap <C-l> <C-w>l
|
||||
" nmap <C-H> <C-w>H
|
||||
" nmap <C-J> <C-w>J
|
||||
" nmap <C-K> <C-w>K
|
||||
" nmap <C-L> <C-w>L
|
||||
" " and for visual mode
|
||||
" vmap <C-h> <C-w>h
|
||||
" vmap <C-j> <C-w>j
|
||||
" vmap <C-k> <C-w>k
|
||||
" vmap <C-l> <C-w>l
|
||||
" vmap <C-H> <C-w>H
|
||||
" vmap <C-J> <C-w>J
|
||||
" vmap <C-K> <C-w>K
|
||||
" vmap <C-L> <C-w>L
|
||||
|
||||
colorscheme slate
|
||||
]]
|
||||
|
||||
vim.cmd [[
|
||||
""""""" Quality of life things that aren't one line (also from stack overflow and stuff)
|
||||
"Use 24-bit (true-color) mode in Vim/Neovim when outside tmux.
|
||||
"If you're using tmux version 2.2 or later, you can remove the outermost $TMUX check and use tmux's 24-bit color support
|
||||
"(see < http://sunaku.github.io/tmux-24bit-color.html#usage > for more information.)
|
||||
if (empty($TMUX))
|
||||
if (has("nvim"))
|
||||
"For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
|
||||
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
|
||||
endif
|
||||
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
|
||||
"Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
|
||||
" < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
|
||||
if (has("termguicolors"))
|
||||
set termguicolors
|
||||
endif
|
||||
endif
|
||||
]]
|
||||
|
||||
-- 'Visual At' plugin (https://github.com/stoeffel/.dotfiles/blob/master/vim/visual-at.vim)
|
||||
vim.cmd [[
|
||||
xnoremap @ :<C-u>call ExecuteMacroOverVisualRange()<CR>
|
||||
function! ExecuteMacroOverVisualRange()
|
||||
echo "@".getcmdline()
|
||||
execute ":'<,'>normal @".nr2char(getchar())
|
||||
endfunction
|
||||
]]
|
||||
|
||||
-- Automatically jump to the last position in a file when opening
|
||||
vim.cmd [[ au BufReadPost * if expand('%:p') !~# '\m/\.git/' && line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif ]]
|
||||
|
Loading…
Add table
Reference in a new issue