feat: refactor init.vim to use lua

This commit is contained in:
max_richter 2021-08-10 21:50:49 +02:00
parent c5096afe64
commit 1e65796eb8
7 changed files with 252 additions and 127 deletions

View File

@ -117,3 +117,4 @@ export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
[[ -s "/home/jim/.gvm/scripts/gvm" ]] && source "/home/jim/.gvm/scripts/gvm" [[ -s "/home/jim/.gvm/scripts/gvm" ]] && source "/home/jim/.gvm/scripts/gvm"
[ -z $DISPLAY ] && export DISPLAY=127.0.0.1:0.0

View File

@ -89,3 +89,8 @@ fi
# tabtab source for packages # tabtab source for packages
# uninstall by removing these lines # uninstall by removing these lines
[[ -f ~/.config/tabtab/zsh/__tabtab.zsh ]] && . ~/.config/tabtab/zsh/__tabtab.zsh || true [[ -f ~/.config/tabtab/zsh/__tabtab.zsh ]] && . ~/.config/tabtab/zsh/__tabtab.zsh || true
export PNPM_HOME="/home/jim/.local/share/pnpm"
export PATH="$PNPM_HOME:$PATH"
alias luamake=/home/jim/bin/lua-language-server/3rd/luamake/luamake

224
configs/init.lua Normal file
View File

@ -0,0 +1,224 @@
local u = require("utils")
local o = vim.o
local opt = vim.opt
local wo = vim.wo
local bo = vim.bo
local g = vim.g
local fn = vim.fn
-- Global options
o.number = true
o.tabstop = 2
o.shiftwidth = 2 -- Indents will have a width of 4
o.softtabstop = 2 -- Sets the number of columns for a TAB
o.expandtab = false -- Expand TABs to spaces
vim.cmd [[set mouse=a]]
require "paq" {
"savq/paq-nvim", -- Let Paq manage itself
-- Theming Plugins
{"kaicataldo/material.vim", branch = "main"},
"ryanoasis/vim-devicons",
-- Layout Plugins
"preservim/nerdtree",
"hoob3rt/lualine.nvim",
-- Code Navigation
"nvim-lua/popup.nvim",
"nvim-lua/plenary.nvim",
"nvim-telescope/telescope.nvim",
-- Syntax / Autocomplete
"neovim/nvim-lspconfig",
"nvim-lua/completion-nvim",
{"nvim-treesitter/nvim-treesitter", run = ":TSUpdate"},
-- Formatting
"mhartington/formatter.nvim",
-- Git Interface
"akinsho/nvim-toggleterm.lua"
}
-- Apply Theme
o.syntax = "enable"
o.termguicolors = true
g.NERDTreeShowHidden = true
g.material_theme_style = "ocean_community"
vim.cmd [[colorscheme material]]
vim.cmd [[highlight Normal guibg=none]]
vim.cmd [[highlight NonText guibg=none]]
local ts = require "nvim-treesitter.configs"
ts.setup {ensure_installed = "maintained", highlight = {enable = true}}
local Terminal = require("toggleterm.terminal").Terminal
local lazygit =
Terminal:new(
{
cmd = "lazygit",
dir = "git_dir",
direction = "float",
float_opts = {
border = "double"
},
-- function to run on opening the terminal
on_open = function(term)
vim.cmd("startinsert!")
vim.api.nvim_buf_set_keymap(term.bufnr, "n", "q", "<cmd>close<CR>", {noremap = true, silent = true})
end,
-- function to run on closing the terminal
on_close = function(term)
vim.cmd("Closing terminal")
end
}
)
function _lazygit_toggle()
lazygit:toggle()
end
vim.api.nvim_set_keymap("n", "<C-g>", "<cmd>lua _lazygit_toggle()<CR>", {noremap = true, silent = true})
require("toggleterm").setup {}
-- KeyBindings
local map = vim.api.nvim_set_keymap
map("n", ",", "", {})
g.mapleader = ","
options = {noremap = true}
map("n", "<C-p>", ":Telescope find_files<CR>", options)
-- Navigate Buffers
map("n", "<C-h>", "<C-w>h", options)
map("n", "<C-j>", "<C-w>j", options)
map("n", "<C-k>", "<C-w>k", options)
map("n", "<C-l>", "<C-w>l", options)
-- Make ctrl+s work
map("n", "<C-s>", "<Esc>:w<CR>", options)
map("i", "<C-s>", "<Esc>:w<CR>i", options)
-- Update vim config
map("n", "<C-u>", "<Esc>:source $MYVIMRC<CR>", options)
-- Autocommands
u.create_augroup(
{
{"VimEnter", "*", "NERDTree"},
{"VimEnter", "*", "if &filetype !=# 'gitcommit' | NERDTree | wincmd p | endif"}
},
"Nerdtree"
)
-- LSP Config
local lsp = require "lspconfig"
local completion = require "completion"
lsp.svelte.setup {on_attach = completion.on_attach}
-- lsp.sumneko_lua.setup {on_attach = completion.on_attach}
lsp.tsserver.setup {on_attach = completion.on_attach}
opt.completeopt = {"menuone", "noinsert", "noselect"}
opt.shortmess:append({c = true})
-- Config Formatter
u.create_augroup(
{
{"BufWritePost", "*.js,*.jsx,*.ts,*.tsx,*.rs,*.lua", "FormatWrite"}
},
"FormatAutogroup"
)
require("formatter").setup(
{
logging = false,
filetype = {
typescript = {
-- prettier
function()
return {
exe = "prettier",
args = {"--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote"},
stdin = true
}
end
},
javascript = {
-- prettier
function()
return {
exe = "prettier",
args = {"--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote"},
stdin = true
}
end
},
svelte = {
-- prettier
function()
return {
exe = "prettier",
args = {"--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote"},
stdin = true
}
end
},
lua = {
-- luafmt
function()
return {
exe = "luafmt",
args = {"--indent-count", 2, "--stdin"},
stdin = true
}
end
}
}
}
)
-- Linting
lsp.diagnosticls.setup {
filetypes = {"javascript"},
init_options = {
linters = {
eslint = {
command = "./node_modules/.bin/eslint",
rootPatterns = {".git"},
debounce = 100,
args = {
"--stdin",
"--stdin-filename",
"%filepath",
"--format",
"json"
},
sourceName = "eslint",
parseJson = {
errorsRoot = "[0].messages",
line = "line",
column = "column",
endLine = "endLine",
endColumn = "endColumn",
message = "${message} [${ruleId}]",
security = "severity"
},
securities = {
[2] = "error",
[1] = "warning"
}
}
},
filetypes = {
javascript = "eslint"
},
formatters = {
prettier = {
command = "./node_modules/.bin/prettier",
args = {"--stdin-filepath", "%filepath", "--single-quote", "--print-width 120"}
}
},
formatFiletypes = {
javascript = "prettier"
}
}
}

View File

@ -1,118 +0,0 @@
set number
set tabstop=2 " The width of a TAB is set to 4.
" Still it is a \t. It is just that
" Vim will interpret it to be having
" a width of 4.
set shiftwidth=2 " Indents will have a width of 4
set softtabstop=2 " Sets the number of columns for a TAB
set expandtab " Expand TABs to spaces
" Plugins will be downloaded under the specified directory.
call plug#begin('~/.vim/plugged')
" Declare the list of plugins.
Plug 'tpope/vim-sensible'
Plug 'prettier/vim-prettier', {
\ 'do': 'yarn install',
\ 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'graphql', 'markdown', 'vue', 'svelte', 'yaml', 'html'] }
Plug 'kaicataldo/material.vim', { 'branch': 'main' }
Plug 'ryanoasis/vim-devicons'
Plug 'preservim/nerdtree'
" For searching through file contents
Plug 'dyng/ctrlsf.vim'
" A status line to the bottom
" Plug 'itchyny/lightline.vim'
Plug 'vim-airline/vim-airline'
" Asynchronous Lint Engine
Plug 'dense-analysis/ale'
" Autocompletion engine
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'mattn/emmet-vim'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && yarn install' }
" Display Images in Vim
" Plug 'ashisha/image.vim'
" Svelte support
Plug 'leafOfTree/vim-svelte-plugin'
Plug 'evanleck/vim-svelte', {'branch': 'main'}
" Multi Cursor select
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
" Plug 'ctrlpvim/ctrlp.vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'kristijanhusak/vim-dadbod-ui'
Plug 'liuchengxu/vim-clap'
Plug 'glepnir/dashboard-nvim'
" List ends here. Plugins become visible to Vim after this call.
call plug#end()
" Or if you have Neovim >= 0.1.5
if (has("termguicolors"))
set termguicolors
endif
let g:svelte_preprocessors = ['typescript']
" Theme
syntax enable
let g:material_theme_style = 'ocean-community'
colorscheme material
" Remove background color
highlight Normal guibg=none
highlight NonText guibg=none
let g:lightline = {
\ 'colorscheme': 'one',
\ 'background': 'dark',
\ }
let mapleader = ","
nmap <leader>rn <Plug>(coc-rename)
"
nmap <C-p> :FZF<CR>
" COC Configs
set updatetime=300
" NerdTREE config
nmap <F6> :NERDTreeToggle<CR>
let NERDTreeShowHidden=1
au VimEnter * NERDTree
au VimEnter * if &filetype !=# 'gitcommit' | NERDTree | wincmd p | endif
nmap <C-h> <C-w>h
nmap <C-j> <C-w>j
nmap <C-k> <C-w>k
nmap <C-l> <C-w>l
nnoremap H gT
nnoremap L gt
:tnoremap <Esc> <C-\><C-n>
autocmd WinEnter * call s:CloseIfOnlyNerdTreeLeft()
" Close all open buffers on entering a window if the only
" buffer that's left is the NERDTree buffer
function! s:CloseIfOnlyNerdTreeLeft()
if exists("t:NERDTreeBufName")
if bufwinnr(t:NERDTreeBufName) != -1
if winnr("$") == 1
q
endif
endif
endif
endfunction

13
configs/lua/utils.lua Normal file
View File

@ -0,0 +1,13 @@
local M = {}
local cmd = vim.cmd
function M.create_augroup(autocmds, name)
cmd('augroup ' .. name)
cmd('autocmd!')
for _, autocmd in ipairs(autocmds) do
cmd('autocmd ' .. table.concat(autocmd, ' '))
end
cmd('augroup END')
end
return M

View File

@ -1,7 +1,7 @@
## ALIASIES ## ## ALIASIES ##
alias -s {yml,yaml,ts,json,js,vim,rc}=nvim alias -s {yml,yaml,ts,json,js,vim,rc}=nvim
alias c="code-insiders ." alias c="code ."
alias ca="c -a" alias ca="c -a"
alias cr="c -r" alias cr="c -r"

View File

@ -1,15 +1,15 @@
if [ -f "$HOME/.config/nvim/init.vim" ]; then if [ -f "$HOME/.config/nvim/init.lua" ]; then
echo " - moving old file to init.vim.BAK" echo " - moving old file to init.lua.BAK"
mv "$HOME/.config/nvim/init.vim" "$HOME/.config/nvim/init.vim.BAK" mv "$HOME/.config/nvim/init.lua" "$HOME/.config/nvim/init.lua.BAK"
fi fi
echo " - linking init.vim --> init.vim" echo " - linking init.vim --> init.vim"
mkdir -p $HOME/.config/nvim mkdir -p $HOME/.config/nvim
ln -s "$HOME/.dotfiles/configs/init.vim" "$HOME/.config/nvim/init.vim" ln -s "$HOME/.dotfiles/configs/init.lua" "$HOME/.config/nvim/init.lua"
ln -s "$HOME/.dotfiles/configs/lua" "$HOME/.config/nvim/lua"
echo " - installing vim-plug" echo " - installing paq-nvim"
sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \ sh -c 'git clone --depth=1 https://github.com/savq/paq-nvim.git "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/pack/paqs/start/paq-nvim'
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
echo " - installing vim plugins" echo " - installing vim plugins"
nvim --headless +PlugInstall +qa nvim --headless +PaqSync +qa