Last active
October 25, 2022 09:00
-
-
Save cipriantarta/99ce623d080c4162a67d97f569bd7bd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('plugins') -- the plugins | |
require('settings') -- plugins & general nvim settings | |
require('mappings') -- key mappings | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
utils = require('utils') | |
local map = utils.map | |
map('n', '<Right>', ':bn<CR>', { silent = true}) | |
map('n', '<Left>', ':bp<CR>', { silent = true}) | |
map('n', '<Leader>w', ':bd!<CR>', { silent = true}) | |
map('n', '<C-x>', ':q!<CR>', { silent = true}) | |
map('n', '<C-s>', ':w<CR>', { silent = true}) | |
map('i', '<C-s>', '<Esc>:w<CR>', { silent = true}) | |
----------------------------- S FZF ----------------------------- | |
vim.cmd [[ | |
command! -bang -nargs=? -complete=dir Files | |
\ call fzf#vim#files(<q-args>, fzf#vim#with_preview({'options': ['--layout=reverse']}), <bang>0) | |
function! RipgrepFzf(query, fullscreen) | |
let command_fmt = "rg --column --line-number --no-heading --color=always --smart-case --glob '!vendor/*' -- %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! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0) | |
]] | |
map('n', '<C-o>', ':Files<CR>', {silent = true}) | |
map('i', '<C-o>', '<Esc>:Files<CR>', {silent = true}) | |
map('n', '<C-k>', ':RG<CR>', {silent = true}) | |
map('i', '<C-k>', '<Esc>:RG<CR>', {silent = true}) | |
----------------------------- E FZF ----------------------------- | |
----------------------------- S NERD ----------------------------- | |
map('n', '<C-n>', ':NERDTreeToggle<CR>', {silent = true}) | |
----------------------------- E NERD ----------------------------- | |
map('n', '<A-o>', ':set paste<CR>m`o<Esc>``:set nopaste<CR>', {silent = true}) | |
map('n', '<A-O>', ':set paste<CR>m`O<Esc>``:set nopaste<CR>', {silent = true}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vim.cmd([[ | |
augroup packer_user_config | |
autocmd! | |
autocmd BufWritePost plugins.lua source <afile> | PackerCompile | |
augroup end | |
]]) | |
return require('packer').startup(function() | |
-- Packer can manage itself | |
use 'wbthomason/packer.nvim' | |
-- LSP | |
use 'neovim/nvim-lspconfig' | |
-- use 'ms-jpq/coq_nvim' | |
-- use {'ms-jpq/coq.artifacts', branch = 'artifacts'} | |
-- use 'ray-x/lsp_signature.nvim' | |
use 'hrsh7th/cmp-nvim-lsp' | |
use 'hrsh7th/cmp-buffer' | |
use 'hrsh7th/cmp-path' | |
use 'hrsh7th/cmp-cmdline' | |
use 'hrsh7th/cmp-nvim-lsp-document-symbol' | |
use 'hrsh7th/cmp-nvim-lsp-signature-help' | |
use 'hrsh7th/nvim-cmp' | |
use 'L3MON4D3/LuaSnip' | |
use 'saadparwaiz1/cmp_luasnip' | |
use 'onsails/lspkind.nvim' | |
use "rafamadriz/friendly-snippets" | |
-- Fuzzy finder | |
use {'junegunn/fzf', run = function() vim.fn['fzf#install']() end} | |
use 'junegunn/fzf.vim' | |
use 'gfanto/fzf-lsp.nvim' | |
use 'nvim-lua/plenary.nvim' | |
-- Lualine | |
use { | |
'nvim-lualine/lualine.nvim', | |
requires = { 'kyazdani42/nvim-web-devicons', opt = true } | |
} | |
-- Theme | |
use 'marko-cerovac/material.nvim' | |
use 'Mofiqul/dracula.nvim' | |
use {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate'} | |
-- NERD | |
use 'preservim/nerdcommenter' | |
use 'preservim/nerdtree' | |
use 'Xuyuanp/nerdtree-git-plugin' | |
use 'ryanoasis/vim-devicons' | |
-- Go | |
use 'sebdah/vim-delve' | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
utils = require('utils') | |
local map = utils.map | |
local map_b = utils.map_b | |
local set = vim.opt | |
local g = vim.g | |
set.encoding = 'UTF-8' | |
set.history = 1000 -- keep 50 lines of command line history | |
set.ruler = true -- show the cursor position all the time | |
set.showcmd = true -- display incomplete commands | |
set.incsearch = true -- do incremental searching | |
set.rnu = true | |
set.nu = true | |
set.clipboard = "unnamed" | |
set.numberwidth = 5 | |
set.expandtab = true | |
set.shiftwidth = 4 | |
set.scrolloff = 5 | |
set.laststatus = 2 | |
set.hidden = true | |
set.backspace = 'indent,eol,start' | |
set.updatetime = 300 | |
set.shortmess:append('c') | |
-- not available in lua | |
vim.cmd [[ | |
set nocompatible | |
set nobackup | |
set nowritebackup | |
set nowrap | |
set backspace=indent,eol,start | |
syntax enable | |
]] | |
-- S THEME | |
g.material_style = 'deep ocean' | |
require('material').setup { | |
custom_highlights = { | |
LineNr = {fg = '#747AA3'} | |
}, | |
custom_colors = { | |
fg = '#c0c6ef' | |
} | |
} | |
require('lualine').setup { | |
options = { | |
theme = 'auto', | |
}, | |
sections = { | |
lualine_c = { | |
{ | |
'filename', | |
path = 1, | |
shorting_target = 40, | |
} | |
} | |
}, | |
tabline = { | |
lualine_a = { | |
{ | |
'buffers', | |
show_modified_status = true, | |
mode = 0 | |
} | |
} | |
} | |
} | |
vim.cmd [[ | |
colorscheme material | |
]] | |
ok_tree, treesitter = pcall(require, 'nvim-treesitter.configs') | |
if ok_tree then | |
treesitter.setup({ | |
ensure_installed = {"c", "lua", "rust", "go", "html", "json", "typescript", "javascript", "terraform"}, | |
sync_install = false, | |
highlight = { | |
-- `false` will disable the whole extension | |
enable = true, | |
} | |
}) | |
end | |
-- E THEME | |
-- S NERD | |
g.NERDSpaceDelims = 1 | |
g.NERDCompactSexyComs = 1 | |
g.NERDDefaultAlign = 'left' | |
g.NERDCommentEmptyLines = 1 | |
g.NERDTrimTrailingWhitespace = 1 | |
-- E NERD | |
-- S FileType | |
vim.cmd [[ | |
autocmd CursorMovedI * if pumvisible() == 0|silent! pclose|endif | |
autocmd InsertLeave * if pumvisible() == 0|silent! pclose|endif | |
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab | |
autocmd FileType typescript,javascript,typescriptreact,javascriptreact setlocal ts=2 sts=2 sw=2 expandtab | |
autocmd FileType go setlocal ts=8 sts=8 sw=8 expandtab | |
autocmd FileType proto setlocal ts=2 sts=2 sw=2 expandtab | |
autocmd FileType lua setlocal ts=2 sts=2 sw=2 expandtab | |
autocmd FileType tf,terraform,tfvars setlocal ts=2 sts=2 sw=2 expandtab | |
filetype plugin on | |
augroup prewrites | |
autocmd! | |
autocmd BufWritePre,FileWritePre * lua vim.lsp.buf.formatting_sync(nil, 1000) | |
autocmd BufWritePre *.tsx,*.ts,*.jsx,*.js EslintFixAll | |
augroup END | |
set completeopt=menu,menuone,noselect | |
]] | |
-- E FileType | |
-- S LSP | |
local lspconfig = require('lspconfig') | |
local opts = { silent=true } | |
map('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts) | |
map('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts) | |
map('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts) | |
map('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts) | |
-- 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) | |
-- Mappings. | |
-- See `:help vim.lsp.*` for documentation on any of the below functions | |
map_b(bufnr, 'n', 'gD', '<cmd>:Declaration()<CR>', opts) | |
map_b(bufnr, 'n', 'gd', '<cmd>:Definitions<CR>', opts) | |
map_b(bufnr, 'n', 'gr', '<cmd>:References<CR>', opts) | |
map_b(bufnr, 'n', 'gi', '<cmd>:Implementations<CR>', opts) | |
map_b(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts) | |
map_b(bufnr, 'n', '<space>D', '<cmd>:TypeDefinitions<CR>', opts) | |
map_b(bufnr, 'n', '<space>k', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | |
map_b(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) | |
map_b(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) | |
map_b(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) | |
map_b(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | |
map_b(bufnr, 'n', '<space>ca', '<cmd>:CodeAction<CR>', opts) | |
map_b(bufnr, 'n', '<space>o', '<cmd>DocumentSymbols<CR>', opts) | |
map_b(bufnr, 'n', ']o', '<cmd>WorkspaceSymbols<CR>', opts) | |
map_b(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts) | |
-- signature | |
local ok, lsp_signature = pcall(require, 'lsp_signature') | |
if ok then | |
lsp_signature.on_attach({ | |
bind = true, | |
handler_opts = { | |
border = 'rounded' | |
}, | |
hint_prefix='' | |
}) | |
end | |
end | |
local servers = { | |
gopls = { | |
root_dir = vim.loop.os_homedir() | |
}, | |
golangci_lint_ls = {}, | |
pyright = {}, | |
rust_analyzer = {}, | |
tsserver = {}, | |
eslint = {} | |
} | |
g.coq_settings = { auto_start = 'shut-up' } | |
local ok_coq, coq = pcall(require, 'coq') | |
local ok_cmp, cmp = pcall(require, 'cmp') | |
if ok_cmp then | |
local lspkind = require('lspkind') | |
local ls = require('luasnip') | |
require("luasnip.loaders.from_vscode").lazy_load() | |
local has_words_before = function() | |
local line, col = unpack(vim.api.nvim_win_get_cursor(0)) | |
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil | |
end | |
cmp.setup({ | |
snippet = { | |
expand = function(args) | |
require('luasnip').lsp_expand(args.body) -- For `luasnip` users. | |
end, | |
}, | |
window = { | |
-- completion = cmp.config.window.bordered(), | |
-- documentation = cmp.config.window.bordered(), | |
}, | |
mapping = cmp.mapping.preset.insert({ | |
['<Right>'] = cmp.mapping.abort(), | |
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. | |
["<Tab>"] = cmp.mapping(function(fallback) | |
if cmp.visible() then | |
cmp.select_next_item() | |
elseif ls.expand_or_jumpable() then | |
ls.expand_or_jump() | |
elseif has_words_before() then | |
cmp.complete() | |
else | |
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`. | |
end | |
end, { "i", "s" }), | |
["<S-Tab>"] = cmp.mapping(function() | |
if cmp.visible() then | |
cmp.select_prev_item() | |
elseif ls.jumpable(-1) then | |
ls.jump(-1) | |
end | |
end, { "i", "s" }), | |
}), | |
sources = cmp.config.sources({ | |
{ name = 'nvim_lsp' }, | |
{ name = 'nvim_lsp_document_symbol' }, | |
{ name = 'nvim_lsp_signature_help' }, | |
{ name = 'luasnip' }, -- For luasnip users. | |
-- { name = 'vsnip' }, -- For vsnip users. | |
-- { name = 'ultisnips' }, -- For ultisnips users. | |
-- { name = 'snippy' }, -- For snippy users. | |
}, { | |
{ name = 'buffer' }, | |
}), | |
formatting = { | |
format = lspkind.cmp_format({ | |
mode = "symbol_text", | |
menu = ({ | |
buffer = "[B]", | |
nvim_lsp = "[LSP]", | |
luasnip = "[Snip]", | |
nvim_lua = "[Lua]", | |
}) | |
}), | |
}, | |
}) | |
end | |
local ok_cmp_lsp, cmp_lsp = pcall(require, 'cmp_nvim_lsp') | |
local cmp_caps = {} | |
if ok_cmp_lsp then | |
cmp_caps = cmp_lsp.default_capabilities(vim.lsp.protocol.make_client_capabilities()) | |
end | |
for server, config in pairs(servers) do | |
local caps = { | |
on_attach = on_attach, | |
init_options = { | |
usePlaceholders = true, | |
} | |
} | |
if ok_coq then | |
lspconfig[server].setup(coq.lsp_ensure_capabilities(caps)) | |
elseif ok_cmp_lsp then | |
caps['capabilities'] = cmp_caps | |
lspconfig[server].setup(caps) | |
else | |
lspconfig[server].setup(caps) | |
end | |
end | |
-- E LSP | |
-- S Delve | |
g.delve_new_command = 'enew' | |
-- E Delve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local M = {} | |
function M.map(mode, lhs, rhs, opts) | |
local options = { noremap = true } | |
if opts then | |
options = vim.tbl_extend('force', options, opts) | |
end | |
vim.api.nvim_set_keymap(mode, lhs, rhs, options) | |
end | |
function M.map_b(bn, mode, lhs, rhs, opts) | |
local options = { noremap = true } | |
if opts then | |
options = vim.tbl_extend('force', options, opts) | |
end | |
vim.api.nvim_buf_set_keymap(bn, mode, lhs, rhs, options) | |
end | |
return M |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment