" nvim config from https://medium.com/better-programming/setting-up-neovim-for-web-development-in-2020-d800de3efacd
" https://www.vimfromscratch.com/articles/vim-for-python/
" http://nerditya.com/code/guide-to-neovim/
" https://medium.com/@hanspinckaers/setting-up-vim-as-an-ide-for-python-773722142d1d

call plug#begin("~/.vim/plugged")
  " Plugin Section

  Plug 'dracula/vim' 
  Plug 'scrooloose/nerdtree'
  Plug 'ryanoasis/vim-devicons'
  " fuzzy finder vs ctrl-p ???
  Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
  Plug 'junegunn/fzf.vim'
  " status/tabline
  Plug 'vim-airline/vim-airline'
  Plug 'vim-airline/vim-airline-themes' 
  " IntelliSense and Syntax Highlighting
  Plug 'neoclide/coc.nvim', {'branch': 'release'}
  let g:coc_global_extensions = ['coc-emmet', 'coc-css', 'coc-html', 'coc-json', 'coc-python', 'coc-prettier', 'coc-tsserver']
  " TypeScript and TSX support
  Plug 'leafgarland/typescript-vim'
  Plug 'peitalin/vim-jsx-typescript'

  " Tag navigation
  Plug 'majutsushi/tagbar'
  nmap <F8> :TagbarToggle<CR>

  " Automatic quote and bracket completion
  Plug 'jiangmiao/auto-pairs'

  " Comment
  Plug 'scrooloose/nerdcommenter'

  " Folding
  Plug 'tmhedberg/SimpylFold'
  " zo: Open fold in current cursor postion
  " zO: Open fold and sub-fold in current cursor postion recursively
  " zc: Close the fold in current cursor position
  " zC: Close the fold and sub-fold in current cursor position recursively
  " zM : close all folds
  " zm : close all folds level by level (if nested)
  " zR: open all folds
  " zr open all folds level by level (if nested)

  " kv language for kivy
  Plug 'farfanoide/vim-kivy'

  " generator for Python docstrings
  Plug 'heavenshell/vim-pydocstring', { 'do': 'make install' }

  " Todo manager
  Plug 'wsdjeg/vim-todo'

  " A Vim Automatic Window Resizing Plugin
  " Plug 'camspiers/animate.vim'
  " Plug 'camspiers/lens.vim'
  
  " all about surroundings: parentheses, brackets, quotes, XML tags, and more.
  Plug 'tpope/vim-surround'
  " Visually select text to be surrounded
  " Type S" to surround the text with double quotes


  " Mardown Preview
  "We can use grip for render a mardownfile
  " or
  Plug 'JamshedVesuna/vim-markdown-preview'
  "Plug 'suan/vim-instant-markdown', {'for': 'markdown'}

  " Simple color picker
  Plug 'KabbAmine/vCoolor.vim'
  " <Alt-C> : To insert a color anywhere & modify the current hex, rgb, rgba or hsl color.
  " <Alt-R> you can insert a rgb color anywhere (NORMAL and INSERT modes).
  " <Alt-V> you can insert a hsl color anywhere (NORMAL and INSERT modes).
  " <Alt-W> you can insert a rgba color anywhere (NORMAL and INSERT modes
  
  Plug 'ap/vim-css-color'

  Plug 'Yggdroot/indentLine'
  "char:  ¦, ┆, │, ⎸, or ▏
  let g:indentLine_char = ' ⎸'
  " let g:indentLine_char_list = ['|', '¦', '┆', '┊']
  " :IndentLinesToggle toggles lines on and off.
  " set cursorcolumn
  " set cursorline

  

  call plug#end()"Config Section

"set indentation for python
autocmd Filetype python setlocal ts=4 sw=4 sts=0 expandtab
" or set tabstop=4
" or
" :set tabstop=4 shiftwidth=4 expandtab
" for fix inentation:
" :retab
" for turn-on white space:
" :set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:·


if (has("termguicolors"))
 set termguicolors
endif
syntax enable
colorscheme dracula

set mouse=a

"let g:NERDTreeShowHidden = 1
let g:NERDTreeMinimalUI = 1
let g:NERDTreeIgnore = []
let g:NERDTreeStatusline = ''
" Automaticaly close nvim if NERDTree is only thing left open
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" Toggle
nnoremap <silent> <C-n> :NERDTreeToggle<CR>

" open new split panes to right and below
set splitright
set splitbelow
" turn terminal to normal mode with escape
tnoremap <Esc> <C-\><C-n>
" start terminal in insert mode
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
" open terminal on ctrl+n
function! OpenTerminal()
  split term://bash
  resize 10
endfunction
nnoremap <M-t> :call OpenTerminal()<CR>

" use alt+hjkl to move between split/vsplit panels
tnoremap <M-h> <C-\><C-n><C-w>h
tnoremap <M-j> <C-\><C-n><C-w>j
tnoremap <M-k> <C-\><C-n><C-w>k
tnoremap <M-l> <C-\><C-n><C-w>l
nnoremap <M-h> <C-w>h
nnoremap <M-j> <C-w>j
nnoremap <M-k> <C-w>k
nnoremap <M-l> <C-w>l

" config of FZF plugin
nnoremap <C-p> :FZF<CR>
let g:fzf_action = {
  \ 'ctrl-t': 'tab split',
  \ 'ctrl-s': 'split',
  \ 'ctrl-v': 'vsplit'
  \}
let $FZF_DEFAULT_COMMAND = 'ag -g ""'

" Limit char guideline
" https://vi.stackexchange.com/questions/356/how-can-i-set-up-a-ruler-at-a-specific-column
set colorcolumn=80,100
highlight ColorColumn ctermbg=darkgrey guibg=grey20

" Line numbering
set nu

" activation french dictionnary via F6
" `z`= sur un mot souligné affiche une liste de corrections possibles
" `zg` rajoute un mot dans le dictionnaire
" `zug` pour annuler l’ajout au dictionnaire
" `]s` pour aller au prochain mot mal orthographié
" `[s` pour le précédent

" Activer le correcteur orthographique français avec F6
map <silent> <F6> "<Esc>:silent setlocal spell! spelllang=fr<CR>"

" copier du texte dans le clipboard avec ctrl-c grace à xclip
" https://hunden.linuxkompis.se/2020/06/30/how-to-copy-text-to-clipboard-in-neovim.html
vmap <C-c> y:call system("xclip -i -selection clipboard", getreg("\""))<CR>:call system("xclip -i", getreg("\""))<CR>

" vim_mardown_preview
let vim_markdown_preview_github=1

" Clear search pattern register
map <Leader><Space> :noh<CR>