Skip to content

Commit

Permalink
Merge pull request #2 from mgnsk/nvim-formatprg
Browse files Browse the repository at this point in the history
Use async formatting
  • Loading branch information
mgnsk authored Jan 9, 2021
2 parents 091cb7b + 0f1de55 commit 521c624
Show file tree
Hide file tree
Showing 30 changed files with 223 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .config/nvim/autoload/fns.vim
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endfunction

function! fns#Format()
if s:autoformat_enabled
execute('Neoformat')
exe 'FormatWrite'
endif
endfunction

Expand Down
10 changes: 0 additions & 10 deletions .config/nvim/autoload/neoformat/formatters/sql.vim

This file was deleted.

1 change: 0 additions & 1 deletion .config/nvim/ftplugin/css.vim

This file was deleted.

1 change: 0 additions & 1 deletion .config/nvim/ftplugin/glsl.vim

This file was deleted.

20 changes: 0 additions & 20 deletions .config/nvim/ftplugin/go.vim

This file was deleted.

1 change: 0 additions & 1 deletion .config/nvim/ftplugin/html.vim

This file was deleted.

1 change: 0 additions & 1 deletion .config/nvim/ftplugin/json.vim

This file was deleted.

1 change: 1 addition & 0 deletions .config/nvim/ftplugin/jsonc.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
set filetype=json
1 change: 0 additions & 1 deletion .config/nvim/ftplugin/lua.vim

This file was deleted.

1 change: 0 additions & 1 deletion .config/nvim/ftplugin/proto.vim

This file was deleted.

1 change: 0 additions & 1 deletion .config/nvim/ftplugin/rust.vim

This file was deleted.

1 change: 0 additions & 1 deletion .config/nvim/ftplugin/scss.vim

This file was deleted.

1 change: 0 additions & 1 deletion .config/nvim/ftplugin/sh.vim

This file was deleted.

4 changes: 0 additions & 4 deletions .config/nvim/ftplugin/typescript.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
let g:neomake_typescript_enabled_makers = ['eslint']

autocmd FileType typescript setlocal makeprg=eslint\ --format\ compact

autocmd BufWritePre *.ts silent call fns#Format()
1 change: 0 additions & 1 deletion .config/nvim/ftplugin/yaml.vim
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
autocmd BufWritePre *.yaml,*.yml silent call fns#Format()
15 changes: 12 additions & 3 deletions .config/nvim/init.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
vim.cmd "packadd pkg-nvim"

vim.g.mapleader = ","

require "mappings"

require "formatter"
if not os.getenv("NVIM_LSP_DISABLED") then
require "lsp"
end
Expand All @@ -15,6 +14,17 @@ require "nvim-treesitter.configs".setup {
}
}

vim.call("neomake#configure#automake", "w")

local undodir = os.getenv("VIM_UNDO_DIR")
if not vim.call("isdirectory", undodir) then
vim.call("mkdir", undodir)
end
vim.o.undodir = undodir
vim.cmd("set undofile")
vim.cmd("set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab")
vim.cmd("set noexpandtab")
vim.cmd("set nocompatible")
vim.o.completeopt = "menuone,noinsert,noselect"
vim.o.lazyredraw = true
vim.cmd("set termguicolors")
Expand Down Expand Up @@ -51,7 +61,6 @@ vim.cmd("set tabline=%!MyTabLine()")

require "colorizer".setup()

vim.g.shfmt_opt = "-ci"
vim.g.neomake_open_list = 2
-- Open fies in new tab.
vim.g.netrw_browse_split = 3
Expand Down
127 changes: 127 additions & 0 deletions .config/nvim/lua/formatter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
require "format".setup {
["*"] = {
{
cmd = {
-- remove trailing whitespace
"sed -i 's/[ \t]*$//'"
}
}
},
css = {
{
cmd = {
"prettier -w"
}
}
},
scss = {
{
cmd = {
"prettier -w"
}
}
},
glsl = {
{
cmd = {
"clang-format -i"
}
}
},
go = {
{
cmd = {
"gofumports -w"
}
}
},
html = {
{
cmd = {
"prettier -w"
}
}
},
json = {
{
cmd = {
"prettier -w"
}
}
},
javascript = {
{
cmd = {
"prettier -w"
}
}
},
typescript = {
{
cmd = {
"prettier -w"
}
}
},
lua = {
{
cmd = {
"luafmt -w replace"
}
}
},
proto = {
{
cmd = {
"clang-format -i"
}
}
},
rust = {
{
cmd = {
"rustfmt"
}
}
},
sh = {
{
cmd = {
"shfmt -w"
}
}
},
sql = {
{
cmd = {
function(file)
return string.format("~/.tools/js/sql_format.mjs %s", file, file)
end
}
}
},
yaml = {
{
cmd = {
"prettier -w"
}
}
},
markdown = {
{
cmd = {
"prettier -w"
}
}
}
}

vim.api.nvim_exec(
[[
augroup FormatAutogroup
autocmd!
autocmd BufWritePost *.css,*.scss,*.vert,*.tesc,*.tese,*.geom,*.frag,*.comp,*.glsl,*go,*.html,*.json,*.js,*.mjs,*.md,*.ts,*.lua,*.proto,*.rs,*.sh,*.sql,*.yml,*.yaml call fns#Format()
augroup END
]],
true
)
14 changes: 9 additions & 5 deletions .config/nvim/lua/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ vimp.tnoremap("<Esc>", [[<C-\><C-n>]])
vimp.nnoremap("<Esc><Esc>", ":nohlsearch<CR>")

vimp.nnoremap("<leader>.", ":")
vimp.nnoremap("<leader>-", ":Commands<CR>")
vimp.nnoremap("<leader>/", ":Commands<CR>")
vimp.nnoremap("<leader>,", ":let $curdir=expand('%:p:h')<CR>:vsplit<CR>:ter<CR>cd $curdir<CR>")
vimp.nnoremap("tt", ":let $curdir=expand('%:p:h')<CR>:tabnew<CR>:ter<CR>cd $curdir<CR>")
vimp.nnoremap("<leader>v", ":vnew<CR>")
Expand All @@ -29,10 +27,17 @@ vimp.nnoremap("<leader>t", ":tabnew<CR>")
vimp.nnoremap("<leader>e", ":Tex<CR>")
vimp.nnoremap("<leader>j", ":bnext<CR>")
vimp.nnoremap("<leader>k", ":bprev<CR>")
vimp.nnoremap("<leader>b", ":Buffers<CR>")
vimp.nnoremap("<leader>u", "gg=G``")
vimp.nnoremap("<leader>g", ":Rg<CR>")

vimp.nnoremap("<leader>-", ":Commands<CR>")
vimp.nnoremap("<leader>/", ":Commands<CR>")
vimp.nnoremap("<leader>b", ":Buffers<CR>")
vimp.nnoremap("<leader>g", ":RG<CR>")
vimp.nnoremap("<leader>o", ":FZF<CR>")
vimp.nnoremap("<leader>T", ":Tags<CR>")
vimp.nnoremap("<leader>F", ":DocumentSymbols<CR>")
vimp.nnoremap("<leader>G", ":BCommits<CR>")

vimp.nnoremap(
"<leader>l",
function()
Expand All @@ -41,7 +46,6 @@ vimp.nnoremap(
)
vimp.nnoremap("<leader>K", "<C-w>K<CR>")
vimp.nnoremap("<leader>H", "<C-w>H<CR>")
vimp.nnoremap("<leader>T", ":Tags<CR>")

vimp.nnoremap(
"<leader>nt",
Expand Down
3 changes: 2 additions & 1 deletion .config/nvim/lua/plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ pkg "sebdah/vim-delve"
pkg "Townk/vim-autoclose"
pkg "neomake/neomake"
pkg "tpope/vim-fugitive"
pkg "sbdchd/neoformat"
pkg "lukas-reineke/format.nvim"
pkg "rbtnn/vim-vimscript_indentexpr"
pkg "svermeulen/vimpeccable"
pkg "norcalli/nvim-colorizer.lua"
pkg "gfanto/fzf-lsp.nvim"
61 changes: 8 additions & 53 deletions .config/nvim/plugin/commands.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8,69 +8,24 @@ let g:clipboard = {
\ },
\ }

set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
set noexpandtab
set nocompatible
"set lazyredraw
"

" Show syn hi groups under cursor.
map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" Use persistent history.
if !isdirectory($VIM_UNDO_DIR)
call mkdir($VIM_UNDO_DIR)
endif
set undodir=$VIM_UNDO_DIR
set undofile

command LspStop lua vim.lsp.stop_client(vim.lsp.get_active_clients())

autocmd Filetype * setlocal omnifunc=v:lua.vim.lsp.omnifunc
autocmd TermOpen term://* startinsert

"nnoremap <silent> gd <cmd>lua vim.lsp.buf.declaration()<CR>
"nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
"nnoremap <silent> 1gD <cmd>lua vim.lsp.buf.type_definition()<CR>

" Customize fzf colors to match your color scheme
" - fzf#wrap translates this to a set of `--color` options
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }

" Rg uses ripgrep.
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1,
\ fzf#vim#with_preview(), <bang>0)
function! RipgrepFzf(query, fullscreen)
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case -- %s || true'
let initial_command = printf(command_fmt, shellescape(a:query))
let reload_command = printf(command_fmt, '{q}')
let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction

command! -bang -nargs=? -complete=dir Files
\ call fzf#vim#files(<q-args>, {'options': ['--layout=reverse', '--info=inline', '--preview', '~/.config/nvim/plugged/fzf.vim/bin/preview.sh {}']}, <bang>0)
command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)

command! -nargs=+ GotoOrOpen call fns#GotoOrOpen(<f-args>)

command! FZFMru call fzf#run({
\ 'source': reverse(s:all_files()),
\ 'sink': 'edit',
\ 'options': '-m -x +s',
\ 'down': '40%' })

function! s:all_files()
return extend(
\ filter(copy(v:oldfiles),
\ "v:val !~ 'fugitive:\\|NERD_tree\\|^/tmp/\\|.git/'"),
\ map(filter(range(1, bufnr('$')), 'buflisted(v:val)'), 'bufname(v:val)'))
endfunction
6 changes: 4 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export PATH="$HOME/go/bin:$PATH"
export PATH="$HOME/.cargo/bin:$PATH"
export PATH="$HOME/bin:$PATH"
export PATH="$HOME/scripts:$PATH"
export PATH="$HOME/.fzf/bin:$PATH"
export PATH="$HOME/.neovim/bin:$PATH"
export PATH="$HOME/.luarocks/bin:$PATH"
export PATH="$HOME/.gem/ruby/2.7.0/bin:$PATH"
Expand All @@ -26,7 +25,10 @@ export PAGER="most"
export MANPAGER="nvim +Man!"

export PROMPT_COMMAND="history -a; history -n"
export FZF_DEFAULT_COMMAND="find -L -not -path '*/\.git/*'"

export FZF_DEFAULT_COMMAND="fd --type f"
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND="fd --type d"

export LIBRARY_PATH="$HOME/.local/lib"

Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ linters:
- depguard
- gochecknoinits
- gochecknoglobals

- exhaustivestruct
13 changes: 13 additions & 0 deletions .tools/js/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 12,
"sourceType": "module"
},
"rules": {
}
}
Loading

0 comments on commit 521c624

Please sign in to comment.