Skip to content

Instantly share code, notes, and snippets.

@cedmundo
Last active October 14, 2024 07:46
Show Gist options
  • Save cedmundo/ec5c5e2640c83a60bd74519d04665ebf to your computer and use it in GitHub Desktop.
Save cedmundo/ec5c5e2640c83a60bd74519d04665ebf to your computer and use it in GitHub Desktop.
nvim/init.vim
set shell=/bin/bash
" Plugins
call plug#begin()
Plug 'preservim/tagbar'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'whonore/Coqtail'
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
Plug 'preservim/nerdtree'
call plug#end()
" required
filetype plugin indent on
" Backup
set backupdir=~/.vim//,.
set directory=~/.vim//,.
" Remove any trailing whitespace that is in the file
autocmd BufRead,BufWrite * if ! &bin | silent! %s/\s\+$//ge | endif
" Restore cursor position to where it was before
augroup JumpCursorOnEdit
au!
autocmd BufReadPost *
\ if expand("<afile>:p:h") !=? $TEMP |
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ let JumpCursorOnEdit_foo = line("'\"") |
\ let b:doopenfold = 1 |
\ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
\ let b:doopenfold = 2 |
\ endif |
\ exe JumpCursorOnEdit_foo |
\ endif |
\ endif
" Need to postpone using "zv" until after reading the modelines.
autocmd BufWinEnter *
\ if exists("b:doopenfold") |
\ exe "normal zv" |
\ if(b:doopenfold > 1) |
\ exe "+".1 |
\ endif |
\ unlet b:doopenfold |
\ endif
augroup END
" Needed for Syntax Highlighting and stuff
syntax enable
set grepprg=grep\ -nH\ $*
" Cool colors
set background=dark
" set t_8f=^[[38;2;%lu;%lu;%lum " Needed in tmux
" set t_8b=^[[48;2;%lu;%lu;%lum " Ditto
set termguicolors
colorscheme koehler
" Necesary for lots of cool vim things
set nocompatible
" No wrap
set nowrap
" Show line numbers
set number
" Who doesn't like autoindent?
set autoindent
" Enable mouse support in console
set mouse=a
" Spaces are better than a tab character
set expandtab
set smarttab
" Got backspace?
set backspace=2
" Who wants an 8 character tab? Not me!
set shiftwidth=2
set softtabstop=2
" Blinking cursor
set guicursor=a:blinkon100
" Show column 80
set colorcolumn=80,120
highlight ColorColumn ctermbg=235 guibg=#262626
" Two spces on html files
au FileType text set expandtab smarttab shiftwidth=2 softtabstop=2
au FileType html set expandtab smarttab shiftwidth=2 softtabstop=2
au FileType js set expandtab smarttab shiftwidth=2 softtabstop=2
au FileType rb set expandtab smarttab shiftwidth=2 softtabstop=2
au FileType ruby set expandtab smarttab shiftwidth=2 softtabstop=2
au FileType javascript set expandtab smarttab shiftwidth=2 softtabstop=2
au FileType css set expandtab smarttab shiftwidth=2 softtabstop=2
au FileType c set expandtab smarttab shiftwidth=2 softtabstop=2
au FileType php set expandtab smarttab shiftwidth=4 softtabstop=4
au FileType java set expandtab smarttab shiftwidth=4 softtabstop=4
au FileType gradle set expandtab smarttab shiftwidth=4 softtabstop=4
au FileType go set noexpandtab smarttab shiftwidth=8 softtabstop=8
" Incremental searching is sexy
set incsearch
" Highlight things that we find with the search
set hlsearch
" GLSL Syntax
au BufNewFile,BufRead *.frag,*.vert,*.fp,*.vp,*.glsl setf glsl
" Fold
set foldmethod=indent
set foldlevel=99
" Relative numbers (toggle absoltue on edit)
set number relativenumber
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
" StatusLine
" function! LinterStatus() abort
" let l:counts = ale#statusline#Count(bufnr(''))
"
" let l:all_errors = l:counts.error + l:counts.style_error
" let l:all_non_errors = l:counts.total - l:all_errors
"
" return l:counts.total == 0 ? 'OK' : printf(
" \ '%dW %dE',
" \ all_non_errors,
" \ all_errors
" \)
" endfunction
function! GitBranch()
return system("timeout 1 git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
endfunction
function! StatuslineGit()
let l:branchname = GitBranch()
return strlen(l:branchname) > 0?' '.l:branchname.' ':''
endfunction
" Status line
set laststatus=2
set statusline=
set statusline+=%#PmenuSel#
" set statusline+=%{LinterStatus()}
set statusline+=%{StatuslineGit()}
set statusline+=%#LineNr#
set statusline+=\ %f
set statusline+=%m\ %=
set statusline+=%#CursorColumn#
set statusline+=\ %y
set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
set statusline+=\[%{&fileformat}\]
set statusline+=\ %l:%c/%{line('$')}
set statusline+=\ %p%%
" Leader key
let mapleader = ","
" Command remaps, mostly accidental keyhits
:command Qa qa
:command WQ wq
:command Wq wq
:command W w
:command Q q
" Custom hotkeys
map ñ ^
map Ñ $h
map <A-d> yyp
map <A-q> c'<C-r>"'<ESC>
map <A-Q> c"<C-r>""<ESC>
" Replace visual selection
vnoremap <C-r> "hy:%s/<C-r>h//gc<left><left><left>
" For local replace
nnoremap gr gd[{V%::s/<C-R>///gc<left><left><left>
" For global replace
nnoremap gR gD:%s/<C-R>///gc<left><left><left>
" Compilation and testing
au FileType c nnoremap <F5> :make<CR>
au FileType c nnoremap <F6> :make test<CR>
" Fuzzy search
command! -bang -nargs=* Ag
\ call fzf#vim#ag(<q-args>,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
nnoremap <C-p> :Ag<CR>
" Configure with lua
lua <<EOF
-- Setup LSP
-- local lspconfig = require('lspconfig')
-- lspconfig.gopls.setup {}
-- Set up nvim-cmp.
local cmp = require'cmp'
cmp.setup({
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-b>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
}),
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
}, {
{ name = 'buffer' },
}),
})
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
}),
matching = { disallow_symbol_nonprefix_matching = false }
})
-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
require('lspconfig')['gopls'].setup {
capabilities = capabilities
}
require('lspconfig')['clangd'].setup {
capabilities = capabilities
}
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment