Migrate neovim config to lua

This commit is contained in:
Fabian Becker 2021-05-19 21:39:28 +02:00
parent 52bbd24071
commit 03fc8f45e6
22 changed files with 699 additions and 527 deletions

View File

@ -1,139 +0,0 @@
" TextEdit might fail if hidden is not set.
set hidden
" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup
" Give more space for displaying messages.
set cmdheight=2
" 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
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("patch-8.1.1564")
" Recently vim can merge signcolumn and number column into one
set signcolumn=number
else
set signcolumn=yes
endif
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
" inoremap <silent><expr> <TAB>
" \ pumvisible() ? "\<C-n>" :
" \ <SID>check_back_space() ? "\<TAB>" :
" \ coc#refresh()
" inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current
" position. Coc only does snippet and additional edit on confirm.
" <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`.
if exists('*complete_info')
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
else
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
endif
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `<leader>aap` for current paragraph
xmap <leader>a <Plug>(coc-codeaction-selected)
nmap <leader>a <Plug>(coc-codeaction-selected)
" Remap keys for applying codeAction to the current buffer.
nmap <leader>ac <Plug>(coc-codeaction)
" Apply AutoFix to problem on the current line.
nmap <leader>qf <Plug>(coc-fix-current)
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver
" nmap <silent> <C-s> <Plug>(coc-range-select)
" xmap <silent> <C-s> <Plug>(coc-range-select)
" IMPORTANT: disabled because they interfere with <C-d> <C-u>
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold', <f-args>)
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
" set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" IMPORTANT: disabled because the statusline is handled by lightline
" Mappings for CoCList - see ./after/plugged/keys.vim

View File

@ -1,28 +0,0 @@
"
" Commands
"
" use fd --type f to only show files not ignored by VCS
command! ProjectFiles call fzf#run(fzf#wrap({'source': 'fd --type f'}))
"
" AutoCMDs
"
" automatically go into insert mode when entering terminal
:au BufEnter * if &buftype == 'terminal' | :startinsert | endif
" force lightline update
autocmd User CocStatusChange,CocDiagnosticChange call lightline#update()
" tsx/jsx filetypes
autocmd BufNewFile,BufRead *.jsx set filetype=javascript.jsx
autocmd BufNewFile,BufRead *.tsx set filetype=typescript.tsx
" autocmd BufNewFile,BufRead *.rs set colorcolumn=80,100
" disable scrolloff in the terminal
autocmd TermOpen,TermEnter * setlocal scrolloff=0
autocmd TermLeave * setlocal scrolloff=8
" autocmd TermOpen * setlocal scrolloff=0

View File

@ -1,162 +0,0 @@
" Keybindings
let mapleader=" "
" use ;; for escape
" http://vim.wikia.com/wiki/Avoid_the_escape_key
inoremap ;; <Esc>
" horizontal split with new buffer
nnoremap <silent> <leader>bh :new<CR>
" vertical split with new buffer
nnoremap <silent> <leader>bv :vnew<CR>
" improved keyboard navigation
nnoremap <leader>h <C-w>h
nnoremap <leader>j <C-w>j
nnoremap <leader>k <C-w>k
nnoremap <leader>l <C-w>l
" Change 2 split windows from vert to horiz or horiz to vert
map <leader>th <C-w>t<C-w>H
map <leader>tk <C-w>t<C-w>K
" Make adjusting split sizes a bit more friendly
noremap <silent> <C-Left> :vertical resize +3<CR>
noremap <silent> <C-Right> :vertical resize -3<CR>
noremap <silent> <C-Up> :resize +3<CR>
noremap <silent> <C-Down> :resize -3<CR>
" improved keyboard support for navigation (especially terminal)
" http://neovim.io/doc/user/nvim_terminal_emulator.html
" tnoremap <Esc> <C-\><C-n>
" tnoremap <A-h> <C-\><C-n><C-w>h
" tnoremap <A-j> <C-\><C-n><C-w>j
" tnoremap <A-k> <C-\><C-n><C-w>k
" tnoremap <A-l> <C-\><C-n><C-w>l
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
if !exists('g:vscode')
" Auto start NERD tree when opening a directory
" autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | wincmd p | endif
" Auto start NERD tree if no files are specified
" autocmd StdinReadPre * let s:std_in=1
" autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | exe 'NERDTree' | endif
" Let quit work as expected if after entering :q the only window left open is NERD Tree itself
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" Shortcut to edit THIS configuration file: (e)dit (c)onfiguration
nnoremap <silent> <leader>ec :e $MYVIMRC<CR>
" Shortcut to source (reload) THIS configuration file after editing it: (s)ource (c)onfiguraiton
nnoremap <silent> <leader>sc :source $MYVIMRC<CR>
" Toggle NERDTree
" Can't get <C-Space> by itself to work, so this works as Ctrl - space - space
" https://github.com/neovim/neovim/issues/3101
" http://stackoverflow.com/questions/7722177/how-do-i-map-ctrl-x-ctrl-o-to-ctrl-space-in-terminal-vim#answer-24550772
"nnoremap <C-Space> :NERDTreeToggle<CR>
"nmap <C-@> <C-Space>
nnoremap <silent> <M-b> :NERDTreeToggle<CR>
" toggle tagbar
nnoremap <silent> <leader>tb :TagbarToggle<CR>
" toggle line numbers
nnoremap <silent> <leader>n :set number! number?<CR>
" toggle line wrap
nnoremap <silent> <leader>w :set wrap! wrap?<CR>
" toggle buffer (switch between current and last buffer)
nnoremap <silent> <leader>bb <C-^>
" go to next buffer
nnoremap <silent> <leader>bn :bn<CR>
nnoremap <C-l> :bn<CR>
" go to previous buffer
nnoremap <silent> <leader>bp :bp<CR>
" https://github.com/neovim/neovim/issues/2048
nnoremap <C-h> :bp<CR>
" close buffer
nnoremap <silent> <leader>bd :bd<CR>
" kill buffer
nnoremap <silent> <leader>bk :bd!<CR>
" list buffers
nnoremap <silent> <leader>bl :ls<CR>
" list and select buffer
nnoremap <silent> <leader>bg :ls<CR>:buffer<Space>
" TELESCOPE
" Find files using Telescope command-line sugar.
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
" Maps display of current buffers
nnoremap <C-b> <cmd>Telescope buffers<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
" Telescope project
nnoremap <silent> <leader>fp :Telescope project<CR>
let s:hidden_all = 0
function! ToggleHiddenAll()
if s:hidden_all == 0
let s:hidden_all = 1
set noshowmode
set noruler
set laststatus=0
set noshowcmd
TagbarClose
NERDTreeClose
else
let s:hidden_all = 0
set showmode
set ruler
set laststatus=2
set showcmd
NERDTree
" NERDTree takes focus, so move focus back to the right
" (note: "l" is lowercase L (mapped to moving right)
wincmd l
TagbarOpen
endif
endfunction
" nnoremap <silent> <leader>h :call ToggleHiddenAll()<CR>
nnoremap <silent> <F9> :FloatermNew --height=0.4 --width=0.98 --wintype=floating --position=bottom --autoclose=2 --title=
tnoremap <silent> <F9> <C-\><C-n>:FloatermNew --height=0.4 --width=0.98 --wintype=floating --position=bottom --autoclose=2 --title=
nnoremap <silent> <F8> :FloatermPrev<CR>
tnoremap <silent> <F8> <C-\><C-n>:FloatermPrev<CR>
nnoremap <silent> <F10> :FloatermNext<CR>
tnoremap <silent> <F10> <C-\><C-n>:FloatermNext<CR>
inoremap <silent> <F11> <C-c>:FloatermToggle<CR>
nnoremap <silent> <F11> :FloatermToggle<CR>
tnoremap <silent> <F11> <C-\><C-n>:FloatermToggle<CR>
tnoremap <silent> <M-o> <C-\><C-n><CR>
nnoremap <C-c><C-c> :FloatermSend<CR>
vnoremap <C-c><C-c> :FloatermSend<CR>
" Automatic formatting for Julia files
autocmd FileType julia nnoremap <buffer> <c-f> :JuliaFormatterFormat<cr>
" Maps quit
noremap <leader>q :q<cr>
" Maps quit all
noremap <c-q> :qa<cr>
" Maps write
nnoremap <leader>w :w<cr>
end

View File

@ -1,32 +0,0 @@
set background=dark
set clipboard+=unnamedplus
" set colorcolumn=80
set ignorecase smartcase
set incsearch
set list listchars=tab:⇒\ ,trail
set mouse+=a
set noswapfile
set nowrap
set number
set relativenumber
set scrolloff=8
set termguicolors
" Set tabstop and shiftwidth to 4 spaces
set expandtab ts=4 sw=4 ai
" hide mode as it's shown in lightline
set noshowmode
syntax on
" open new split panes to right and below (as you probably expect)
set splitright
set splitbelow
" colorscheme nord
" colorscheme dracula
colorscheme moonlight
" terminal disable linenumber
au TermOpen * setlocal nonumber norelativenumber

View File

@ -1,40 +0,0 @@
{
"explorer.icon.enableNerdfont": true,
"java.format.enabled": false,
"rust-analyzer.updates.channel": "nightly",
"coc.preferences.formatOnSaveFiletypes": [
"cs",
"html",
"java",
"javascript",
"json",
"go",
"python",
"rust",
"scala",
"typescript",
"typescript.tsx",
"typescriptreact",
"vue",
"xml"
],
"languageserver": {
"go": {
"command": "gopls",
"rootPatterns": [
"go.mod"
],
"trace.server": "verbose",
"filetypes": [
"go"
]
}
},
"python.formatting.provider": "black",
"python.formatting.blackArgs": [
"--line-length",
"120"
],
"python.linting.flake8Enabled": true,
"pyright.enable": true
}

21
.config/nvim/init.lua Normal file
View File

@ -0,0 +1,21 @@
require('globals')
require('keymappings')
require('settings')
-- Convert to lua
vim.cmd('source ~/.config/nvim/vim-plug/plugins.vim')
require('colorscheme')
require('lsp')
require('lsp.docker-ls')
require('lsp.python-ls')
require('lsp.julia-ls')
require('lsp.json-ls')
require('lsp.elixir-ls')
require('lsp.go-ls')
require('lsp.terraform-ls')
require('plugins.telescope')
require('plugins.compe')
require('plugins.which-key')

View File

@ -1,126 +0,0 @@
call plug#begin()
Plug 'airblade/vim-gitgutter'
" Plug 'andymass/vim-matchup'
Plug 'editorconfig/editorconfig-vim'
Plug 'junegunn/vim-easy-align'
" Multiple cursors for editing
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'edkolev/tmuxline.vim'
Plug 'majutsushi/tagbar'
let g:tagbar_ctags_bin = '/usr/local/bin/ctags'
Plug 'itchyny/lightline.vim'
let g:lightline = {
\ 'colorscheme': 'challenger_deep',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'cocstatus', 'readonly', 'gitbranch', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'cocstatus': 'coc#status',
\ 'gitbranch': 'FugitiveHead',
\ },
\ 'separator': { 'left': "\ue0b0", 'right': "\ue0b2" },
\ 'subseparator': { 'left': "\ue0b1", 'right': "\ue0b3" }
\ }
Plug 'airblade/vim-rooter'
let g:rooter_manual_only = 1
Plug 'justinmk/vim-sneak'
let g:sneak#label = 1
Plug 'machakann/vim-highlightedyank'
let g:highlightedyank_highlight_duration = 100
" Easy commenting for Vim
Plug 'preservim/nerdcommenter'
" Indentation lines
Plug 'Yggdroot/indentLine'
Plug 'lukas-reineke/indent-blankline.nvim'
" NERD Tree - tree explorer
" https://github.com/scrooloose/nerdtree
" http://usevim.com/2012/07/18/nerdtree/
" (loaded on first invocation of the command)
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'ryanoasis/vim-devicons'
" nerdtree-git-plugin - show git status in NERD Tree
" https://github.com/Xuyuanp/nerdtree-git-plugi
Plug 'Xuyuanp/nerdtree-git-plugin'
" Enforce editor settings
" https://github.com/editorconfig/editorconfig-vim
Plug 'editorconfig/editorconfig-vim'
" Terminal in floating window
Plug 'voldikss/vim-floaterm'
" Telescope fuzzy find files/grep
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-project.nvim'
"""""""""""""""""""""""""
" => Language Support
"""""""""""""""""""""""""
Plug 'neoclide/jsonc.vim'
Plug 'vim-python/python-syntax'
let g:python_highlight_all = 1
Plug 'JuliaEditorSupport/julia-vim'
let g:latex_to_unicode_auto = 1
" Formatting Julia Files
Plug 'kdheepak/JuliaFormatter.vim'
" themes & colorschemes
Plug 'challenger-deep-theme/vim', { 'as': 'challenger-deep' }
Plug 'dracula/vim', { 'as': 'dracula' }
Plug 'arcticicestudio/nord-vim'
let g:nord_cursor_line_number_background = 1
let g:nord_bold = 1
let g:nord_italic = 1
let g:nord_italic_comments = 1
Plug 'shaunsingh/moonlight.nvim'
call plug#end()
""""""""""""""""""""""""""""""
" PLUGIN SETTINGS
""""""""""""""""""""""""""""""
""""""""""""""""""""""""""""""
" VIM-FLOATERM
""""""""""""""""""""""""""""""
let g:floaterm_open_command = 'vsplit'
"""""""""""""""""""""
"JULIA FORMATTER
"""""""""""""""""""""
let g:JuliaFormatter_options = {
\ 'indent' : 4,
\ 'margin' : 92,
\ 'always_for_in' : v:false,
\ 'whitespace_typedefs' : v:false,
\ 'whitespace_ops_in_indices' : v:true,
\ }

View File

@ -0,0 +1,3 @@
vim.cmd('let g:nvcode_termcolors=256')
vim.cmd('colorscheme ' .. O.colorscheme)

View File

@ -0,0 +1,70 @@
O = {
auto_close_tree = 0,
auto_complete = true,
background = dark,
ignorecase = smartcase,
clipboard = unnamedplus,
incsearch = true,
termguicolors = true,
colorscheme = 'moonlight',
hidden_files = true,
wrap_lines = false,
number = true,
relative_number = true,
shell = 'zsh',
timeoutlen = 100,
number = true,
scrolloff = 8,
noshowmode = true,
splitright = true,
splitbelow = true,
database = {save_location = '~/.config/nvcode_db', auto_execute = 1},
python = {
linter = 'flake8',
-- @usage can be 'yapf', 'black'
formatter = 'black',
autoformat = false,
isort = false,
diagnostics = {virtual_text = {spacing = 0, prefix = ""}, signs = true, underline = true},
analysis = {type_checking = "basic", auto_search_paths = true, use_library_code_types = true}
},
lua = {
-- @usage can be 'lua-format'
formatter = '',
autoformat = false,
diagnostics = {virtual_text = {spacing = 0, prefix = ""}, signs = true, underline = true}
},
sh = {
-- @usage can be 'shellcheck'
linter = '',
-- @usage can be 'shfmt'
formatter = '',
autoformat = false,
diagnostics = {virtual_text = {spacing = 0, prefix = ""}, signs = true, underline = true}
},
tsserver = {
-- @usage can be 'eslint'
linter = '',
-- @usage can be 'prettier'
formatter = '',
autoformat = false,
diagnostics = {virtual_text = {spacing = 0, prefix = ""}, signs = true, underline = true}
},
json = {
-- @usage can be 'prettier'
formatter = '',
autoformat = false,
diagnostics = {virtual_text = {spacing = 0, prefix = ""}, signs = true, underline = true}
},
clang = {diagnostics = {virtual_text = {spacing = 0, prefix = ""}, signs = true, underline = true}},
ruby = {
diagnostics = {virtualtext = {spacing = 0, prefix = ""}, signs = true, underline = true},
filetypes = {'rb', 'erb', 'rakefile'}
},
-- css = {formatter = '', autoformat = false, virtual_text = true},
-- json = {formatter = '', autoformat = false, virtual_text = true}
}
DATA_PATH = vim.fn.stdpath('data')
CACHE_PATH = vim.fn.stdpath('cache')

View File

@ -0,0 +1,155 @@
vim.g.mapleader = ' '
-- TODO find better place
vim.g.floaterm_open_command = 'vsplit'
-- better window movement
vim.api.nvim_set_keymap('n', '<C-h>', '<C-w>h', {silent = true})
vim.api.nvim_set_keymap('n', '<C-j>', '<C-w>j', {silent = true})
vim.api.nvim_set_keymap('n', '<C-k>', '<C-w>k', {silent = true})
vim.api.nvim_set_keymap('n', '<C-l>', '<C-w>l', {silent = true})
-- TODO fix this
-- Terminal window navigation
vim.cmd([[
tnoremap <C-h> <C-\><C-N><C-w>h
tnoremap <C-j> <C-\><C-N><C-w>j
tnoremap <C-k> <C-\><C-N><C-w>k
tnoremap <C-l> <C-\><C-N><C-w>l
inoremap <C-h> <C-\><C-N><C-w>h
inoremap <C-j> <C-\><C-N><C-w>j
inoremap <C-k> <C-\><C-N><C-w>k
inoremap <C-l> <C-\><C-N><C-w>l
tnoremap <Esc> <C-\><C-n>
]])
-- TODO fix this
-- resize with arrows
vim.cmd([[
nnoremap <silent> <C-Up> :resize -2<CR>
nnoremap <silent> <C-Down> :resize +2<CR>
nnoremap <silent> <C-Left> :vertical resize +2<CR>
nnoremap <silent> <C-Right> :vertical resize -2<CR>
]])
-- improved keyboard support for navigation (especially terminal)
vim.cmd([[
nnoremap <leader>h <C-w>h
nnoremap <leader>j <C-w>j
nnoremap <leader>k <C-w>k
nnoremap <leader>l <C-w>l
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
]])
-- Change 2 split windows from vert to horiz or horiz to vert
vim.cmd([[
map <leader>th <C-w>t<C-w>H
map <leader>tk <C-w>t<C-w>K
]])
-- Make adjusting split sizes a bit more friendly
vim.cmd([[
noremap <silent> <C-Left> :vertical resize +3<CR>
noremap <silent> <C-Right> :vertical resize -3<CR>
noremap <silent> <C-Up> :resize +3<CR>
noremap <silent> <C-Down> :resize -3<CR>
]])
-- FloatTerm
vim.cmd([[
nnoremap <silent> <F9> :FloatermNew --height=0.4 --width=0.98 --wintype=floating --position=bottom --autoclose=2 --title=
tnoremap <silent> <F9> <C-\><C-n>:FloatermNew --height=0.4 --width=0.98 --wintype=floating --position=bottom --autoclose=2 --title=
nnoremap <silent> <F8> :FloatermPrev<CR>
tnoremap <silent> <F8> <C-\><C-n>:FloatermPrev<CR>
nnoremap <silent> <F10> :FloatermNext<CR>
tnoremap <silent> <F10> <C-\><C-n>:FloatermNext<CR>
inoremap <silent> <F11> <C-c>:FloatermToggle<CR>
nnoremap <silent> <F11> :FloatermToggle<CR>
tnoremap <silent> <F11> <C-\><C-n>:FloatermToggle<CR>
tnoremap <silent> <M-o> <C-\><C-n><CR>
nnoremap <C-c><C-c> :FloatermSend<CR>
vnoremap <C-c><C-c> :FloatermSend<CR>
]])
-- Telescope
vim.cmd([[
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <C-b> <cmd>Telescope buffers<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
]])
-- better indenting
vim.api.nvim_set_keymap('v', '<', '<gv', {noremap = true, silent = true})
vim.api.nvim_set_keymap('v', '>', '>gv', {noremap = true, silent = true})
-- I hate escape
vim.api.nvim_set_keymap('i', 'jk', '<ESC>', {noremap = true, silent = true})
vim.api.nvim_set_keymap('i', 'kj', '<ESC>', {noremap = true, silent = true})
vim.api.nvim_set_keymap('i', 'jj', '<ESC>', {noremap = true, silent = true})
-- Tab switch buffer
vim.api.nvim_set_keymap('n', '<TAB>', ':bnext<CR>', {noremap = true, silent = true})
vim.api.nvim_set_keymap('n', '<S-TAB>', ':bprevious<CR>', {noremap = true, silent = true})
-- Move selected line / block of text in visual mode
vim.api.nvim_set_keymap('x', 'K', ':move \'<-2<CR>gv-gv', {noremap = true, silent = true})
vim.api.nvim_set_keymap('x', 'J', ':move \'>+1<CR>gv-gv', {noremap = true, silent = true})
vim.cmd([[
if !exists('g:vscode')
" Let quit work as expected if after entering :q the only window left open is NERD Tree itself
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" Toggle NERDTree
" Can't get <C-Space> by itself to work, so this works as Ctrl - space - space
" https://github.com/neovim/neovim/issues/3101
" http://stackoverflow.com/questions/7722177/how-do-i-map-ctrl-x-ctrl-o-to-ctrl-space-in-terminal-vim#answer-24550772
"nnoremap <C-Space> :NERDTreeToggle<CR>
"nmap <C-@> <C-Space>
"nnoremap <silent> <M-b> :NERDTreeToggle<CR>
" toggle tagbar
nnoremap <silent> <leader>tb :TagbarToggle<CR>
" toggle line wrap
nnoremap <silent> <leader>w :set wrap! wrap?<CR>
" toggle buffer (switch between current and last buffer)
nnoremap <silent> <leader>bb <C-^>
" close buffer
nnoremap <silent> <leader>bd :bd<CR>
" kill buffer
nnoremap <silent> <leader>bk :bd!<CR>
" list buffers
nnoremap <silent> <leader>bl :ls<CR>
" list and select buffer
nnoremap <silent> <leader>bg :ls<CR>:buffer<Space>
" Telescope project
nnoremap <silent> <leader>fp :Telescope project<CR>
" Automatic formatting for Julia files
autocmd FileType julia nnoremap <buffer> <c-f> :JuliaFormatterFormat<cr>
" Maps quit
noremap <leader>q :q<cr>
" Maps quit all
noremap <c-q> :qa<cr>
" Maps write
nnoremap <leader>w :w<cr>
end
]])

View File

@ -0,0 +1,6 @@
-- npm install -g dockerfile-language-server-nodejs
require'lspconfig'.dockerls.setup {
cmd = {DATA_PATH .. "/lspinstall/dockerfile/node_modules/.bin/docker-langserver", "--stdio"},
on_attach = require'lsp'.common_on_attach,
root_dir = vim.loop.cwd
}

View File

@ -0,0 +1,10 @@
require'lspconfig'.elixirls.setup{
cmd = { DATA_PATH .. "/lspinstall/elixir/elixir-ls/language_server.sh"};
}
-- needed for the LSP to recognize elixir files (alternativly just use elixir-editors/vim-elixir)
vim.cmd([[
au BufRead,BufNewFile *.ex,*.exs set filetype=elixir
au BufRead,BufNewFile *.eex,*.leex,*.sface set filetype=eelixir
au BufRead,BufNewFile mix.lock set filetype=elixir
]])

View File

@ -0,0 +1,7 @@
require'lspconfig'.gopls.setup{
cmd = {DATA_PATH .. "/lspinstall/go/gopls"},
settings = {gopls = {analyses = {unusedparams = true}, staticcheck = true}},
root_dir = require'lspconfig'.util.root_pattern(".git","go.mod","."),
init_options = {usePlaceholders = true, completeUnimported = true},
on_attach = require'lsp'.common_on_attach
}

View File

@ -0,0 +1,116 @@
-- TODO figure out why this don't work
vim.fn.sign_define(
"LspDiagnosticsSignError",
{texthl = "LspDiagnosticsSignError", text = "", numhl = "LspDiagnosticsSignError"}
)
vim.fn.sign_define(
"LspDiagnosticsSignWarning",
{texthl = "LspDiagnosticsSignWarning", text = "", numhl = "LspDiagnosticsSignWarning"}
)
vim.fn.sign_define(
"LspDiagnosticsSignHint",
{texthl = "LspDiagnosticsSignHint", text = "", numhl = "LspDiagnosticsSignHint"}
)
vim.fn.sign_define(
"LspDiagnosticsSignInformation",
{texthl = "LspDiagnosticsSignInformation", text = "", numhl = "LspDiagnosticsSignInformation"}
)
vim.cmd("nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>")
vim.cmd("nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>")
vim.cmd("nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>")
vim.cmd("nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>")
vim.cmd("nnoremap <silent> ca :Lspsaga code_action<CR>")
vim.cmd("nnoremap <silent> K :Lspsaga hover_doc<CR>")
-- vim.cmd('nnoremap <silent> <C-k> <cmd>lua vim.lsp.buf.signature_help()<CR>')
vim.cmd("nnoremap <silent> <C-p> :Lspsaga diagnostic_jump_prev<CR>")
vim.cmd("nnoremap <silent> <C-n> :Lspsaga diagnostic_jump_next<CR>")
-- -- scroll down hover doc or scroll in definition preview
-- vim.cmd("nnoremap <silent> <C-f> <cmd>lua require('lspsaga.action').smart_scroll_with_saga(1)<CR>")
-- -- scroll up hover doc
-- vim.cmd("nnoremap <silent> <C-b> <cmd>lua require('lspsaga.action').smart_scroll_with_saga(-1)<CR>")
-- vim.cmd('command! -nargs=0 LspVirtualTextToggle lua require("lsp/virtual_text").toggle()')
-- Set Default Prefix.
-- Note: You can set a prefix per lsp server in the lv-globals.lua file
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = {
prefix = "",
spacing = 0,
},
signs = true,
underline = true,
}
)
-- symbols for autocomplete
vim.lsp.protocol.CompletionItemKind = {
"  (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)"
}
--[[ " autoformat
autocmd BufWritePre *.js lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.jsx lua vim.lsp.buf.formatting_sync(nil, 100)
autocmd BufWritePre *.lua lua vim.lsp.buf.formatting_sync(nil, 100) ]]
-- Java
-- autocmd FileType java nnoremap ca <Cmd>lua require('jdtls').code_action()<CR>
local function documentHighlight(client, bufnr)
-- Set autocommands conditional on server_capabilities
if client.resolved_capabilities.document_highlight then
vim.api.nvim_exec(
[[
hi LspReferenceRead cterm=bold ctermbg=red guibg=#464646
hi LspReferenceText cterm=bold ctermbg=red guibg=#464646
hi LspReferenceWrite cterm=bold ctermbg=red guibg=#464646
augroup lsp_document_highlight
autocmd! * <buffer>
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
augroup END
]],
false
)
end
end
local lsp_config = {}
function lsp_config.common_on_attach(client, bufnr)
documentHighlight(client, bufnr)
end
function lsp_config.tsserver_on_attach(client, bufnr)
lsp_config.common_on_attach(client, bufnr)
client.resolved_capabilities.document_formatting = false
end
-- Use a loop to conveniently both setup defined servers
-- and map buffer local keybindings when the language server attaches
-- local servers = {"pyright", "tsserver"}
-- for _, lsp in ipairs(servers) do nvim_lsp[lsp].setup {on_attach = on_attach} end
return lsp_config

View File

@ -0,0 +1,16 @@
-- npm install -g vscode-json-languageserver
require'lspconfig'.jsonls.setup {
cmd = {
"node", DATA_PATH .. "/lspinstall/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js",
"--stdio"
},
on_attach = require'lsp'.common_on_attach,
commands = {
Format = {
function()
vim.lsp.buf.range_formatting({}, {0, 0}, {vim.fn.line("$"), 0})
end
}
}
}

View File

@ -0,0 +1 @@
require'lspconfig'.julials.setup{}

View File

@ -0,0 +1,22 @@
-- npm i -g pyright
require'lspconfig'.pyright.setup {
cmd = {DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver", "--stdio"},
on_attach = require'lsp'.common_on_attach,
handlers = {
["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = O.python.diagnostics.virtual_text,
signs = O.python.diagnostics.signs,
underline = O.python.diagnostics.underline,
update_in_insert = true
})
},
settings = {
python = {
analysis = {
typeCheckingMode = O.python.analysis.type_checking,
autoSearchPaths = O.python.analysis.auto_search_paths,
useLibraryCodeForTypes = O.python.analysis.use_library_code_types
}
}
}
}

View File

@ -0,0 +1,4 @@
require'lspconfig'.terraformls.setup{
cmd = {DATA_PATH .. "/lspinstall/terraform/terraform-ls", "serve"},
on_attach = require'lsp'.common_on_attach
}

View File

@ -0,0 +1,46 @@
vim.o.completeopt = "menuone,noselect"
require'compe'.setup {
enabled = true;
autocomplete = true;
debug = false;
min_length = 1;
preselect = 'enable';
throttle_time = 80;
source_timeout = 200;
incomplete_delay = 400;
max_abbr_width = 100;
max_kind_width = 100;
max_menu_width = 100;
documentation = false;
source = {
path = true;
buffer = true;
calc = true;
vsnip = true;
nvim_lsp = true;
nvim_lua = true;
spell = true;
tags = true;
snippets_nvim = true;
treesitter = true;
};
}
local t = function(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
_G.s_tab_complete = function()
if vim.fn.pumvisible() == 1 then
return t "<C-p>"
elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
return t "<Plug>(vsnip-jump-prev)"
else
return t "<S-Tab>"
end
end
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})

View File

@ -0,0 +1,71 @@
local actions = require('telescope.actions')
-- Global remapping
------------------------------
-- '--color=never',
require('telescope').setup {
defaults = {
find_command = {'rg', '--no-heading', '--with-filename', '--line-number', '--column', '--smart-case'},
prompt_position = "bottom",
-- prompt_prefix = " ",
prompt_prefix = "",
selection_caret = "",
entry_prefix = " ",
initial_mode = "insert",
selection_strategy = "reset",
sorting_strategy = "descending",
layout_strategy = "horizontal",
layout_defaults = {horizontal = {mirror = false}, vertical = {mirror = false}},
file_sorter = require'telescope.sorters'.get_fuzzy_file,
file_ignore_patterns = {},
generic_sorter = require'telescope.sorters'.get_generic_fuzzy_sorter,
shorten_path = true,
winblend = 0,
width = 0.75,
preview_cutoff = 120,
results_height = 1,
results_width = 0.8,
border = {},
borderchars = {'', '', '', '', '', '', '', ''},
color_devicons = true,
use_less = true,
set_env = {['COLORTERM'] = 'truecolor'}, -- default = nil,
file_previewer = require'telescope.previewers'.vim_buffer_cat.new,
grep_previewer = require'telescope.previewers'.vim_buffer_vimgrep.new,
qflist_previewer = require'telescope.previewers'.vim_buffer_qflist.new,
-- Developer configurations: Not meant for general override
buffer_previewer_maker = require'telescope.previewers'.buffer_previewer_maker,
mappings = {
i = {
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
-- To disable a keymap, put [map] = false
-- So, to not map "<C-n>", just put
-- ["<c-x>"] = false,
["<esc>"] = actions.close,
-- Otherwise, just set the mapping to the function that you want it to be.
-- ["<C-i>"] = actions.select_horizontal,
-- Add up multiple actions
["<CR>"] = actions.select_default + actions.center
-- You can perform as many actions in a row as you like
-- ["<CR>"] = actions.select_default + actions.center + my_cool_custom_action,
},
n = {
["<C-j>"] = actions.move_selection_next,
["<C-k>"] = actions.move_selection_previous,
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist,
-- ["<C-i>"] = my_cool_custom_action,
}
}
},
extensions = {
fzy_native = {
override_generic_sorter = false,
override_file_sorter = true,
}
}
}

View File

@ -0,0 +1,115 @@
require("which-key").setup {
plugins = {
marks = true, -- shows a list of your marks on ' and `
registers = true, -- shows your registers on " in NORMAL or <C-r> in INSERT mode
-- the presets plugin, adds help for a bunch of default keybindings in Neovim
-- No actual key bindings are created
presets = {
operators = true, -- adds help for operators like d, y, ...
motions = true, -- adds help for motions
text_objects = true, -- help for text objects triggered after entering an operator
windows = true, -- default bindings on <c-w>
nav = true, -- misc bindings to work with windows
z = true, -- bindings for folds, spelling and others prefixed with z
g = true -- bindings for prefixed with g
}
},
icons = {
breadcrumb = "»", -- symbol used in the command line area that shows your active key combo
separator = "", -- symbol used between a key and it's label
group = "+" -- symbol prepended to a group
},
window = {
border = "single", -- none, single, double, shadow
position = "bottom", -- bottom, top
margin = {1, 0, 1, 0}, -- extra window margin [top, right, bottom, left]
padding = {2, 2, 2, 2} -- extra window padding [top, right, bottom, left]
},
layout = {
height = {min = 4, max = 25}, -- min and max height of the columns
width = {min = 20, max = 50}, -- min and max width of the columns
spacing = 3 -- spacing between columns
},
hidden = {"<silent>", "<cmd>", "<Cmd>", "<CR>", "call", "lua", "^:", "^ "}, -- hide mapping boilerplate
show_help = true -- show help message on the command line when the popup is visible
}
local opts = {
mode = "n", -- NORMAL mode
prefix = "<leader>",
buffer = nil, -- Global mappings. Specify a buffer number for buffer local mappings
silent = true, -- use `silent` when creating keymaps
noremap = true, -- use `noremap` when creating keymaps
nowait = false -- use `nowait` when creating keymaps
}
-- Set leader
vim.api.nvim_set_keymap('n', '<Space>', '<NOP>', {noremap = true, silent = true})
vim.g.mapleader = ' '
-- explorer
vim.api.nvim_set_keymap('n', '<Leader>e', ':NERDTreeToggle<CR>', {noremap = true, silent = true})
-- dashboard
vim.api.nvim_set_keymap('n', '<Leader>;', ':Dashboard<CR>', {noremap = true, silent = true})
-- TODO create entire treesitter section
local mappings = {
["/"] = "Comment",
["e"] = "Explorer",
f = {
f = {":Telescope find_files<CR>", "Find File"}
},
["f"] = "Find File",
g = {
name = "+Git",
j = {"<cmd>NextHunk<cr>", "Next Hunk"},
k = {"<cmd>PrevHunk<cr>", "Prev Hunk"},
p = {"<cmd>PreviewHunk<cr>", "Preview Hunk"},
r = {"<cmd>ResetHunk<cr>", "Reset Hunk"},
R = {"<cmd>ResetBuffer<cr>", "Reset Buffer"},
s = {"<cmd>StageHunk<cr>", "Stage Hunk"},
u = {"<cmd>UndoStageHunk<cr>", "Undo Stage Hunk"},
o = {"<cmd>Telescope git_status<cr>", "Open changed file"},
b = {"<cmd>Telescope git_branches<cr>", "Checkout branch"},
c = {"<cmd>Telescope git_commits<cr>", "Checkout commit"},
C = {"<cmd>Telescope git_bcommits<cr>", "Checkout commit(for current file)"},
},
l = {
name = "+LSP",
a = {"<cmd>Lspsaga code_action<cr>", "Code Action"},
A = {"<cmd>Lspsaga range_code_action<cr>", "Selected Action"},
d = {"<cmd>Telescope lsp_document_diagnostics<cr>", "Document Diagnostics"},
D = {"<cmd>Telescope lsp_workspace_diagnostics<cr>", "Workspace Diagnostics"},
f = {"<cmd>LspFormatting<cr>", "Format"},
i = {"<cmd>LspInfo<cr>", "Info"},
l = {"<cmd>Lspsaga lsp_finder<cr>", "LSP Finder"},
L = {"<cmd>Lspsaga show_line_diagnostics<cr>", "Line Diagnostics"},
p = {"<cmd>Lspsaga preview_definition<cr>", "Preview Definition"},
q = {"<cmd>Telescope quickfix<cr>", "Quickfix"},
r = {"<cmd>Lspsaga rename<cr>", "Rename"},
t = {"<cmd>LspTypeDefinition<cr>", "Type Definition"},
x = {"<cmd>cclose<cr>", "Close Quickfix"},
s = {"<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols"},
S = {"<cmd>Telescope lsp_workspace_symbols<cr>", "Workspace Symbols"}
},
s = {
name = "+Search",
b = {"<cmd>Telescope git_branches<cr>", "Checkout branch"},
c = {"<cmd>Telescope colorscheme<cr>", "Colorscheme"},
d = {"<cmd>Telescope lsp_document_diagnostics<cr>", "Document Diagnostics"},
D = {"<cmd>Telescope lsp_workspace_diagnostics<cr>", "Workspace Diagnostics"},
f = {"<cmd>Telescope find_files<cr>", "Find File"},
m = {"<cmd>Telescope marks<cr>", "Marks"},
M = {"<cmd>Telescope man_pages<cr>", "Man Pages"},
r = {"<cmd>Telescope oldfiles<cr>", "Open Recent File"},
R = {"<cmd>Telescope registers<cr>", "Registers"},
t = {"<cmd>Telescope live_grep<cr>", "Text"}
},
S = {name = "+Session", s = {"<cmd>SessionSave<cr>", "Save Session"}, l = {"<cmd>SessionLoad<cr>", "Load Session"}}
}
local wk = require("which-key")
wk.register(mappings, opts)

View File

@ -0,0 +1,36 @@
vim.cmd('set iskeyword+=-') -- treat dash separated words as a word text object"
vim.cmd('set shortmess+=c') -- Don't pass messages to |ins-completion-menu|.
vim.cmd('set inccommand=split') -- Make substitution work in realtime
vim.o.hidden = O.hidden_files -- Required to keep multiple buffers open multiple buffers
vim.o.title = true
TERMINAL = vim.fn.expand('$TERMINAL')
vim.cmd('let &titleold="'..TERMINAL..'"')
vim.o.titlestring="%<%F%=%l/%L - nvim"
vim.wo.wrap = O.wrap_lines -- Display long lines as just one line
vim.cmd('set whichwrap+=<,>,[,],h,l') -- move to next line with theses keys
vim.cmd('syntax on') -- syntax highlighting
vim.o.pumheight = 10 -- Makes popup menu smaller
vim.o.fileencoding = "utf-8" -- The encoding written to file
vim.o.cmdheight = 2 -- More space for displaying messages
vim.cmd('set colorcolumn=99999') -- fix indentline for now
vim.o.mouse = "a" -- Enable your mouse
vim.o.splitbelow = true -- Horizontal splits will automatically be below
vim.o.termguicolors = true -- set term gui colors most terminals support this
vim.o.splitright = true -- Vertical splits will automatically be to the right
vim.o.t_Co = "256" -- Support 256 colors
vim.o.conceallevel = 0 -- So that I can see `` in markdown files
vim.cmd('set ts=4') -- Insert 4 spaces for a tab
vim.cmd('set sw=4') -- Change the number of space characters inserted for indentation
vim.cmd('set expandtab') -- Converts tabs to spaces
vim.bo.smartindent = true -- Makes indenting smart
vim.wo.number = O.number -- set numbered lines
vim.wo.relativenumber = O.relative_number -- set relative number
vim.wo.cursorline = true -- Enable highlighting of the current line
vim.o.showtabline = 2 -- Always show tabs
vim.o.showmode = false -- We don't need to see things like -- INSERT -- anymore
vim.o.backup = false -- This is recommended by coc
vim.o.writebackup = false -- This is recommended by coc
vim.wo.signcolumn = "yes" -- Always show the signcolumn, otherwise it would shift the text each time
vim.o.updatetime = 300 -- Faster completion
vim.o.timeoutlen = O.timeoutlen -- By default timeoutlen is 1000 ms
vim.o.clipboard = "unnamedplus" -- Copy paste between vim and everything else