Last active
May 9, 2022 14:57
-
-
Save cedmundo/ec5c5e2640c83a60bd74519d04665ebf to your computer and use it in GitHub Desktop.
nvim/init.vim
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
set shell=/bin/bash | |
" Plugins | |
call plug#begin('~/.vim/plugged') | |
Plug 'ycm-core/YouCompleteMe' | |
Plug 'dense-analysis/ale' | |
Plug 'pangloss/vim-javascript' | |
Plug 'mxw/vim-jsx' | |
Plug '~/.fzf' | |
Plug 'junegunn/fzf.vim' | |
Plug 'davidosomething/vim-colors-meh' | |
Plug 'axvr/photon.vim' | |
Plug 'dbgx/lldb.nvim' | |
Plug 'igankevich/mesonic' | |
call plug#end() | |
filetype plugin indent on " required | |
" 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 photon | |
colorscheme industry | |
" 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 | |
" Spaces are better than a tab character | |
set expandtab | |
set smarttab | |
" Who wants an 8 character tab? Not me! | |
set shiftwidth=2 | |
set softtabstop=2 | |
" Enable mouse support in console | |
set mouse=a | |
" Got backspace? | |
set backspace=2 | |
" Incremental searching is sexy | |
set incsearch | |
" Highlight things that we find with the search | |
set hlsearch | |
" Python3 Support | |
let g:python_host_prog = '/usr/bin/python2' | |
let g:python3_host_prog = "/usr/bin/python3" | |
" GLSL Syntax | |
au BufNewFile,BufRead *.frag,*.vert,*.fp,*.vp,*.glsl setf glsl | |
" W to w | |
:command Qa qa | |
:command WQ wq | |
:command Wq wq | |
:command W w | |
:command Q q | |
" Replace visual selection | |
vnoremap <C-r> "hy:%s/<C-r>h//gc<left><left><left> | |
" Two spces on html files | |
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 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 | |
au BufReadPost,BufNewFile *.hbs set filetype=handlebars smartindent expandtab smarttab shiftwidth=2 softtabstop=2 | |
" Leader key | |
let mapleader = "," | |
" Ale | |
let g:ale_fixers = { 'javascript': ['standard', 'eslint'], 'elixir': ['mix_format'], 'python': ['black'], 'cpp': ['clang-format'] } | |
let g:ale_linters = { 'python': 'flake8', 'c': ['clangtidy'], 'cpp': ['clangtidy'] } | |
let g:ale_lint_on_enter = 1 | |
let g:ale_lint_on_text_changed = 0 | |
let g:ale_fix_on_save = 1 | |
let g:ale_c_parse_makefile = 1 | |
let g:ale_python_flake8_options = "--ignore=E501,W503" | |
" YCM configuration | |
let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py' | |
let g:ycm_key_invoke_completion = '<C-Space>' | |
let g:ale_cpp_clangtidy_checks = [] | |
let g:ale_cpp_clangtidy_executable = 'clang-tidy' | |
let g:ale_c_parse_compile_commands=1 | |
let g:ale_cpp_clangtidy_extra_options = '' | |
let g:ale_cpp_clangtidy_options = '' | |
let g:ale_set_balloons=1 | |
let g:ale_linters_explicit=1 | |
let g:airline#extensions#ale#enabled=1 | |
let g:ale_c_build_dir = 'build' | |
let g:ale_c_build_dir_names = ['build', 'bin'] | |
" Backup | |
set backupdir=~/.vim//,. | |
set directory=~/.vim//,. | |
" Custom hotkeys | |
map ñ ^ | |
map Ñ $h | |
map <A-d> Yp | |
map <A-q> c'<C-r>"'<ESC> | |
map <A-Q> c"<C-r>""<ESC> | |
" 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> | |
" Fold | |
set foldmethod=indent | |
set foldlevel=99 | |
set number relativenumber | |
augroup numbertoggle | |
autocmd! | |
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber | |
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber | |
augroup END | |
" set guicursor=a:blinkon100 | |
" let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1 | |
" " insert mode - line | |
" let &t_SI .= "\<Esc>[5 q" | |
" "replace mode - underline | |
" let &t_SR .= "\<Esc>[4 q" | |
" "common - block | |
" let &t_EI .= "\<Esc>[3 q" | |
" 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%% | |
nnoremap <F5> :make<CR> | |
nnoremap <F6> :make test<CR> | |
" nnoremap <F5> :LL next<CR> | |
" nnoremap <F6> :LL step<CR> | |
" nnoremap <F7> :LL finish<CR> | |
" nnoremap <F9> :LLsession load<CR> | |
" | |
" let s:debugMode = 0 | |
" function! ToggleDebugMode() | |
" if s:debugMode | |
" execute 'LLmode code' | |
" let s:debugMode = 0 | |
" else | |
" execute 'LLmode debug' | |
" let s:debugMode = 1 | |
" endif | |
" endfunction | |
" nnoremap <F8> :call ToggleDebugMode()<CR> | |
" | |
" function AddBreakpoint() | |
" execute 'LL b' expand('%:p') . ':' . line('.') | |
" endfunction | |
" nnoremap <F3> :call AddBreakpoint()<CR> | |
" nnoremap <F4> :LL run<CR> | |
" Augmenting Ag command using fzf#vim#with_preview function | |
" * fzf#vim#with_preview([[options], [preview window], [toggle keys...]]) | |
" * For syntax-highlighting, Ruby and any of the following tools are required: | |
" - Bat: https://github.com/sharkdp/bat | |
" - Highlight: http://www.andre-simon.de/doku/highlight/en/highlight.php | |
" - CodeRay: http://coderay.rubychan.de/ | |
" - Rouge: https://github.com/jneen/rouge | |
" | |
" :Ag - Start fzf with hidden preview window that can be enabled with "?" key | |
" :Ag! - Start fzf in fullscreen and display the preview window above | |
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> | |
" nnoremap <C-P> :FZF<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment