Skip to content

Instantly share code, notes, and snippets.

@thiagoramos23
Created November 27, 2021 03:37
Show Gist options
  • Save thiagoramos23/240a02149634c126e19e595607e99656 to your computer and use it in GitHub Desktop.
Save thiagoramos23/240a02149634c126e19e595607e99656 to your computer and use it in GitHub Desktop.
initvim-organized.vim
" set runtimepath^=~/.vim runtimepath+=~/.vim/after
" let &packpath = &runtimepath
" source ~/.vimrc
"'' VIM PRE-PLUG ''"
set nocompatible
filetype off
syntax enable
" PLUGINS
call plug#begin('~/.config/nvim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'master'}
Plug 'thiagoramos23/jump-to-test-file'
""" Themes
Plug 'morhetz/gruvbox'
""" Language Support ''"
Plug 'rust-lang/rust.vim'
Plug 'sheerun/vim-polyglot'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'vim-ruby/vim-ruby'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-rake'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-endwise'
Plug 'elixir-editors/vim-elixir'
Plug 'tpope/vim-bundler'
Plug 'tpope/vim-rhubarb'
Plug 'vim-test/vim-test'
Plug 'mhinz/vim-mix-format'
Plug 'terryma/vim-multiple-cursors'
" Built in LSP
Plug 'neovim/nvim-lspconfig'
" Nvim Completion
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
" For vsnip user.
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
Plug 'onsails/lspkind-nvim'
" Web Development
" Plug 'ap/vim-css-colors'
Plug 'mattn/emmet-vim'
" Fancy stuffs
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Plug 'ruanoais/vim-devicons'
" Plug 'dracula/vim', { 'name': 'dracula' }
"""Telescope
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-fzy-native.nvim'
Plug 'stsewd/fzf-checkout.vim'
" Utilities
Plug 'preservim/nerdcommenter'
Plug 'voldikss/vim-floaterm'
Plug 'vimwiki/vimwiki'
"Blame
Plug 'tveskag/nvim-blame-line'
"Dash Support
Plug 'rizzatti/dash.vim'
" Bookmarks
Plug 'MattesGroeger/vim-bookmarks'
"Tmux Navigator
Plug 'christoomey/vim-tmux-navigator'
" Tab Bar
Plug 'kyazdani42/nvim-web-devicons'
Plug 'romgrk/barbar.nvim'
" Git
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'shumphrey/fugitive-gitlab.vim'
call plug#end()
"'' END PLUG ''"
" BASIC CONFIGURATION {{{
filetype plugin indent on
set exrc
set path+=**
set wildmode=longest,list,full
set encoding=UTF-8
set cursorline
set showmatch
set linebreak
set ignorecase
set hidden
set smartcase
set clipboard+=unnamedplus
set tabstop=2
set shiftwidth=2
set softtabstop=2
set nobackup
set nowritebackup
set secure
set shortmess+=c
set termguicolors
set guicursor=
set updatetime=200
set cursorcolumn
set mouse=a
set spelllang=en_us
set nowrap
set number
set noshowmode
set relativenumber "" PogChamp
set foldenable
set foldmethod=marker
set foldmarker={{{,}}}
set fillchars+=vert:\ ,fold:-,eob:\
" BASIC STYLING
highlight Comment cterm=italic
highlight CursorLine ctermbg=Black cterm=NONE
highlight CursorLineNr ctermbg=Black ctermfg=Green
highlight LineNr ctermbg=Black ctermfg=White
highlight SpellBad ctermbg=Red ctermfg=White
highlight SpellCap cterm=NONE ctermbg=NONE
highlight SpellRare cterm=NONE ctermbg=NONE
highlight SpellLocal cterm=Underline ctermbg=NONE
" Customize cursor line
highlight CursorLine cterm=NONE ctermbg=Black
" highlight CursorLineNr cterm=Bold ctermbg=Black ctermfg=White
" highlight LineNr ctermbg=NONE ctermfg=White
highlight VertSplit ctermbg=Black
" Customize folds
highlight Folded ctermfg=White ctermbg=NONE cterm=bold
" }}}
" BASIC KEY BINDING "'' VIM Keymaps ''"
nnoremap vv :vsp<CR>
nnoremap ss :sp<CR>
nnoremap <silent> <c-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <c-j> :TmuxNavigateDown<cr>
nnoremap <silent> <c-k> :TmuxNavigateUp<cr>
nnoremap <silent> <c-l> :TmuxNavigateRight<cr>
nnoremap <leader>ev :vsplit ~/.vimrc<cr>
nnoremap <leader>sv :source ~/.vimrc<cr>
let mapleader=","
" COC EXPLORE KEY BINDING
nmap <C-]> :CocCommand explorer --width 60<CR>
nmap <space>e :CocCommand explorer --preset floating<CR>
" Swap current line with lower line
map <leader>x ddp
" Toogle spellchecker
map <leader>s :setlocal spell!<CR>
"'' VIM Keymaps ''"
nnoremap vv :vsp<CR>
nnoremap ss :sp<CR>
nnoremap <silent> <c-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <c-j> :TmuxNavigateDown<cr>
nnoremap <silent> <c-k> :TmuxNavigateUp<cr>
nnoremap <silent> <c-l> :TmuxNavigateRight<cr>
nnoremap <leader>ev :vsplit ~/.config/nvim/init.vim<cr>
nnoremap <leader>sv :source ~/.config/nvim/init.vim<cr>
nmap <silent> <leader>qq :nohlsearch<CR>
noremap <silent> zz %
nnoremap <silent> <Leader>co :copen 20<CR>
nnoremap <silent> <Leader>cl :cexpr []<CR>
" " Copy to clipboard
vnoremap <leader>y "+y
nnoremap <leader>Y "+yg_
nnoremap <leader>y "+y
nnoremap <leader>yy "+yy
" Yank all
nnoremap <leader>ya ggVGy<C-o>
" " Paste from clipboard
nnoremap <leader>p "+p
nnoremap <leader>P "+P
vnoremap <leader>p "+p
vnoremap <leader>P "+P
" SEARCH
nnoremap <leader>r yiw:%s/\<<C-r>"\>/<C-r>"/gc<left><left><left>
nnoremap <leader>f yiw:/\<<C-r>"\><left><left><left>
" BLAME
nnoremap <silent> <leader>b :ToggleBlameLine<CR>
" TEST
nmap <silent> <leader>rn :TestNearest<CR>
nmap <silent> <leader>rf :TestFile<CR>
nmap <silent> <leader>rs :TestSuite<CR>
nmap <silent> <leader>rl :TestLast<CR>
nmap <silent> <leader>rv :TestVisit<CR>
let g:test#strategy = "vimux"
" }}}
" REMAP TABKEY {{{
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>
" }}}
" FLOATERM {{
"'' Floatterm ''"
if filereadable(expand("~/.config/nvim/plugged/vim-floaterm/plugin/floaterm.vim"))
nnoremap <leader>fl :FloatermNew --autoclose=2 --height=0.9 --width=0.9 --wintype=floating lazygit<CR>
nnoremap <leader>fr :FloatermNew --autoclose=2 --height=0.75 --width=0.75 --wintype=floating ranger<CR>
nnoremap <leader>ft :FloatermNew --autoclose=2 --height=0.9 --width=0.9 --wintype=floating<CR>
endif
" }}}
" COLOR SCHEME {{{
colorscheme gruvbox
set background=dark
" }}}
" EMMET-VIM {{{
let g:user_emmet_leader_key='<C-Z>'
let g:user_emmet_mode='a' "enable all function in all mode.
" let g:user_emmet_install_global = 0
" autocmd FileType html,css EmmetInstall
" }}}
" VIM AIRLINE THEME {{{
let g:airline#extensions#tabline#enabled = 1
let g:airline_powerline_fonts = 0
" let g:airline_theme='murmur'
" let g:airline_theme='minimalist'
let g:airline_theme='gruvbox'
" }}}
" TELESCOPE {{{
" Find files using Telescope command-line sugar.
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fb <cmd>Telescope live_grep<cr>
nnoremap <leader>. <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
" Using Lua functions
nnoremap <leader>ff <cmd>lua require('telescope.builtin').find_files()<cr>
nnoremap <leader>fs <cmd>lua require('telescope.builtin').live_grep()<cr>
nnoremap <leader>. <cmd>lua require('telescope.builtin').buffers()<cr>
nnoremap <leader>fh <cmd>lua require('telescope.builtin').help_tags()<cr>
lua << EOF
require('telescope').load_extension('fzy_native')
EOF
" }}}
" BUFFERS {{{
" Move to previous/next
"
nnoremap<silent> <C-s> :BufferPick<CR>
nnoremap <silent> <leader>z :BufferPrevious<CR>
nnoremap <silent> <leader>v :BufferNext<CR>
nnoremap <silent> <leader>d :BufferClose<CR>
" }}}
" COC EXTENSIONS {{{
if filereadable(expand("~/.config/nvim/plugged/coc.nvim/plugin/coc.vim"))
let g:coc_global_extensions=['coc-explorer', 'coc-tailwindcss']
endif
" }}}
" LSP ELIXIR CONFIG {{{
" START LSP
lua << EOF
local lspconfig = require("lspconfig")
-- Neovim doesn't support snippets out of the box, so we need to mutate the
-- capabilities we send to the language server to let them know we want snippets.
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
-- Setup our autocompletion. These configuration options are the default ones
-- copied out of the documentation.
local cmp = require("cmp")
cmp.setup({
snippet = {
expand = function(args)
-- For `vsnip` user.
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<C-y>"] = cmp.mapping.confirm({ select = true }),
},
sources = {
{ name = "nvim_lsp" },
{ name = "vsnip" },
},
formatting = {
format = require("lspkind").cmp_format({
with_text = true,
menu = {
nvim_lsp = "[LSP]",
},
}),
},
})
-- ELIXIR NVIM
-- A callback that will get called when a buffer connects to the language server.
-- Here we create any key maps that we want to have on that buffer.
local on_attach = function(_, bufnr)
local function map(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local map_opts = {noremap = true, silent = true}
map("n", "df", "<cmd>lua vim.lsp.buf.formatting()<cr>", map_opts)
map("n", "gt", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<cr>", map_opts)
map("n", "gd", "<cmd>lua vim.lsp.buf.definition()<cr>", map_opts)
map("n", "K", "<cmd>lua vim.lsp.buf.hover()<cr>", map_opts)
map("n", "gD", "<cmd>lua vim.lsp.buf.implementation()<cr>", map_opts)
map("n", "<c-k>", "<cmd>lua vim.lsp.buf.signature_help()<cr>", map_opts)
map("n", "1gD", "<cmd>lua vim.lsp.buf.type_definition()<cr>", map_opts)
-- These have a different style than above because I was fiddling
-- around and never converted them. Instead of converting them
-- now, I'm leaving them as they are for this article because this is
-- what I actually use, and hey, it works ¯\_(ツ)_/¯.
vim.cmd [[imap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>']]
vim.cmd [[smap <expr> <C-l> vsnip#available(1) ? '<Plug>(vsnip-expand-or-jump)' : '<C-l>']]
vim.cmd [[imap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>']]
vim.cmd [[smap <expr> <Tab> vsnip#jumpable(1) ? '<Plug>(vsnip-jump-next)' : '<Tab>']]
vim.cmd [[imap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>']]
vim.cmd [[smap <expr> <S-Tab> vsnip#jumpable(-1) ? '<Plug>(vsnip-jump-prev)' : '<S-Tab>']]
vim.cmd [[inoremap <silent><expr> <C-Space> compe#complete()]]
vim.cmd [[inoremap <silent><expr> <CR> compe#confirm('<CR>')]]
vim.cmd [[inoremap <silent><expr> <C-e> compe#close('<C-e>')]]
vim.cmd [[inoremap <silent><expr> <C-f> compe#scroll({ 'delta': +4 })]]
vim.cmd [[inoremap <silent><expr> <C-d> compe#scroll({ 'delta': -4 })]]
-- tell nvim-cmp about our desired capabilities
require("cmp_nvim_lsp").update_capabilities(capabilities)
end
-- Finally, let's initialize the Elixir language server
-- Replace the following with the path to your installation
local path_to_elixirls = vim.fn.expand("/Users/branches/server/elixir-ls/release/language_server.sh")
lspconfig.elixirls.setup({
cmd = {path_to_elixirls},
capabilities = capabilities,
on_attach = on_attach,
settings = {
elixirLS = {
-- I choose to disable dialyzer for personal reasons, but
-- I would suggest you also disable it unless you are well
-- aquainted with dialzyer and know how to use it.
dialyzerEnabled = false,
-- I also choose to turn off the auto dep fetching feature.
-- It often get's into a weird state that requires deleting
-- the .elixir_ls directory and restarting your editor.
fetchDeps = false
}
}
})
EOF
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment