config: nvim: rewrite config in lua and use packer as plugin manager
This commit is contained in:
parent
07be5a4e7a
commit
6863d4c2eb
11 changed files with 174 additions and 197 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,3 +1,3 @@
|
||||||
zsh/zsh_history
|
zsh/zsh_history
|
||||||
zsh/cache
|
zsh/cache
|
||||||
config/nvim/autoload
|
config/nvim/plugin
|
||||||
|
|
|
||||||
|
|
@ -1,127 +0,0 @@
|
||||||
" disable autocmd
|
|
||||||
set secure
|
|
||||||
|
|
||||||
" file/directory matching
|
|
||||||
set wildmode=list:longest,full
|
|
||||||
" ignore case when completing
|
|
||||||
if exists('+wildignorecase')
|
|
||||||
set wildignorecase
|
|
||||||
endif
|
|
||||||
" ignorelist
|
|
||||||
set wildignore=*.o,*.d,*.so,*.class,*.aux,*.log,*.out,*.toc,*.pdf,*.pyc
|
|
||||||
|
|
||||||
" increase command history
|
|
||||||
set history=1000
|
|
||||||
" increase count of possible undos
|
|
||||||
set undolevels=1000
|
|
||||||
|
|
||||||
" use unix line-endings and recognize dos endings
|
|
||||||
set fileformats=unix,dos
|
|
||||||
|
|
||||||
" tabs
|
|
||||||
set tabstop=4
|
|
||||||
set shiftwidth=4
|
|
||||||
set autoindent
|
|
||||||
set smartindent
|
|
||||||
set smarttab
|
|
||||||
|
|
||||||
" allow backspacing over autoindent and line breaks
|
|
||||||
set backspace=indent,eol,start
|
|
||||||
|
|
||||||
" already display matches while searching
|
|
||||||
set incsearch
|
|
||||||
" only check for case if the searched word contains a capital
|
|
||||||
set ignorecase
|
|
||||||
set smartcase
|
|
||||||
" highlight all matches. use <C-L> to remove the highlights
|
|
||||||
set hlsearch
|
|
||||||
|
|
||||||
" treat hyphenated words as a single word
|
|
||||||
set iskeyword+=-
|
|
||||||
|
|
||||||
" syntax folding
|
|
||||||
if has('folding')
|
|
||||||
set foldmethod=syntax
|
|
||||||
" only use folding when there is enough space
|
|
||||||
" if &columns > 80
|
|
||||||
" set foldcolumn=2
|
|
||||||
" endif
|
|
||||||
set foldlevel=99
|
|
||||||
|
|
||||||
" dont open fold for block movements
|
|
||||||
set foldopen-=block
|
|
||||||
endif
|
|
||||||
|
|
||||||
" allow buffers with changes to be hidden
|
|
||||||
set hidden
|
|
||||||
|
|
||||||
" correct splitting
|
|
||||||
if has('vertsplit')
|
|
||||||
set splitright
|
|
||||||
set splitbelow
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Visual
|
|
||||||
" set text color for dark terminal background
|
|
||||||
set background=dark
|
|
||||||
|
|
||||||
" activate syntax highlighting
|
|
||||||
if has('syntax')
|
|
||||||
syntax enable
|
|
||||||
endif
|
|
||||||
|
|
||||||
" set colorscheme
|
|
||||||
colorscheme dichromatic
|
|
||||||
" TODO: use `colorscheme ron` as fallback?
|
|
||||||
|
|
||||||
" display line at which the current is positioned
|
|
||||||
if exists('+cursorline')
|
|
||||||
set cursorline
|
|
||||||
" remove line and make the line bold instead
|
|
||||||
highlight CursorLine term=bold cterm=bold
|
|
||||||
highlight CursorLineNR term=bold cterm=bold ctermbg=darkgrey
|
|
||||||
endif
|
|
||||||
|
|
||||||
" display warning column at 81 and 121
|
|
||||||
let &colorcolumn="81,121"
|
|
||||||
highlight ColorColumn ctermbg=235 guibg=#2d2d2d
|
|
||||||
|
|
||||||
" display line numbers
|
|
||||||
set number
|
|
||||||
|
|
||||||
" show cursor position all the time
|
|
||||||
set ruler
|
|
||||||
|
|
||||||
" show vim tabs all the time
|
|
||||||
set showtabline=2
|
|
||||||
|
|
||||||
" show currently typed command
|
|
||||||
set showcmd
|
|
||||||
|
|
||||||
" define characters to display when using 'set list'
|
|
||||||
set listchars=tab:→\ ,trail:∙,eol:¬,extends:❯,precedes:❮,nbsp:␣
|
|
||||||
|
|
||||||
" enable nvim-colorizer
|
|
||||||
if has('nvim')
|
|
||||||
set termguicolors
|
|
||||||
lua require'colorizer'.setup()
|
|
||||||
endif
|
|
||||||
|
|
||||||
" increase completion performance and reduce time until timeout
|
|
||||||
set updatetime=300
|
|
||||||
set timeoutlen=500
|
|
||||||
|
|
||||||
" copy paste between vim and everything else
|
|
||||||
set clipboard=unnamedplus
|
|
||||||
|
|
||||||
" Misc
|
|
||||||
set mouse=n
|
|
||||||
|
|
||||||
" remove windows ^M when the encoding gets messed up
|
|
||||||
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
|
|
||||||
|
|
||||||
" autoreload vimrc when writing init.vim
|
|
||||||
au! BufWritePost $MYVIMRC source %
|
|
||||||
|
|
||||||
" add convenience command for force-saving read-only files
|
|
||||||
cmap w!! w !sudo tee %
|
|
||||||
3
config/nvim/init.lua
Normal file
3
config/nvim/init.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
require('general')
|
||||||
|
require('keybindings')
|
||||||
|
require('plugins')
|
||||||
|
|
@ -1,4 +0,0 @@
|
||||||
source $HOME/.config/nvim/plugins.vim
|
|
||||||
source $HOME/.config/nvim/general.vim
|
|
||||||
source $HOME/.config/nvim/keybindings.vim
|
|
||||||
source $HOME/.config/nvim/lsp.vim
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
" allow easier pane switching
|
|
||||||
nnoremap <C-J> <C-W><C-J>
|
|
||||||
nnoremap <C-K> <C-W><C-K>
|
|
||||||
nnoremap <C-L> <C-W><C-L>
|
|
||||||
nnoremap <C-H> <C-W><C-H>
|
|
||||||
|
|
||||||
" allow easier pane resizing
|
|
||||||
nnoremap <M-J> :resize -2<CR>
|
|
||||||
nnoremap <M-K> :resize +2<CR>
|
|
||||||
nnoremap <M-L> :vertical resize -2<CR>
|
|
||||||
nnoremap <M-H> :vertical resize +2<CR>
|
|
||||||
|
|
||||||
" use TAB to switch to next buffers
|
|
||||||
nnoremap <TAB> :bnext<CR>
|
|
||||||
" use Shift-TAB to switch to previous buffers
|
|
||||||
nnoremap <S-TAB> :bprevious<CR>
|
|
||||||
|
|
||||||
" use TAB for completion
|
|
||||||
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>"
|
|
||||||
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<TAB>"
|
|
||||||
|
|
@ -1,25 +0,0 @@
|
||||||
" lsp-config
|
|
||||||
if has('nvim')
|
|
||||||
nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
|
|
||||||
nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>
|
|
||||||
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
|
|
||||||
nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>
|
|
||||||
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
|
|
||||||
nnoremap <silent> <C-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
|
|
||||||
nnoremap <silent> <C-r> <cmd>lua vim.lsp.buf.rename()<CR>
|
|
||||||
nnoremap <silent> <C-n> <cmd>lua vim.lsp.diagnostic.goto_prev()<CR>
|
|
||||||
nnoremap <silent> <C-p> <cmd>lua vim.lsp.diagnostic.goto_next()<CR>
|
|
||||||
|
|
||||||
" auto-format
|
|
||||||
autocmd BufWritePre *.js lua vim.lsp.buf.formatting_sync(nil, 100)
|
|
||||||
autocmd BufWritePre *.jsx lua vim.lsp.buf.formatting_sync(nil, 100)
|
|
||||||
autocmd BufWritePre *.py lua vim.lsp.buf.formatting_sync(nil, 100)
|
|
||||||
|
|
||||||
" setup lsp-providers
|
|
||||||
" (-> need to be installed manually first and then added here)
|
|
||||||
lua require'lspconfig'.ccls.setup{}
|
|
||||||
lua require'lspconfig'.clangd.setup{}
|
|
||||||
lua require'lspconfig'.pyright.setup{}
|
|
||||||
lua require'lspconfig'.bashls.setup{}
|
|
||||||
lua require'lspconfig'.gopls.setup{}
|
|
||||||
endif
|
|
||||||
74
config/nvim/lua/general.lua
Normal file
74
config/nvim/lua/general.lua
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
-- reduce boilerplate by defining some shortcuts
|
||||||
|
local opt = vim.opt
|
||||||
|
local cmd = vim.cmd
|
||||||
|
local autocmd = vim.api.nvim_create_autocmd
|
||||||
|
|
||||||
|
--------------------
|
||||||
|
-- General
|
||||||
|
--------------------
|
||||||
|
opt.mouse = 'n' -- enable mouse support in normal mode
|
||||||
|
opt.clipboard = 'unnamedplus' -- copy/paste to and from system clipboard
|
||||||
|
|
||||||
|
opt.wildmode = 'list:longest,full'
|
||||||
|
opt.wildignorecase = true
|
||||||
|
opt.wildignore = '*.o,*.d,*.so,*.class,*.aux,*.log,*.out,*.toc,*.pdf,*.pyc'
|
||||||
|
|
||||||
|
opt.fileformats = 'unix,dos' -- use identical lineendings for all platforms
|
||||||
|
opt.secure = true -- disable autocmd for security reasons
|
||||||
|
|
||||||
|
--------------------
|
||||||
|
-- Tabs
|
||||||
|
--------------------
|
||||||
|
opt.tabstop = 4 -- 1 tab == N spaces
|
||||||
|
opt.shiftwidth = 4 -- shift N spaces when pressing tab
|
||||||
|
opt.smartindent = true -- take syntax into account for applying indentation
|
||||||
|
|
||||||
|
--------------------
|
||||||
|
-- Search
|
||||||
|
--------------------
|
||||||
|
opt.ignorecase = true -- ignore capitalization on search
|
||||||
|
opt.smartcase = true -- ignore capitalication unless word contains a capital
|
||||||
|
|
||||||
|
opt.iskeyword:append '-' -- treat hyphenated words as a single word
|
||||||
|
|
||||||
|
--------------------
|
||||||
|
-- Neovim UI
|
||||||
|
--------------------
|
||||||
|
opt.number = true -- line numbers
|
||||||
|
opt.ruler = true -- cursor position in statusbar
|
||||||
|
opt.showtabline = 2 -- always show vim tabs
|
||||||
|
opt.showcmd = true -- display currently typed command
|
||||||
|
opt.termguicolors = true -- enable 24-bit RGB color
|
||||||
|
|
||||||
|
-- highlight line at which the cursor is positioned
|
||||||
|
opt.cursorline = true
|
||||||
|
cmd 'highlight CursorLine term=bold cterm=bold'
|
||||||
|
cmd 'highlight CursorLineNR term=bold cterm=bold ctermbg=darkgrey'
|
||||||
|
|
||||||
|
-- display warning column at 81 and 121
|
||||||
|
opt.colorcolumn = '81,121'
|
||||||
|
cmd 'highlight ColorColumn ctermbg=235 guibg=#2d2d2d'
|
||||||
|
|
||||||
|
opt.splitright = true -- horizontal split to the right
|
||||||
|
opt.splitbelow = true -- vertical split to the bottom
|
||||||
|
|
||||||
|
-- define characters to display when using 'set list'
|
||||||
|
opt.listchars = 'tab:→ ,trail:∙,eol:¬,extends:❯,precedes:❮,nbsp:␣'
|
||||||
|
|
||||||
|
--------------------
|
||||||
|
-- Performance
|
||||||
|
--------------------
|
||||||
|
opt.hidden = true -- allow buffers with changes to be hidden
|
||||||
|
opt.updatetime = 300 -- delay (in ms) to wait before triggering event
|
||||||
|
opt.timeoutlen = 500 -- time (in ms) to wait for event to complete
|
||||||
|
opt.history = 10000 -- remember N lines of history
|
||||||
|
|
||||||
|
--------------------
|
||||||
|
-- Misc
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
-- remove redundant whitespaces on save
|
||||||
|
autocmd('BufWritePre', {
|
||||||
|
pattern = '*',
|
||||||
|
command = ':%s/\\s\\+$//e'
|
||||||
|
})
|
||||||
5
config/nvim/lua/keybindings.lua
Normal file
5
config/nvim/lua/keybindings.lua
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
local map = require('utils').map -- import map
|
||||||
|
|
||||||
|
-- allow switching between buffers using tab and Shift-tab
|
||||||
|
map('n', '<TAB>', ':bnext<CR>')
|
||||||
|
map('n', '<S-TAB>', ':bprevious<CR>')
|
||||||
61
config/nvim/lua/plugins.lua
Normal file
61
config/nvim/lua/plugins.lua
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
--------------------
|
||||||
|
-- Packer Bootstrap
|
||||||
|
--------------------
|
||||||
|
local packer_installed, _ = pcall(require, 'packer')
|
||||||
|
local packer_bootstrap = false
|
||||||
|
if (not packer_installed) then
|
||||||
|
-- ask user whether packer should be bootstrapped
|
||||||
|
packer_bootstrap = require('utils').prompt(
|
||||||
|
'Plugin manager packer not found. Install it now?',
|
||||||
|
'Bootstrapping packer now...',
|
||||||
|
'Skipping setup of packer and plugins.')
|
||||||
|
|
||||||
|
if (not packer_bootstrap) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- perform actual bootstrap
|
||||||
|
local fn = vim.fn
|
||||||
|
local install_path = fn.stdpath('data') .. '/site/pack/packer/start/packer.nvim'
|
||||||
|
fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
|
||||||
|
vim.cmd('packadd packer.nvim')
|
||||||
|
end
|
||||||
|
|
||||||
|
-- helper function to be used `config` parameter of packer's use to externalize
|
||||||
|
-- plugin configuration, expects the name of the config file
|
||||||
|
function load_config(name)
|
||||||
|
return string.format('require("plugins/%s")', name)
|
||||||
|
end
|
||||||
|
|
||||||
|
return require('packer').startup({
|
||||||
|
function(use)
|
||||||
|
use 'wbthomason/packer.nvim'
|
||||||
|
|
||||||
|
--------------------
|
||||||
|
-- Visuals
|
||||||
|
--------------------
|
||||||
|
use { -- colorblind-friendly colorscheme
|
||||||
|
'romainl/vim-dichromatic',
|
||||||
|
config = function() vim.cmd('colorscheme dichromatic') end,
|
||||||
|
}
|
||||||
|
use { -- color highlighter
|
||||||
|
'norcalli/nvim-colorizer.lua',
|
||||||
|
config = function() require('colorizer').setup() end,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Automatically set up your configuration after cloning packer.nvim
|
||||||
|
-- Put this at the end after all plugins
|
||||||
|
if packer_bootstrap then
|
||||||
|
require('packer').sync()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
config = {
|
||||||
|
display = {
|
||||||
|
open_fn = require("packer.util").float,
|
||||||
|
},
|
||||||
|
profile = {
|
||||||
|
enable = true,
|
||||||
|
threshold = 1, -- the amount in ms that a plugins load time must be over for it to be included in the profile
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
30
config/nvim/lua/utils.lua
Normal file
30
config/nvim/lua/utils.lua
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
-- keybinding mapper
|
||||||
|
function M.map(mode, lhs, rhs, opts)
|
||||||
|
local options = { noremap = true, silent = true }
|
||||||
|
if opts then
|
||||||
|
options = vim.tbl_extend('force', options, opts)
|
||||||
|
end
|
||||||
|
vim.api.nvim_set_keymap(mode, lhs, rhs, options)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- simple prompt
|
||||||
|
function M.prompt(msg, accept_msg, deny_msg)
|
||||||
|
local answer = vim.fn.input(msg .. ' (YES/no) ')
|
||||||
|
while(true) do
|
||||||
|
-- clear vim cmdline before printing anything
|
||||||
|
vim.cmd('mode')
|
||||||
|
if answer == 'YES' then
|
||||||
|
print(accept_msg)
|
||||||
|
return true
|
||||||
|
elseif string.lower(answer) == 'no' then
|
||||||
|
print(deny_msg)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
-- re-request user input
|
||||||
|
answer = vim.fn.input('Please retry: ' .. msg .. ' (YES/no) ')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
" warn if vim-plug is not available
|
|
||||||
if empty(glob('~/.config/nvim/autoload/plug.vim'))
|
|
||||||
echom "Install https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
|
|
||||||
\ to ~/.config/nvim/autoload/plug.vim"
|
|
||||||
endif
|
|
||||||
|
|
||||||
call plug#begin('~/.config/nvim/autoload/plugged')
|
|
||||||
|
|
||||||
" vim colortheme for colorblind
|
|
||||||
Plug 'romainl/vim-dichromatic'
|
|
||||||
|
|
||||||
" only for nvim!
|
|
||||||
if has('nvim')
|
|
||||||
" language server protocol support
|
|
||||||
Plug 'neovim/nvim-lspconfig'
|
|
||||||
" colorizes colorcodes
|
|
||||||
Plug 'norcalli/nvim-colorizer.lua'
|
|
||||||
endif
|
|
||||||
|
|
||||||
call plug#end()
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue