automate/020_neovim.sh

500 lines
13 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# Install Neovim
apt install -y software-properties-common
apt install -y neovim
# Need to backport from sid
apt install -y #python-neovim python3-neovim
# python-neovim if notavailableasapackage
#pip2 install --user --upgrade neovim
#pip3 install --user --upgrade neovim
DEST=${1:-/etc/skel}
#ln -sfr ${DEST}/.vim ${DEST}/.config/nvim
mkdir -p ${DEST}/.config/nvim
mkdir -p ${DEST}/.config/nvim/bundle
mkdir -p ${DEST}/.config/nvim/colors
git clone http://github.com/VundleVim/Vundle.vim.git ${DEST}/.config/nvim/bundle/Vundle.vim
# http://github.com/Netherdrake/Dotfiles/blob/master/config/nvim/init.vim
#ln -sfr ${DEST}/.vimrc ${DEST}/.config/nvim/init.vim
# wget -c --directory-prefix ${DEST}/.config/nvim https://raw.githubusercontent.com/Netherdrake/Dotfiles/master/config/nvim/init.vim
cat > ${DEST}/.config/nvim/init.vim << 'EOF'
""""""""""""""""""""""""""""""""
"
" PACKAGE MANAGEMENT
"
""""""""""""""""""""""""""""""""
" not a vi
set encoding=utf-8
" start vundler
filetype off
set rtp+=~/.config/nvim/bundle/Vundle.vim
"call vundle#rc()
call vundle#begin('~/.config/nvim/bundle')
Plugin 'VundleVim/Vundle.vim'
" core plugins
Bundle "gmarik/vundle"
Bundle "flazz/vim-colorschemes"
Bundle "joshdick/onedark.vim"
Bundle "vim-scripts/candyman.vim"
"Bundle "kien/ctrlp.vim"
Bundle "ctrlpvim/ctrlp.vim"
" vim main plugins
Bundle "sjl/gundo.vim"
Bundle "bling/vim-airline"
Bundle "vim-airline/vim-airline-themes"
Bundle "ryanoasis/vim-devicons"
Bundle "jlanzarotta/bufexplorer"
Bundle "scrooloose/syntastic.git"
Bundle "vim-scripts/tComment"
Bundle "tpope/vim-surround"
Bundle "mileszs/ack.vim"
Bundle "rking/ag.vim"
Bundle "tpope/vim-fugitive"
Bundle 'jreybert/vimagit'
Bundle "henrik/vim-indexed-search"
Bundle "tpope/vim-abolish"
Bundle "tpope/vim-repeat"
Bundle "jiangmiao/auto-pairs"
Bundle "xolox/vim-session"
Bundle "xolox/vim-misc"
Bundle "editorconfig/editorconfig-vim"
Bundle "godlygeek/tabular"
Bundle "airblade/vim-gitgutter"
Bundle "Lokaltog/vim-easymotion"
Bundle "rhysd/clever-f.vim"
" togglable panels
Bundle "scrooloose/nerdtree"
Bundle "tpope/vim-vinegar"
Bundle "vim-scripts/taglist.vim"
Bundle "majutsushi/tagbar"
Bundle "sbdchd/neoformat"
" language vundles
Bundle "pangloss/vim-javascript"
Bundle "marijnh/tern_for_vim"
Bundle "othree/javascript-libraries-syntax.vim"
Bundle "fatih/vim-go"
" Bundle "klen/python-mode"
Bundle "plasticboy/vim-markdown"
Bundle "vim-scripts/c.vim"
" platformio
Bundle "coddingtonbear/neomake-platformio"
Bundle "maralla/completor.vim"
" databases
Bundle "vim-scripts/SQLUtilities"
Bundle "NagatoPain/AutoSQLUpperCase.vim"
" autocomplete
" Bundle "Valloric/YouCompleteMe"
Bundle 'davidhalter/jedi-vim'
Bundle "MarcWeber/vim-addon-mw-utils"
Bundle "tomtom/tlib_vim"
" snippets
Bundle "SirVer/ultisnips"
Bundle "honza/vim-snippets"
call vundle#end()
" enable all the plugins
filetype plugin indent on
""""""""""""""""""""""""""""""""
"
" SETTINGS & KEYBINDINGS
"
""""""""""""""""""""""""""""""""
set expandtab
set smarttab
set shiftwidth=4
set softtabstop=4
set tabstop=4
set autoindent
set ruler
set hidden
set ignorecase
set smartcase
set showmatch
set incsearch
set hls
set relativenumber
set ls=2
set cursorline
set nowrap
set backspace=indent,eol,start
set shell=/bin/bash
set completeopt -=preview
set textwidth=100
set wildmenu
set noshowmode
set cmdheight=1
" set autoread
" backup/persistance settings
set undodir=~/.vim/tmp/undo//
set backupdir=~/.vim/tmp/backup//
set directory=~/.vim/tmp/swap//
set backupskip=/tmp/*,/private/tmp/*"
set backup
set writebackup
set noswapfile
" persist (g)undo tree between sessions
set undofile
set history=100
set undolevels=100
" set <leader>
let mapleader=","
" enable mouse
set mouse=a
" show trailing whitespaces
set list
set listchars=tab:▸\ ,trail:¬,nbsp:.,extends:,precedes:
augroup ListChars2
au!
autocmd filetype go set listchars+=tab:\ \
autocmd ColorScheme * hi! link SpecialKey Normal
augroup END
" syntax highlighting
syntax on
"colorscheme candyman
colorscheme onedark
" session management
let g:session_directory = "~/.vim/session"
let g:session_autoload = "no"
let g:session_autosave = "no"
let g:session_command_aliases = 1
nnoremap <leader>so :OpenSession
nnoremap <leader>ss :SaveSession
nnoremap <leader>sd :DeleteSession<CR>
nnoremap <leader>sc :CloseSession<CR>
" togglables without FN keys
nnoremap <leader>1 :GundoToggle<CR>
set pastetoggle=<leader>2
nnoremap <leader>3 :TlistToggle<CR>
nnoremap <leader>4 :TagbarToggle<CR>
nnoremap <leader>5 :NERDTreeToggle<CR>
" visual reselect of just pasted
nnoremap gp `[v`]
"make enter break and do newlines
nnoremap <CR> O<Esc>j
nnoremap <leader>j i<CR><Esc>==
"make space in normal mode add space
nnoremap <Space> i<Space><Esc>l
" better scrolling
nnoremap <C-j> <C-d>
nnoremap <C-k> <C-u>
" consistent menu navigation
inoremap <C-j> <C-n>
inoremap <C-k> <C-p>
" intellij style autocomplete shortcut
inoremap <C-@> <C-x><C-o>
inoremap <C-Space> <C-x><C-o>
" ctrlP config
let g:ctrlp_map = "<c-p>"
nnoremap <leader>t :CtrlPMRU<CR>
nnoremap <leader>bp :CtrlPBuffer<CR>
" easy motion rebinded
nmap <leader>f <Plug>(easymotion-f2)
nmap <leader>F <Plug>(easymotion-F2)
" open vimrc
nnoremap <leader>v :e ~/.config/nvim/init.vim<CR>
nnoremap <leader>V :tabnew ~/.config/nvim/init.vim<CR>
" reload all open buffers
nnoremap <leader>Ra :tabdo exec "windo e!"
"map next-previous jumps
nnoremap <leader>m <C-o>
nnoremap <leader>. <C-i>
" Keep search matches in the middle of the window.
nnoremap n nzzzv
nnoremap N Nzzzv
" Use sane regexes
nnoremap <leader>/ /\v
vnoremap <leader>/ /\v
" Use :Subvert search
nnoremap <leader>// :S /
vnoremap <leader>// :S /
" Use regular replace
nnoremap <leader>s :%s /
vnoremap <leader>s :%s /
" Use :Subvert replace
nnoremap <leader>S :%S /
vnoremap <leader>S :%S /
" clever-f prompt
let g:clever_f_show_prompt = 1
let g:clever_f_across_no_line = 1
" airline
if !exists("g:airline_symbols")
let g:airline_symbols = {}
endif
let g:airline_theme="powerlineish"
let g:airline_powerline_fonts=1
let g:airline#extensions#branch#empty_message = "no .git"
let g:airline#extensions#whitespace#enabled = 0
let g:airline#extensions#syntastic#enabled = 1
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#tab_nr_type = 1 " tab number
let g:airline#extensions#tabline#fnamecollapse = 1 " /a/m/model.rb
let g:airline#extensions#hunks#non_zero_only = 1 " git gutter
" Syntastic
" show list of errors and warnings on the current file
nmap <leader>e :Errors<CR>
" turn to next or previous errors, after open errors list
nmap <leader>n :lnext<CR>
nmap <leader>p :lprevious<CR>
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
" check also when just opened the file
let g:syntastic_check_on_open = 1
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_enable_signs = 1
" syntastic checker for javascript.
" eslint is the only tool support JSX.
" If you don't need write JSX, you can use jshint.
" And eslint is slow, but not a hindrance
let g:syntastic_javascript_checkers = ['jshint']
" let g:syntastic_javascript_checkers = ['eslint']
" syntastic checker for python.
" let g:syntastic_python_checkers = ["pylint"]
" let g:syntastic_python_checkers = ["flake8"]
let g:syntastic_python_checkers = ['prospector']
" don't put icons on the sign column (it hides the vcs status icons of signify)
let g:syntastic_enable_signs = 1
" custom icons (enable them if you use a patched font, and enable the previous
" setting)
let g:syntastic_error_symbol = '✗'
let g:syntastic_warning_symbol = '⚠'
let g:syntastic_style_error_symbol = '✗'
let g:syntastic_style_warning_symbol = '⚠'
" YouCompleteMe
"let g:ycm_filetype_blacklist = {}
"let g:ycm_key_list_select_completion = []
"let g:ycm_key_list_previous_completion = []
"let g:ycm_key_invoke_completion = "<C-j>"
"let g:ycm_collect_identifiers_from_tags_files = 1
if executable("ag")
let g:ackprg = "ag --nogroup --column"
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
endif
" reload ctags
nnoremap <leader>C :!ctags -R --fields=+l --exclude=.git --exclude=log --exclude=tmp *<CR><CR>
" git and ack stuff
let g:gitgutter_enabled = 1
let g:gitgutter_realtime = 0
let g:gitgutter_eager = 0
nnoremap <leader>G mG:Git!
nnoremap <leader>g :Git
nnoremap <leader>A :!ag
nnoremap <leader>a :Ag!
""""""""""""""""""""""""""""""""
"
" PROGRAMMING LANGUAGES
"
""""""""""""""""""""""""""""""""
" vim-go settings
let g:go_fmt_command = "goimports"
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_structs = 1
" vim-go bindings
augroup FileType go
au!
au FileType go nmap gd <Plug>(go-def)
au FileType go nmap <Leader>dd <Plug>(go-def-vertical)
au FileType go nmap <Leader>dv <Plug>(go-doc-vertical)
au FileType go nmap <Leader>db <Plug>(go-doc-browser)
au FileType go nmap <Leader>i <Plug>(go-info)
au FileType go nmap <leader>r <Plug>(go-run)
au FileType go nmap <leader>b <Plug>(go-build)
au FileType go nmap <leader>t <Plug>(go-test)
augroup END
" General file runners for various languages
function! LangRunner()
if(&ft=="python")
nnoremap <leader>r :!python %<cr>
elseif(&ft=="ruby")
nnoremap <leader>r :!ruby %<cr>
elseif(&ft=="javascript")
nnoremap <leader>r :!node %<cr>
elseif(&ft=="php")
nnoremap <leader>r :!php %<cr>
elseif(&ft=="c")
nnoremap <leader>r :!make run<cr>
endif
endfunction
au BufEnter * call LangRunner()
" enable angular syntax
let g:used_javascript_libs = 'jquery,angularjs'
""""""""""""""""""""""""""""""""
"
" COOL HACKS
"
""""""""""""""""""""""""""""""""
" Make sure Vim returns to the same line when you reopen a file.
augroup line_return
au!
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
" Visual Mode */# from Scrooloose
function! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
endfunction
vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o>
" Text Highlighter = <leader>h[1-4]
function! HiInterestingWord(n)
" Save our location.
normal! mz
" Yank the current word into the z register.
normal! "zyiw
" Calculate an arbitrary match ID. Hopefully nothing else is using it.
let mid = 86750 + a:n
" Clear existing matches, but don't worry if they don't exist.
silent! call matchdelete(mid)
" Construct a literal pattern that has to match at boundaries.
let pat = '\V\<' . escape(@z, '\') . '\>'
" Actually match the words.
call matchadd("InterestingWord" . a:n, pat, 1, mid)
" Move back to our original location.
normal! `z
endfunction
nnoremap <leader>hh :call clearmatches()<CR>:noh<CR>
nnoremap <silent> <leader>h1 :call HiInterestingWord(1)<cr>
nnoremap <silent> <leader>h2 :call HiInterestingWord(2)<cr>
nnoremap <silent> <leader>h3 :call HiInterestingWord(3)<cr>
nnoremap <silent> <leader>h4 :call HiInterestingWord(4)<cr>
nnoremap <silent> <leader>h5 :call HiInterestingWord(5)<cr>
nnoremap <silent> <leader>h6 :call HiInterestingWord(6)<cr>
hi def InterestingWord1 guifg=#000000 ctermfg=16 guibg=#ffa724 ctermbg=214
hi def InterestingWord2 guifg=#000000 ctermfg=16 guibg=#aeee00 ctermbg=154
hi def InterestingWord3 guifg=#000000 ctermfg=16 guibg=#8cffba ctermbg=121
hi def InterestingWord4 guifg=#000000 ctermfg=16 guibg=#b88853 ctermbg=137
hi def InterestingWord5 guifg=#000000 ctermfg=16 guibg=#ff9eb8 ctermbg=211
hi def InterestingWord6 guifg=#000000 ctermfg=16 guibg=#ff2c4b ctermbg=195
highlight search ctermfg=white ctermbg=3423513
" better retab
fu! Retab()
:retab
:%s/\s\+$//
endfunction
""""""""""""""""""""""""""""""""
"
" BUG WORKAROUNDS
"
""""""""""""""""""""""""""""""""
" realign buffers when iterm goes fullscreen
augroup FixProportionsOnResize
au!
au VimResized * exe "normal! \<c-w>="
augroup END
" vim mode-switch lag fix
if ! has("gui_running")
set ttimeoutlen=10
augroup FastEscape
autocmd!
au InsertEnter * set timeoutlen=0
au InsertLeave * set timeoutlen=1000
augroup END
endif
" macos vs linux clipboard
if has("mac")
set clipboard+=unnamed
else
set clipboard=unnamedplus
endif
" make C-a, C-x work properly
set nrformats=
" potential lag fix
let g:matchparen_insert_timeout=1
" fix bufexplorer bug with hidden
let g:bufExplorerFindActive=0
EOF
# Only if you want to replace vim
#update-alternatives --install /usr/bin/vi vi /usr/bin/nvim 60
#update-alternatives --config vi
#update-alternatives --install /usr/bin/vim vim /usr/bin/nvim 60
#update-alternatives --config vim
#update-alternatives --install /usr/bin/editor editor /usr/bin/nvim 60
#update-alternatives --config editor