|
" install vim-plug if needed. |
|
if empty(glob('~/.local/share/nvim/site/autoload/plug.vim')) |
|
silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs |
|
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |
|
autocmd VimEnter * PlugInstall --sync | source ~/.config/nvim/init.vim |
|
endif |
|
|
|
" Specify a directory for plugins |
|
" - For Neovim: stdpath('data') . '/plugged' |
|
" - Avoid using standard Vim directory names like 'plugin' |
|
call plug#begin(stdpath('config').'/plugged') |
|
|
|
" Make sure you use single quotes |
|
" elixir |
|
Plug 'elixir-editors/vim-elixir' |
|
Plug 'elixir-lsp/elixir-ls', { 'do': { -> g:ElixirLS.compile() } } |
|
" language server protocol (lsp) |
|
Plug 'neoclide/coc.nvim', {'branch': 'release'} |
|
" statusline |
|
Plug 'vim-airline/vim-airline' |
|
Plug 'vim-airline/vim-airline-themes' |
|
" theme |
|
Plug 'morhetz/gruvbox' |
|
" vertical lines at each indentation level |
|
Plug 'Yggdroot/indentLine' |
|
" comment manipulation |
|
Plug 'preservim/nerdcommenter' |
|
" fzf - fuzzy search |
|
Plug 'junegunn/fzf' |
|
Plug 'junegunn/fzf.vim' |
|
" file system / tree explorer |
|
Plug 'preservim/nerdtree' |
|
" icons |
|
Plug 'ryanoasis/vim-devicons' |
|
" git |
|
Plug 'tpope/vim-fugitive' |
|
Plug 'junegunn/gv.vim' |
|
Plug 'airblade/vim-gitgutter' |
|
" tags |
|
Plug 'majutsushi/tagbar' |
|
" Surround.vim is all about 'surroundings': parentheses, brackets, quotes, XML tags, and more |
|
Plug 'tpope/vim-surround' |
|
" multiple cursor |
|
Plug 'terryma/vim-multiple-cursors' |
|
" rust |
|
Plug 'rust-lang/rust.vim' |
|
" emmet |
|
Plug 'mattn/emmet-vim' |
|
" undo tree |
|
Plug 'simnalamburt/vim-mundo' |
|
" move line/selection left/right up/down |
|
Plug 'matze/vim-move' |
|
" just to solve disappearing quotes in json because of indentLines plug [patch-1] |
|
Plug 'elzr/vim-json' |
|
" fancy start screen |
|
Plug 'mhinz/vim-startify' |
|
|
|
" Initialize plugin system |
|
call plug#end() |
|
|
|
" the prefix to use for leader commands |
|
let mapleader=" " |
|
|
|
" switches to absolute line numbers automatically when relative numbers don't make sense. |
|
set number relativenumber |
|
augroup numbertoggle |
|
autocmd! |
|
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu | set rnu | endif |
|
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif |
|
augroup END |
|
" toggle line number mode |
|
nnoremap <silent> <F7> :set relativenumber!<cr> |
|
|
|
" enable highlighting of the current cursor position |
|
" set cursorline |
|
" set cursorcolumn |
|
|
|
" set syntax theme |
|
syntax on |
|
set termguicolors " try `:set notermguicolors` for comparison |
|
colorscheme gruvbox |
|
set background=dark |
|
" gruvbox clearly not good as airline theme |
|
let g:airline_theme='simple' |
|
|
|
" set column guide |
|
set textwidth=80 |
|
set colorcolumn=+1 |
|
|
|
" reduce travel time to reach <Esc> key |
|
imap kj <Esc> |
|
imap jk <Esc> |
|
|
|
" set mouse mode |
|
set mouse=a |
|
|
|
" bind to system clipboard (install xclip, see :h clipboard) |
|
set clipboard+=unnamedplus |
|
|
|
" keep block cursor on insert mode |
|
set guicursor= |
|
|
|
" don't highlight all matched |
|
set nohlsearch |
|
|
|
" Make searching case insensitive |
|
set ignorecase |
|
" ... unless the query has capital letters. |
|
set smartcase |
|
|
|
" keep hlsearch while searching |
|
set incsearch |
|
augroup incsearchHighlight |
|
autocmd! |
|
autocmd CmdlineEnter /,\? :set hlsearch |
|
autocmd CmdlineLeave /,\? :set nohlsearch |
|
augroup END |
|
|
|
" keep the cursor a bit far than the edges (bottom & top) always |
|
set scrolloff=10 |
|
|
|
" turn on spellcheck for comments |
|
set spell spelllang=en |
|
|
|
" no temp shits |
|
set nobackup |
|
set noswapfile |
|
|
|
" indent related shits |
|
set smartindent |
|
set tabstop=4 |
|
set softtabstop=4 |
|
set shiftwidth=4 |
|
set expandtab |
|
|
|
" show hidden characters |
|
set list |
|
set listchars=tab:→\ ,space:·,nbsp:␣,trail:•,precedes:«,extends:» |
|
|
|
""""""""""""""""""""""""""""" |
|
" Coc - lsp |
|
"""""""""""""""""""""""""""""""" |
|
let g:coc_global_extensions = ['coc-elixir', 'coc-diagnostic', 'coc-json', 'coc-rls', "coc-pairs"] |
|
|
|
" TextEdit might fail if hidden is not set. |
|
set hidden |
|
|
|
" Some servers have issues with backup files, see #649. |
|
set nobackup |
|
set nowritebackup |
|
|
|
" Give more space for displaying messages. |
|
set cmdheight=2 |
|
|
|
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable |
|
" delays and poor user experience. |
|
set updatetime=50 |
|
|
|
" Don't pass messages to |ins-completion-menu|. |
|
set shortmess+=c |
|
|
|
" Always show the signcolumn, otherwise it would shift the text each time |
|
" diagnostics appear/become resolved. |
|
set signcolumn=yes |
|
" disable signcolumn for tagbar, nerdtree, as thats useless |
|
autocmd FileType tagbar,nerdtree setlocal signcolumn=no |
|
|
|
" Use tab for trigger completion with characters ahead and navigate. |
|
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by |
|
" other plugin before putting this into your config. |
|
inoremap <silent><expr> <TAB> |
|
\ pumvisible() ? "\<C-n>" : |
|
\ <SID>check_back_space() ? "\<TAB>" : |
|
\ coc#refresh() |
|
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" |
|
|
|
function! s:check_back_space() abort |
|
let col = col('.') - 1 |
|
return !col || getline('.')[col - 1] =~# '\s' |
|
endfunction |
|
|
|
" Use <c-space> to trigger completion. |
|
inoremap <silent><expr> <c-space> coc#refresh() |
|
|
|
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current |
|
" position. Coc only does snippet and additional edit on confirm. |
|
" <cr> could be remapped by other vim plugin, try `:verbose imap <CR>`. |
|
if exists('*complete_info') |
|
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>" |
|
else |
|
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" |
|
endif |
|
|
|
"""""""""""""""""""""""""""""""" |
|
" Elixir - thanks to: https://bernheisel.com/blog/vim-elixir-ls-plug/ |
|
"""""""""""""""""""""""""""""""" |
|
" Define elixir_ls dictionary |
|
let g:ElixirLS = {} |
|
let ElixirLS.path = stdpath('config').'/plugged/elixir-ls' |
|
let ElixirLS.lsp = ElixirLS.path.'/release/language_server.sh' |
|
let ElixirLS.cmd = join([ |
|
\ 'asdf install &&', |
|
\ 'mix do', |
|
\ 'local.hex --force --if-missing,', |
|
\ 'local.rebar --force,', |
|
\ 'deps.get,', |
|
\ 'compile,', |
|
\ 'elixir_ls.release' |
|
\ ], ' ') |
|
|
|
" run it in background |
|
function ElixirLS.on_stdout(_job_id, data, _event) |
|
let self.output[-1] .= a:data[0] |
|
call extend(self.output, a:data[1:]) |
|
endfunction |
|
|
|
let ElixirLS.on_stderr = function(ElixirLS.on_stdout) |
|
|
|
function ElixirLS.on_exit(_job_id, exitcode, _event) |
|
if a:exitcode[0] == 0 |
|
echom '>>> ElixirLS compiled' |
|
else |
|
echoerr join(self.output, ' ') |
|
echoerr '>>> ElixirLS compilation failed' |
|
endif |
|
endfunction |
|
|
|
function ElixirLS.compile() |
|
let me = copy(g:ElixirLS) |
|
let me.output = [''] |
|
echom '>>> compiling ElixirLS' |
|
let me.id = jobstart('cd ' . me.path . ' && git pull && ' . me.cmd, me) |
|
endfunction |
|
|
|
" update the Elixir language server |
|
call coc#config('elixir', { |
|
\ 'command': g:ElixirLS.lsp, |
|
\ 'filetypes': ['elixir', 'eelixir'] |
|
\}) |
|
call coc#config('elixir.pathToElixirLS', g:ElixirLS.lsp) |
|
|
|
"""""""""""""""""""""""""""""""" |
|
" NerdTree |
|
"""""""""""""""""""""""""""""""" |
|
nnoremap <silent> <leader>tt :NERDTreeToggle<CR> |
|
|
|
" close vim if the only window left open is a NERDTree |
|
autocmd BufEnter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif |
|
|
|
" If you are using vim-plug, you'll also need to add these lines to avoid crashes when calling vim-plug functions while the cursor is on the NERDTree window: |
|
let g:plug_window = 'noautocmd vertical topleft new' |
|
|
|
" show dot/hidden files |
|
let NERDTreeShowHidden=1 |
|
|
|
""""""""""""""""""""""""""""""" |
|
" tags |
|
""""""""""""""""""""""""""""""" |
|
let g:tagbar_type_elixir = { |
|
\ 'ctagstype' : 'elixir', |
|
\ 'kinds' : [ |
|
\ 'p:protocols', |
|
\ 'm:modules', |
|
\ 'e:exceptions', |
|
\ 'y:types', |
|
\ 'd:delegates', |
|
\ 'f:functions', |
|
\ 'c:callbacks', |
|
\ 'a:macros', |
|
\ 't:tests', |
|
\ 'i:implementations', |
|
\ 'o:operators', |
|
\ 'r:records' |
|
\ ], |
|
\ 'sro' : '.', |
|
\ 'kind2scope' : { |
|
\ 'p' : 'protocol', |
|
\ 'm' : 'module' |
|
\ }, |
|
\ 'scope2kind' : { |
|
\ 'protocol' : 'p', |
|
\ 'module' : 'm' |
|
\ }, |
|
\ 'sort' : 0 |
|
\ } |
|
nnoremap <silent> <leader>tc :TagbarToggle<CR> |
|
|
|
""""""""""""""""""""""""""" |
|
" splits |
|
""""""""""""""""""""""""""" |
|
map - <C-W>- |
|
map + <C-W>+ |
|
|
|
nnoremap <leader>h :wincmd h<CR> |
|
nnoremap <leader>j :wincmd j<CR> |
|
nnoremap <leader>k :wincmd k<CR> |
|
nnoremap <leader>l :wincmd l<CR> |
|
|
|
"""""""""""""""""""""""""" |
|
" Rust |
|
"""""""""""""""""""""""""" |
|
" run rustfmt on save |
|
let g:rustfmt_autosave = 1 |
|
|
|
""""""""""""""""""""""""" |
|
" fzf |
|
""""""""""""""""""""""""" |
|
map \ :Files<CR> |
|
|
|
"""""""""""""""""""""""" |
|
" Mundo - undo tree |
|
"""""""""""""""""""""""" |
|
" Enable persistent undo so that undo history persists across vim sessions |
|
set undofile |
|
set undodir=~/.vim/undo |
|
|
|
nnoremap <leader>tu :MundoToggle<CR> |
|
|
|
"""""""""""""""""""""" |
|
" patch-1 |
|
"""""""""""""""""""""" |
|
let g:vim_json_syntax_conceal = 0 |
|
|
|
" save |
|
map <C-w> :w<cr> |
|
imap <C-w> <C-o>:w<cr> |