Variable

%      : nom du fichier en cours (test.txt)
%:p    : chemin complet du fichier en cours (/home/user/test.txt)
%:p:h  : répertoire complet du fichier en cours (sans le nom du fichier et sans le dernier /,   /home/user.txt)

Trucs

Changer le répertoire en cours: :cd repertoire

vimdiff

Changer les couleurs affreuses de vimdiff (dans le fichier ~/.vimrc)

highlight DiffAdd cterm=none ctermfg=white ctermbg=green
highlight DiffDelete cterm=none ctermfg=white ctermbg=Red
highlight DiffChange cterm=none ctermfg=black ctermbg=Yellow
highlight DiffText cterm=none ctermfg=white ctermbg=Magenta

Remplacer

Remplacer <92> par un ' :%s/[\x92]/'/g (source: http://superuser.com/a/224526)

vim + tmux

Avec Vundle et vim+tmux

#vundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

# .vimrc
https://github.com/VundleVim/Vundle.vim
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'christoomey/vim-tmux-navigator'
call vundle#end()
filetype plugin indent on

# .tmux.conf
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n C-h if-shell "$is_vim" "send-keys C-h"  "select-pane -L"
bind-key -n C-j if-shell "$is_vim" "send-keys C-j"  "select-pane -D"
bind-key -n C-k if-shell "$is_vim" "send-keys C-k"  "select-pane -U"
bind-key -n C-l if-shell "$is_vim" "send-keys C-l"  "select-pane -R"
bind-key -n C-\ if-shell "$is_vim" "send-keys C-\\" "select-pane -l"
bind-key -T copy-mode-vi C-h select-pane -L
bind-key -T copy-mode-vi C-j select-pane -D
bind-key -T copy-mode-vi C-k select-pane -U
bind-key -T copy-mode-vi C-l select-pane -R
bind-key -T copy-mode-vi C-\ select-pane -l

Commande tmux: CTRL % (split). Commande Vim: CTRL-H (gauche), CTRL-L (droite), CTRL-J (haut), CTRL_K (bas)

Source: christoomey/vim-tmux-navigator

Mes configs

syntax on
" indentation selon le langage avec = 
let PHP_vintage_case_default_indent = 1
filetype plugin indent on

" pathogen from https://github.com/tpope/vim-pathogen
" SyntasticCheck from https://github.com/vim-syntastic/syntastic
" deb package phpcode-sniffer
execute pathogen#infect()

set nu
set ai
set ts=4
set et
set sts=4
set sw=4
set listchars=tab:»»,trail:-,nbsp:£
set list
set iskeyword+=-,:
set pastetoggle=<F3>

let php_parent_error_close = 1
let php_folding = 0
let php_noShortTags = 1
let php_sql_query = 0

" https://akrabat.com/checking-your-code-for-psr-2/
let g:syntastic_xml_checkers=[]
let g:syntastic_php_checkers=['php', 'phpcs']
let g:syntastic_php_phpcs_args='--standard=PSR12 -n'
let g:syntastic_javascript_checkers=['nodejs']

" appuyer sur "i" et F3 pour activer/désactiver le mode insertion (collage)
" pareil que :set paste / :set nopaste
set pastetoggle=<F3>

highlight DiffAdd cterm=none ctermfg=white ctermbg=green
highlight DiffDelete cterm=none ctermfg=white ctermbg=Red
highlight DiffChange cterm=none ctermfg=black ctermbg=Yellow
highlight DiffText cterm=none ctermfg=white ctermbg=Magenta

Indentation des array() php avec vim

Actuel: autoindent, expandtab, softtabstop=4, tabstop=4, filetype=php, shiftwidth=4, syntax=php
/usr/share/vim/vim80/syntax/php.vim, Jason Woofenden (Last Change: Dec 11, 2016)

Indentation actuelle avec la commande =

$a = array(
         'ab',
         'cd'
         );

Résultat attendu:

$a = array(
     'ab',
     'cd'
);

Test #2, https://github.com/2072/PHP-Indenting-for-VIm

1. installer vundle https://github.com/VundleVim/Vundle.vim#quick-start
2. résolu:
$a = array(
    'ab',
    'cd'
);
// avec filetype plugin indent on ???

Debugging with vim-vdebug, xdebug and vim-nox

cd ~/.vim/bundle
git clone https://github.com/vim-vdebug/vdebug.git

sudo apt install vim-nox php-xdebug

~/.vimrc
call pathogen#helptags()

# checking if xdebug is there
php -m | grep xdebug

in vim, press <F5>
in another window, launch script with
XDEBUG_CONFIG="idekey=xdebug" php -d xdebug.remote_enable=1 file.php
in vim, press <any key> or wait
other key: <F2> step over, <F3> step into , <F9> go to cursor, <F10> toggle breakpoint
press <F6> to end
:tabclose to close tab