Skip to content

Instantly share code, notes, and snippets.

@viniciusgonmelo
Last active June 14, 2023 20:03
Show Gist options
  • Save viniciusgonmelo/44f106afe35746098cb7a14ee9415f15 to your computer and use it in GitHub Desktop.
Save viniciusgonmelo/44f106afe35746098cb7a14ee9415f15 to your computer and use it in GitHub Desktop.
Configuração pro Neovim.
" ~/.config/nvim/init.vim
" Configurações dos plugins
source /home/admin/.config/nvim/plugin-config/vim-plug.vim
source /home/admin/.config/nvim/plugin-config/deoplete.vim
source /home/admin/.config/nvim/plugin-config/neosnippet.vim
source /home/admin/.config/nvim/plugin-config/denite.vim
source /home/admin/.config/nvim/plugin-config/vim-fake.vim
source /home/admin/.config/nvim/plugin-config/monokai.vim
source /home/admin/.config/nvim/plugin-config/nvim-lspconfig.lua
syntax on
set cursorline
set number
set hlsearch
set ignorecase
set undofile
set hidden
set shortmess=at
set cmdheight=2
set clipboard=unnamedplus
set encoding=UTF-8
set expandtab
set tabstop=2
set shiftwidth=2
" <zo>: open fold
" <zc>: close
" <zR>: open all
" <zM>: close all
" auto generated based on indent; start open
set foldmethod=indent
set foldlevelstart=99
augroup no_autoinsert_comment_on_nl
au!
au FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
augroup END
augroup json_conceal
au!
au BufNewFile,BufRead *.json set conceallevel=0
augroup END
nnoremap * :keepjumps normal! mi*`i<CR>
function! Preserve(command)
let search = @/
let cursor_position = getpos('.')
normal! H
let window_position = getpos('.')
call setpos('.', cursor_position)
execute a:command
let @/ = search
call setpos('.', window_position)
normal! zt
call setpos('.', cursor_position)
endfunction
function! Indent()
call Preserve('normal gg=G')
endfunction
augroup fmt
au!
au BufWritePre *.html.twig,*.blade.php,*.css call Indent()
augroup END
" ~/.config/nvim/plugin-config/denite.vim
" https://github.com/ctaylo21/jarvis/blob/master/config/nvim/init.vim
try
" === Denite setup ==="
" Use ripgrep for searching current directory for files
" By default, ripgrep will respect rules in .gitignore
" --files: Print each file that would be searched (but don't search)
" --glob: Include or exclues files for searching that match the given glob
" (aka ignore .git files)
"
call denite#custom#var('file/rec', 'command', ['rg', '--files', '--glob', '!.git'])
" Use ripgrep in place of "grep"
call denite#custom#var('grep', 'command', ['rg'])
" Custom options for ripgrep
" --vimgrep: Show results with every match on it's own line
" --hidden: Search hidden directories and files
" --heading: Show the file name above clusters of matches from each file
" --S: Search case insensitively if the pattern is all lowercase
call denite#custom#var('grep', 'default_opts', ['--hidden', '--vimgrep', '--heading', '-S'])
" Recommended defaults for ripgrep via Denite docs
call denite#custom#var('grep', 'recursive_opts', [])
call denite#custom#var('grep', 'pattern_opt', ['--regexp'])
call denite#custom#var('grep', 'separator', ['--'])
call denite#custom#var('grep', 'final_opts', [])
" Remove date from buffer list
call denite#custom#var('buffer', 'date_format', '')
" Custom options for Denite
" split - Use floating window for Denite
" start_filter - Start filtering on default
" auto_resize - Auto resize the Denite window height automatically.
" source_names - Use short long names if multiple sources
" prompt - Customize denite prompt
" highlight_matched_char - Matched characters highlight
" highlight_matched_range - matched range highlight
" highlight_window_background - Change background group in floating window
" highlight_filter_background - Change background group in floating filter window
" winrow - Set Denite filter window to top
" vertical_preview - Open the preview window vertically
let s:denite_options = {'default' : {
\ 'split': 'floating',
\ 'start_filter': 1,
\ 'auto_resize': 1,
\ 'source_names': 'short',
\ 'prompt': 'λ ',
\ 'highlight_matched_char': 'QuickFixLine',
\ 'highlight_matched_range': 'Visual',
\ 'highlight_window_background': 'Visual',
\ 'highlight_filter_background': 'DiffAdd',
\ 'winrow': 1,
\ 'vertical_preview': 1
\ }}
" Loop through denite options and enable them
function! s:profile(opts) abort
for l:fname in keys(a:opts)
for l:dopt in keys(a:opts[l:fname])
call denite#custom#option(l:fname, l:dopt, a:opts[l:fname][l:dopt])
endfor
endfor
endfunction
call s:profile(s:denite_options)
catch
echo 'Denite not installed. It should work after running :PlugInstall'
endtry
" === Denite shorcuts === "
" ; - Browser currently open buffers
" <leader>t - Browse list of files in current directory
" <leader>g - Search current directory for occurences of given term and close window if no results
" <leader>j - Search current directory for occurences of word under cursor
nmap ; :Denite buffer<CR>
nmap <leader>t :DeniteProjectDir file/rec<CR>
nnoremap <leader>g :<C-u>Denite grep:. -no-empty<CR>
nnoremap <leader>j :<C-u>DeniteCursorWord grep:.<CR>
" Define mappings while in 'filter' mode
" <C-o> - Switch to normal mode inside of search results
" <Esc> - Exit denite window in any mode
" <CR> - Open currently selected file in any mode
" <C-t> - Open currently selected file in a new tab
" <C-v> - Open currently selected file a vertical split
" <C-h> - Open currently selected file in a horizontal split
autocmd FileType denite-filter call s:denite_filter_my_settings()
function! s:denite_filter_my_settings() abort
imap <silent><buffer> <C-o>
\ <Plug>(denite_filter_update)
inoremap <silent><buffer><expr> <Esc>
\ denite#do_map('quit')
nnoremap <silent><buffer><expr> <Esc>
\ denite#do_map('quit')
inoremap <silent><buffer><expr> <CR>
\ denite#do_map('do_action')
inoremap <silent><buffer><expr> <C-t>
\ denite#do_map('do_action', 'tabopen')
inoremap <silent><buffer><expr> <C-v>
\ denite#do_map('do_action', 'vsplit')
inoremap <silent><buffer><expr> <C-h>
\ denite#do_map('do_action', 'split')
endfunction
" Define mappings while in denite window
" <CR> - Opens currently selected file
" q or <Esc> - Quit Denite window
" d - Delete currenly selected file
" p - Preview currently selected file
" <C-o> or i - Switch to insert mode inside of filter prompt
" <C-t> - Open currently selected file in a new tab
" <C-v> - Open currently selected file a vertical split
" <C-h> - Open currently selected file in a horizontal split
autocmd FileType denite call s:denite_my_settings()
function! s:denite_my_settings() abort
nnoremap <silent><buffer><expr> <CR>
\ denite#do_map('do_action')
nnoremap <silent><buffer><expr> q
\ denite#do_map('quit')
nnoremap <silent><buffer><expr> <Esc>
\ denite#do_map('quit')
nnoremap <silent><buffer><expr> d
\ denite#do_map('do_action', 'delete')
nnoremap <silent><buffer><expr> p
\ denite#do_map('do_action', 'preview')
nnoremap <silent><buffer><expr> i
\ denite#do_map('open_filter_buffer')
nnoremap <silent><buffer><expr> <C-o>
\ denite#do_map('open_filter_buffer')
nnoremap <silent><buffer><expr> <C-t>
\ denite#do_map('do_action', 'tabopen')
nnoremap <silent><buffer><expr> <C-v>
\ denite#do_map('do_action', 'vsplit')
nnoremap <silent><buffer><expr> <C-h>
\ denite#do_map('do_action', 'split')
endfunction
" ~/.config/nvim/plugin-config/deoplete.vim
set completeopt-=preview
set noshowmode
let g:deoplete#enable_at_startup = 1
let g:echodoc_enable_at_startup = 1
let g:deoplete#lsp#use_icons_for_candidates = 1
call deoplete#custom#source('neosnippet', 'rank', 1000)
call deoplete#custom#source('lsp', 'rank', 999)
call deoplete#custom#option('ignore_sources', {'_': ['file']})
call deoplete#custom#var('terminal', 'require_same_tab', v:false)
#!/usr/bin/env bash
# Instala os servidores de linguagem pro Neovim no Arch Linux
# Também instalar Python, nodejs, Ruby etc.
sudo pacman -S jedi-language-server \
bash-language-server \
typescript-language-server \
clangd yaml-language-server \
pyright \
psalm \
lua-language-server
yay -S ruby-solargraph \
vim-language-server \
lemminx \
vscode-langservers-extracted \
dockerfile-language-server \
nodejs-intelephense \
phpactor \
sqls \
volar-server-bin
" ~/.config/nvim/plugin-config/monokai.vim
if exists('+termguicolors')
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
set termguicolors
endif
colorscheme monokai
" ~/.config/nvim/plugin-config/neosnippet.vim
" https://github.com/honza/vim-snippets
let g:neosnippet#snippets_directory = "~/.config/nvim/honza-snippets"
let g:neosnippet#disable_runtime_snippets = {'_' : 1}
imap <C-k> <Plug>(neosnippet_expand_or_jump)
smap <C-k> <Plug>(neosnippet_expand_or_jump)
xmap <C-k> <Plug>(neosnippet_expand_target)
imap <expr><TAB>
\ pumvisible() ? "\<C-n>" :
\ neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
smap <expr><TAB>
\ neosnippet#expandable_or_jumpable() ?
\ "\<Plug>(neosnippet_expand_or_jump)" : "\<TAB>"
if has('conceal')
set conceallevel=2 concealcursor=niv
endif
-- ~/.config/nvim/plugin-config/nvim-lspconfig.lua
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap = true, silent = true }
vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
require'lsp-format'.setup {
javascript = {
exclude = { "tsserver" }
},
typescript = {
exclude = { "tsserver" }
}
}
-- 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)
require'lsp-format'.on_attach(client)
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl',
'<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>f', '<cmd>lua vim.lsp.buf.format()<CR>', opts)
end
local servers = { 'jedi_language_server', 'vimls', 'tsserver', 'solargraph', 'bashls', 'clangd', 'lemminx', 'eslint', 'dockerls', 'yamlls', 'pyright' }
for _, lsp in pairs(servers) do
require'lspconfig'[lsp].setup {
on_attach = on_attach,
}
end
--Enable completion
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
require'lspconfig'.cssls.setup {
capabilities = capabilities,
on_attach = on_attach,
filetypes = { "css", "scss", "sass", "less" }
}
require'lspconfig'.html.setup {
capabilities = capabilities,
on_attach = on_attach,
}
require'lspconfig'.jsonls.setup {
capabilities = capabilities,
on_attach = on_attach,
}
require'lspconfig'.intelephense.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {
intelephense = {
format = { enable = true }
}
}
}
require'lspconfig'.perlpls.setup {
capabilities = capabilities,
on_attach = on_attach,
settings = {
pls = {
perlcritic = { enabled = true, perlcriticrc = os.getenv("HOME") .. "/.perlcriticrc" },
syntax = { enabled = true, perl = "/usr/bin/env perl" },
perltidy = { perltidyrc = os.getenv("HOME") .. "/.perltidyrc" }
}
}
}
require'lspconfig'.psalm.setup {
capabilities = capabilities,
on_attach = on_attach,
cmd = { 'vendor/bin/psalm-language-server' }
}
require'lspconfig'.phpactor.setup {
on_attach = on_attach,
init_options = {
["language_server_phpstan.enabled"] = false,
["language_server_psalm.enabled"] = false,
}
}
require'lspconfig'.sqls.setup {
on_attach = function(client, bufnr)
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl',
'<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
require'sqls'.on_attach(client, bufnr)
end
}
require'lspconfig'.lua_ls.setup {
settings = {
Lua = {
runtime = {
version = 'LuaJIT',
path = runtime_path,
},
diagnostics = {
globals = { 'vim' },
},
workspace = {
library = vim.api.nvim_get_runtime_file('', true),
checkThirdParty = false, -- THIS IS THE IMPORTANT LINE TO ADD
},
telemetry = {
enable = false,
},
},
},
}
require'lspconfig'.volar.setup {
capabilities = capabilities,
on_attach = on_attach,
init_options = {
typescript = {
tsdk = '/home/vini/.nvm/versions/node/v19.0.0/lib/node_modules/typescript/lib'
}
}
}
--DIAGNOSTIC
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
underline = true,
signs = true,
update_in_insert = true,
virtual_text = false,
max_width = 60,
max_height = 10,
}
)
--HOVER
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
vim.lsp.handlers.hover, {
border = "single",
focusable = false,
max_width = 40,
max_height = 15,
}
)
" ~/.config/nvim/plugin-config/vim-fake.vim
call fake#define('sex', 'fake#choice(["male", "female"])')
call fake#define('name', 'fake#int(1) ? fake#gen("male_name")'
\ . ' : fake#gen("female_name")')
call fake#define('fullname', 'fake#gen("name") . " " . fake#gen("surname")')
call fake#define('sentense', 'fake#capitalize('
\ . 'join(map(range(fake#int(3,15)),"fake#gen(\"nonsense\")"))'
\ . ' . fake#chars(1,"..............!?"))')
call fake#define('paragraph', 'join(map(range(fake#int(3,10)),"fake#gen(\"sentense\")"))')
call fake#define('lipsum', 'fake#gen("paragraph")')
call fake#define('age', 'float2nr(floor(110 * fake#betapdf(1.0, 1.45)))')
call fake#define('gtld', 'fake#get(fake#load("gtld"),'
\ . 'fake#betapdf(0.2, 3.0))')
call fake#define('email', 'tolower(substitute(printf("%s@%s.%s",'
\ . 'fake#gen("name"),'
\ . 'fake#gen("surname"),'
\ . 'fake#gen("gtld")), "\\s", "-", "g"))')
" ~/.config/nvim/plugin-config/vim-plug.vim
call plug#begin('~/.config/nvim/plugged')
Plug 'neovim/nvim-lspconfig'
Plug 'Shougo/context_filetype.vim'
if has('nvim')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
Plug 'deoplete-plugins/deoplete-lsp'
Plug 'Shougo/neopairs.vim'
Plug 'Shougo/echodoc.vim'
Plug 'Shougo/neoinclude.vim'
Plug 'Konfekt/FastFold'
Plug 'Shougo/neosnippet.vim'
Plug 'pixelastic/vim-undodir-tree'
Plug 'tpope/vim-obsession'
if has('nvim')
Plug 'Shougo/denite.nvim', { 'do': ':UpdateRemotePlugins' }
else
Plug 'Shougo/denite.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
Plug 'ConradIrwin/vim-bracketed-paste'
Plug 'jmckiern/vim-shoot', { 'do': '\"./install.py\" chromedriver' }
Plug 'gregsexton/matchtag'
Plug 'DougBeney/pickachu'
Plug 'tkhren/vim-fake'
Plug 'vimlab/split-term.vim'
Plug 'deoplete-plugins/deoplete-terminal'
Plug 'vim-scripts/loremipsum'
Plug 'ryanoasis/vim-devicons'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'windwp/nvim-ts-autotag'
Plug 'nanotee/sqls.nvim'
Plug 'lukas-reineke/lsp-format.nvim'
Plug 'tanvirtin/monokai.nvim'
Plug 'andymass/vim-matchup'
Plug 'jamestthompson3/nvim-remote-containers'
Plug 'lumiliet/vim-twig'
Plug 'jwalton512/vim-blade'
Plug 'othree/html5.vim'
Plug 'sbdchd/neoformat'
Plug 'tpope/vim-commentary'
Plug 'chrisbra/Colorizer'
call plug#end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment