set nocompatible
filetype off

runtime! debian.vim

if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif

"""""""""""""""""""""""""""
" PLUGINS
"""""""""""""""""""""""""""

let g:SuperTabDefaultCompletionType = "<c-x><c-o>"

let g:polyglot_disabled = ['markdown']

set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()

Plugin 'VundleVim/Vundle.vim'
Plugin 'mileszs/ack.vim.git'
Plugin 'Shougo/neocomplete.vim'
Plugin 'tobyS/pdv.git'
Plugin 'scrooloose/syntastic.git'
Plugin 'majutsushi/tagbar'
Plugin 'leafgarland/typescript-vim.git'
Plugin 'SirVer/ultisnips.git'
Plugin 'taglist.vim'
" " Plugin 'bling/vim-airline.git'
Plugin 'vim-airline/vim-airline'
Plugin 'kchmck/vim-coffee-script.git'
" Plugin 'sheerun/vim-polyglot'
Plugin 'honza/vim-snippets.git'
Plugin 'tobyS/vmustache.git'
Plugin 'sjl/gundo.vim.git'
Plugin 'godlygeek/tabular.git'
Plugin 'tpope/vim-fugitive.git'
Plugin 'groenewege/vim-less.git'
Plugin 'arnaud-lb/vim-php-namespace.git'
Plugin 'tpope/vim-surround.git'
Plugin 'scrooloose/nerdtree'
Plugin 'nerdtree-ack'
" Plugin 'php-cs-fixer'
Plugin 'php-doc-upgrade'
Plugin 'php.vim'
Plugin 'closetag.vim'
Plugin 'vim-scripts/Emmet.vim'
" Plugin 'beyondwords/vim-twig'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'Xuyuanp/nerdtree-git-plugin'
Plugin 'jistr/vim-nerdtree-tabs'
Plugin 'raimondi/delimitmate'
Plugin 'dietsche/vim-lastplace.git'
Plugin 'tomtom/tcomment_vim'
Plugin 'ahri/vim-sesspit'
Plugin 'voronkovich/ctrlp-symfony2.vim'
Plugin 'Colorizer--Brabandt'
Plugin 'gregsexton/gitv'
Plugin 'markgandolfo/nerdtree-fetch.vim'
Plugin 'evandotpro/nerdtree-chmod'
Plugin 'shawncplus/phpcomplete.vim'
Plugin 'bronson/vim-trailing-whitespace'
Plugin 'jacoborus/tender'
" Plugin 'vexxor/phpdoc.vim'
Plugin 'Rican7/php-doc-modded'
Plugin 'mzlogin/vim-markdown-toc'
Plugin 'rosenfeld/conque-term'
" Plugin 'joonty/vdebug'
Plugin 'isRuslan/vim-es6'
Plugin 'suan/vim-instant-markdown'
"Plugin 'dracula/vim'
Plugin 'sniphpets/sniphpets-doctrine'
Plugin 'sniphpets/sniphpets'
"Plugin 'jaxbot/semantic-highlight.vim'
"Plugin 'thaerkh/vim-indentguides'
"Plugin 'nathanaelkane/vim-indent-guides'
Plugin 'Yggdroot/indentLine'
Plugin 'PotatoesMaster/i3-vim-syntax'
Plugin 'fatih/vim-go'
Plugin 'mhinz/vim-signify'
Plugin 'andrewradev/splitjoin.vim'
Plugin 'wahidrahim/resize-font'
Plugin 'skywind3000/asyncrun.vim'
Plugin 'valloric/listtoggle'
Plugin 'c9s/phpunit.vim'
" Plugin 'terryma/vim-multiple-cursors'
Plugin 'dkarter/bullets.vim'
Plugin 'connorholyday/vim-snazzy'
Plugin 'bluz71/vim-moonfly-colors'
Plugin 'glepnir/oceanic-material'
" " Plugin 'patstockwell/vim-monokai-tasty'
Plugin 'AlessandroYorba/Sierra'
Plugin 'junegunn/fzf'
Plugin 'ParamagicDev/vim-medic_chalk'
Plugin 'vim-ruby/vim-ruby'
Plugin 'Shadowsith/vim-ruby-autocomplete'
Plugin 'autozimu/LanguageClient-neovim'
Plugin 'joshdick/onedark.vim'

Plugin 'puremourning/vimspector'
Plugin 'MarcWeber/vim-addon-ruby-debug-ide'

Plugin 'cocopon/iceberg.vim'

Plugin 'voldikss/vim-floaterm'

Plugin 'liuchengxu/vim-which-key'

Plugin 'CoderCookE/vim-chatgpt'

Plugin 'joerdav/templ.vim'

call vundle#end()

"""""""""""""""""""""""""""
" THEME
"""""""""""""""""""""""""""

syntax on

if has('gui_running')
	" colorscheme tender
	" colorscheme dracula
	" colorscheme vim-monokai-tasty
	" colorscheme moonfly
    " set background=dark
    " colorscheme oceanic_material
	" colorscheme snazzy

    " let g:sierra_Midnight = 1
    " let g:sierra_Twilight = 1
    " let g:sierra_Sunset = 1

    let g:sierra_Pitch = 1
    " colorscheme sierra
	" colorscheme onedark
	colorscheme iceberg
else
	" colorscheme Tomorrow-Night-Bright
	" colorscheme onedark
	colorscheme iceberg
endif

set background=dark

if has("autocmd")
	filetype plugin on
	au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
endif

set statusline=%<%f%=%([%{Tlist_Get_Tagname_By_Line()}]%)

set completeopt-=preview

"""""""""""""""""""""""""""
" PLUGINS CONFIGURATION
"""""""""""""""""""""""""""

" SEMANTIC "
""""""""""""

if has('gui_running')
	let g:semanticEnableFileTypes = { 'javascript': 'js', 'vim': 'vim', 'php': 'php'}
endif

" NERDTREE-GIT "
""""""""""""""""
let g:NERDTreeGitStatusIndicatorMapCustom = {
	\ 'Modified'  : 'M',
	\ 'Staged'    : 'S',
	\ 'Untracked' : '?',
	\ 'Renamed'   : 'R',
	\ 'Unmerged'  : 'U',
	\ 'Deleted'   : '!',
	\ 'Dirty'     : 'D',
	\ 'Clean'     : 'C',
	\ 'Unknown'   : '?!'
\ }

let s:tlist_0_v_count = 0

" ChatGPT "
"""""""""""
let g:chat_gpt_max_tokens=2000
let g:chat_gpt_model='gpt-3.5-turbo'
let g:chat_gpt_session_mode=1
let g:chat_gpt_temperature = 0.7
let g:chat_gpt_lang = 'French'

vmap <silent> <leader>0 <Plug>(chatgpt-menu)

" Markdown preview "
""""""""""""""""""""
let g:vim_markdown_auto_insert_bullets = 1
let g:vim_markdown_follow_anchor = 1
let g:vim_markdown_autowrite = 0
let g:vim_markdown_conceal = 0
let g:instant_markdown_autostart = 0


" COLORIZER "
"""""""""""""

let g:colorizer_auto_color = 1

" SNIPS "
"""""""""

let g:snips_author = "Simon Vieille <simon@deblan.fr>"
let g:snips_email = "simon@deblan.fr"
let g:snips_github = "https://gitnet.fr/deblan"

let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
let g:UltiSnipsEditSplit="vertical"


" Floaterm "
""""""""""""

let g:floaterm_keymap_toggle = '<F4>'
let g:floaterm_keymap_new    = '<leader>t'
let g:floaterm_keymap_prev   = '<leader>p'
let g:floaterm_keymap_next   = '<leader>n'
let g:floaterm_keymap_kill   = '<leader>q'
let g:floaterm_height   = 0.95
let g:floaterm_width   = 0.95

" AIRLINE "
"""""""""""

let g:airline_powerline_fonts = 1

if !exists('g:airline_symbols')
    let g:airline_symbols = {}
endif

" unicode symbols
let g:airline_left_sep = '»'
let g:airline_left_sep = '▶'
let g:airline_right_sep = '«'
let g:airline_right_sep = '◀'
let g:airline_symbols.linenr = '␊'
let g:airline_symbols.linenr = '␤'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'
let g:airline_symbols.paste = 'ρ'
let g:airline_symbols.paste = 'Þ'
let g:airline_symbols.paste = '∥'
let g:airline_symbols.whitespace = 'Ξ'
let g:airline_theme = 'tender'

" airline symbols
if has('gui_running')
	let g:airline_left_sep = ''
	let g:airline_left_alt_sep = ''
	let g:airline_right_sep = ''
	let g:airline_right_alt_sep = ''
	let g:airline_symbols.branch = ''
	let g:airline_symbols.readonly = ''
	let g:airline_symbols.linenr = ''
endif

" CLOSETAG "
""""""""""""

au Filetype html,xml,xsl,php,jsp,jspf,twig source ~/.vim/bundle/closetag.vim/plugin/closetag.vim

" NERDTree "
""""""""""""

let g:nerdtree_tabs_open_on_gui_startup = 2
let g:nerdtree_tabs_open_on_console_startup = 2
let g:nerdtree_tabs_autoclose = 0
let NERDTreeCascadeSingleChildDir = 0
let NERDTreeCascadeOpenSingleChildDir = 1

" CTRLP Symfony "
"""""""""""""""""

command! Sfassets CtrlPSymfony2Assets
command! Sfconfigs CtrlPSymfony2Configs
command! Sfcontrollers CtrlPSymfony2Controllers
command! Sfmodels CtrlPSymfony2Entities
command! Sfentities CtrlPSymfony2Entities
command! Sfviews CtrlPSymfony2Views
command! Sfservices CtrlPSymfonyServices
command! Sfservicesdefinition CtrlPSymfonyServiceDefinition
command! Sfforms CtrlPSymfonyForms

" PHP-CS-FIXER "
""""""""""""""""

" let g:php_cs_fixer_level = ''
" let g:php_cs_fixer_php_path = "/usr/bin/php7.3"

" GUIDES

" CTAGS "
"""""""""

command! CT AsyncRun ctags **/*.php

" EMMET "
"""""""""

let g:user_emmet_expandabbr_key = '<c-e>'
let g:use_emmet_complete_tag = 1

let g:user_emmet_settings = {
\  'indentation' : '    ',
\  'php' : {
\    'extends': 'html',
\    'aliases' : {
\    },
\    'snippets' : {
\      'php': "<?php\n\t|\n?>",
\      'sf:exe' : "public function |Action()\n{\n\n}",
\      'pf' : "public function |()\n{\n\n}",
\      'ppf' : "protected function |()\n{\n\n}",
\      'pppf' : "private function |()\n{\n\n}",
\      'sf:pdo': "\\$con = Propel::getConnection();\n\\$stmt = \\$con->prepare('|');\n\\$stmt->bindValue();\n\\$stmt->execute();\n\\$results = \\$stmt->fetchAll();",
\      'b:add': "\\$builder->add(\n    '|',\n    TextType::class,\n    [\n        'label' => '',\n        'required' => true,\n        'attr' => [\n        ],\n        'constraints' => [\n        ],\n    ]\n);",
\      'b:addfile': "\\$builder->add(\n    \\$builder->create(\n        '|',\n        'file',\n        [\n            'label' => '',\n            'attr' => [\n            ],\n            'constraints' => [\n            ],\n        ]\n    )->addModelTransformer(new \\Trinity\\Component\\Form\\DataTransformer\\StringToFileTransformer(\\$builder->getData(), 'file'))\n);\n\n\\$builder->addEventSubscriber(\n    new \\Trinity\\Component\\Form\\EventListener\\FileDeleteFormListener(\n        \\$builder->getFormFactory(),\n        [\n            '|',\n        ]\n    )\n);",
\      'foreach': "foreach (\\$| as \\$k => \\$v) {\n\t\n}",
\      'vard': "echo '<pre>', var_dump(|), '</pre>';\n",
\      'vardd': "echo '<pre>', var_dump(|), '</pre>';\ndie;\n",
\      'class': "class | {\n\tpublic function __construct() {\n\t\n\t}\n}\n",
\      'cc': "/**\n * @var type\n */\n",
\      'if': "if (|) {\n\n}",
\      'for': "for ($u = 0; $u < |; $u++) {\n\t\n}",
\      'while': "while (|) {\n\n}",
\    }
\  },
\  'javascript' : {
\    'aliases' : {
\    },
\    'snippets' : {
\      'ready': "$(document).ready(function() {\n\t|\n});",
\      'closure': "(function($) {\n\t|\n})(jQuery);",
\      'load': "$(|).load('', function(datas) {});",
\      'if': "if (|) {\n\n}",
\      'for': "for (var u=0; u<|; u++) {\n\t\n}",
\      'while': "while (|) {\n\n}",
\    }
\  },
\  'xml' : {
\    'aliases' : {
\    },
\    'snippets' : {
\      'table': "<table name=\"\" phpName=\"\">\n\t\n</table>",
\      'column': "<column name=\"\" type=\"integer\" size=\"\" required=\"true\" />\n",
\      'fkey': "<foreign-key onUpdate=\"none\" foreignTable=\"\" onDelete=\"cascade\">\n\t\n</foreign-key>\n",
\      'reference': "<reference local=\"\" foreign=\"\"/>\n"
\    }
\  },
\  'twig' : {
\    'extends': 'html',
\    'aliases' : {
\    },
\    'snippets' : {
\      'if': "{% if | %}\n\n{% endif %}\n",
\      'else': "{% else %}\n",
\      'elseif': "{% elseif %}\n",
\      'twig': "{% | %}\n",
\      'include': "{% include \"|\" %}\n",
\      'render': "{% render \"|\" %}\n",
\      'vard':  "<pre>{{ dump(|) }}</pre>\n",
\      'vardd': "<pre>{{ dump(|) }}</pre>\n",
\      'debug': "<pre>{{ dump(|) }}</pre>\n",
\      'dump': "<pre>{{ dump(|) }}</pre>\n",
\      'for': "{% for key, value in | %}\n\n{% endfor %}\n"
\    }
\  }
\}

" GITGUTTER "
"""""""""""""

let g:gitgutter_max_signs = 1000

" CTAGS "
"""""""""

let Tlist_Process_File_Always = 1
let Tlist_Ctags_Cmd='/usr/bin/ctags'

" NEOCOMPLETE "
"""""""""""""""

function! s:my_cr_function()
	return neocomplete#close_popup() . "\<CR>"
	"return (pumvisible() ? "\<C-y>" : "" ) . "\<CR>"
	"inoremap <expr> <C-n> pumvisible() ? '<C-n>' :
	""	\ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
endfunction

if !exists('g:neocomplete#keyword_patterns')
    let g:neocomplete#keyword_patterns = {}
endif

if !exists('g:neocomplete#force_omni_input_patterns')
	let g:neocomplete#force_omni_input_patterns = {}
endif

let g:ruby_autocomplete_solargraph = 'solargraph'
let g:completor_ruby_omni_trigger = '([$\w]{1,}|\.[\w]*|::[$\w]*)$'

let g:acp_enableAtStartup = 0
let g:neocomplete#enable_at_startup = 1
let g:neocomplete#enable_smart_case = 1
let g:neocomplete#sources#syntax#min_keyword_length = 3
let g:neocomplete#force_omni_input_patterns.php = '\h\w*\|[^. \t]->\%(\h\w*\)\?\|\h\w*::\%(\h\w*\)\?'
let g:neocomplete#force_omni_input_patterns.ruby = '[^. *\t]\.\w*\|\h\w*::'
"let g:neocomplete#force_omni_input_patterns.php = '\h\w*\|[^- \t]->\w*'
let g:neocomplete#lock_buffer_name_pattern = '\*ku\*'
let g:neocomplete#sources#dictionary#dictionaries = {
    \ 'default' : '',
    \ 'vimshell' : $HOME.'/.vimshell_hist',
    \ 'scheme' : $HOME.'/.gosh_completions'
\ }
let g:neocomplete#disable_auto_complete = 1
let g:neocomplete#keyword_patterns['default'] = '\h\w*'

if !exists('g:LanguageClient_serverCommands')
	let g:LanguageClient_serverCommands = {}
	let g:LanguageClient_serverCommands.php = ['/home/simon/bin/phpactor', 'language-server']
	let g:LanguageClient_serverCommands.bash = ['bash-language-server', 'start']
	let g:LanguageClient_serverCommands.sh = ['bash-language-server', 'start']
	let g:LanguageClient_serverCommands.css = ['css-languageserver', '--stdio']
	let g:LanguageClient_serverCommands.scss = ['css-languageserver', '--stdio']
	let g:LanguageClient_serverCommands.js = ['quick-lint-js', '--stdin']
	let g:LanguageClient_serverCommands.typescript = ['typescript-language-server', '--stdio']
	let g:LanguageClient_serverCommands.typescriptreact = ['typescript-language-server', '--stdio']
	let g:LanguageClient_serverCommands.go = ['gopls', 'serve']
	let g:LanguageClient_serverCommands.templ = ['templ', 'lsp']
	let g:LanguageClient_serverCommands.ruby = ['/home/simon/bin/solargraph', 'stdio']
	let g:LanguageClient_serverCommands.dockerfile = ['docker-langserver', '--stdio']
endif

inoremap <expr><C-g> neocomplete#undo_completion()
inoremap <expr><C-l> neocomplete#complete_common_string()
inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>

inoremap <expr><TAB>
	\ pumvisible() ? "\<C-n>" :
	\ neosnippet#expandable_or_jumpable() ? "\<Plug>(neosnippet_expand_or_jump)" :
	\ "\<TAB>"

inoremap <expr><C-h> neocomplete#smart_close_popup()."\<C-h>"
inoremap <expr><BS> neocomplete#smart_close_popup()."\<C-h>"

" PDV (DOC) "
"""""""""""""

function! PhpSyntaxOverride()
  hi! def link phpDocTags  phpDefine
  hi! def link phpDocParam phpType
endfunction

augroup phpSyntaxOverride
  autocmd!
  autocmd FileType php call PhpSyntaxOverride()
augroup END

let g:pdv_template_dir = $HOME."/.vim/bundle/pdv/templates_snip/"
let g:pdv_cfg_autoEndFunction = 0
let g:pdv_cfg_autoEndClass = 0
let g:pdv_cfg_php4always = 0
let g:pdv_cfg_php4guess = 0
let g:pdv_cfg_annotation_Package = 0
let g:pdv_cfg_annotation_Version = 0
let g:pdv_cfg_annotation_Copyright = 0
let g:pdv_cfg_annotation_License = 0


" Vdebug "
""""""""""

let g:vdebug_options = {}
let g:vdebug_options['port'] = 9000

" Clipboard "
"""""""""""""

vmap <C-c> "+yi
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <ESC>"+pa

" PHPDOC "
""""""""""

noremap <F11> :call PhpDoc()<CR>

"""""""""""""""""""""""""""
" MAPPING
"""""""""""""""""""""""""""

" set keywordprg=pman
let mapleader = "_"

map <F1>  :!indentation %<CR>
map <F2>  :!php8.0 ~/php-cs-fixer.phar fix "%" --rules=@PhpCsFixer<CR>
map <F8>  :!phpmd % text /usr/share/phpmd/psr2.xml \| cut -d: -f2-<CR>
map <c-B> :!php -l %<CR>
map <c-s> :w<CR>
map <F6>  :call PhpInsertUse()<CR>

vmap <leader>cc :s/\%V_\([a-z]\)/\U\1/g<cr>
vmap <leader>sc :s/\%V\([A-Z]\)/_\L\1/g<cr>
vmap <leader>lc <leader>sc<cr>

nmap <leader>cc vaw<leader>cc
nmap <leader>sc vaw<leader>sc
nmap <leader>lc vaw<leader>sc
nmap <F7> ins<tab><esc>o
nmap <c-Down> :ResizeFontSmaller<CR>
nmap <c-Up> :ResizeFontBigger<CR>

inoremap <silent> <Bar>   <Bar><Esc>:call <SID>align()<CR>a

function! s:align()
  let p = '^\s*|\s.*\s|\s*$'
  if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
    let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
    let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
    Tabularize/|/l1
    normal! 0
    call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  endif
endfunction

"""""""""""""""""""""""""""
" VIM INSPECTOR
"""""""""""""""""""""""""""

"" for normal mode - the word under the cursor
nmap <Leader>di <Plug>VimspectorBalloonEval
" for visual mode, the visually selected text
xmap <Leader>di <Plug>VimspectorBalloonEval

"""""""""""""""""""""""""""
" UI AND EDITION
"""""""""""""""""""""""""""

set mouse=a
set autoindent
set nu
set rnu
set showmatch
set tabstop=4
set shiftwidth=4
set softtabstop=4
set incsearch
set wildmenu
set cursorline
"set guipty
set fdc=2
set splitbelow
set splitright
set hlsearch
set nomodeline
set clipboard=unnamedplus

" set modeline
" set guifont=Consolas\ 13
" set guifont=Fantasque\ Sans\ Mono\ 14
set guifont=JetBrains\ Mono\ Medium\ 14

autocmd FileType php setlocal expandtab omnifunc=LanguageClient#complete
autocmd FileType javascript setlocal expandtab shiftwidth=2 softtabstop=2 omnifunc=javascriptcomplete#CompleteJS
autocmd FileType js setlocal expandtab shiftwidth=2 softtabstop=2 omnifunc=javascriptcomplete#CompleteJS
autocmd FileType vue setlocal expandtab shiftwidth=2 softtabstop=2 omnifunc=javascriptcomplete#CompleteJS
autocmd FileType xml setlocal expandtab omnifunc=xmlcomplete#CompleteTags
autocmd FileType css setlocal expandtab shiftwidth=2 softtabstop=2 omnifunc=LanguageClient#complete
autocmd FileType scss setlocal expandtab shiftwidth=2 softtabstop=2 omnifunc=LanguageClient#complete
autocmd FileType coffee setlocal expandtab
autocmd FileType html setlocal expandtab omnifunc=htmlcomplete#CompleteTags
autocmd FileType twig setlocal expandtab omnifunc=htmlcomplete#CompleteTags
autocmd FileType markdown setlocal expandtab omnifunc=htmlcomplete#CompleteTags
autocmd FileType json setlocal expandtab
autocmd FileType python setlocal noexpandtab omnifunc=pythoncomplete#Complete
autocmd FileType ruby setlocal omnifunc=LanguageClient#complete
autocmd FileType go setlocal omnifunc=LanguageClient#complete
autocmd FileType templ setlocal omnifunc=LanguageClient#complete
autocmd FileType bash setlocal omnifunc=LanguageClient#complete
autocmd FileType sh setlocal omnifunc=LanguageClient#complete
autocmd filetype typescript setlocal expandtab shiftwidth=2 softtabstop=2 tabstop=2 omnifunc=languageclient#complete
autocmd filetype typescriptreact setlocal expandtab shiftwidth=2 softtabstop=2 tabstop=2 omnifunc=languageclient#complete
autocmd FileType dockerfile setlocal omnifunc=LanguageClient#complete

au BufRead,BufNewFile *.yaml,*.yml setfiletype yaml
au BufRead,BufNewFile *.vue setfiletype html
au BufRead,BufNewFile *.html.twig,*.twig setfiletype twig
au BufRead,BufNewFile *.js setfiletype js
" au BufRead,BufNewFile *.templ setfiletype go
