Files
huhuhu_config/config_files/.vimrc
T

287 lines
9.4 KiB
VimL

"#hugogogo#
" ---------------------------------------------------------------------
" base settings
" ---------------------------------------------------------------------
" Show (partial) command in status line.
"set showcmd
" Show matching brackets.
set showmatch
" Do case insensitive matching
set ignorecase
" Do smart case matching
set smartcase
" set the backspace key to
set backspace=indent,eol,start
" Incremental search
"set incsearch
" Automatically save before commands like :next and :make
"set autowrite
" Hide buffers when they are abandoned
set hidden
" Enable mouse usage (all modes)
"set mouse=a
set mouse=
" turns on syntax hilighting
syntax on
" the '<leader>' key used in the mappings below (default '\', but '\'
" needs AltGr on spanish keyboards and does not always reach vim)
let mapleader = ","
" ---------------------------------------------------------------------
" colors
" ---------------------------------------------------------------------
" vim detects the terminal background at startup : it queries the
" terminal when it supports it, and falls back to 'dark'. do NOT set
" 'background' manually here, it would override the detection and
" break one of the two computers. the scheme then adapts :
" 'default' on a light terminal, 'ron' on a dark one
"colo elflord
"colo murphy
if &background == "light"
colorscheme default
else
colo ron
endif
highlight Normal ctermbg=NONE
highlight nonText ctermbg=NONE
" ---------------------------------------------------------------------
" copy to clipboard
" ---------------------------------------------------------------------
" copy to the clipboard from vim : in visual mode, select text with
" 'v' (or 'V' for whole lines, Ctrl-v for a block), then type
" '<leader>y' ('<leader>' is ',' since it is set in base settings) :
" the selected lines are piped to 'wl-copy' and can be pasted
" anywhere (C-v, middle click). note : the range is whole lines, a
" partial-line selection copies the full lines. requires
" 'wl-clipboard' installed (for the screen-level equivalent, see
" the 'C-a Y' binding in .screenrc)
vnoremap <leader>y :w !wl-copy<CR><CR>
" ---------------------------------------------------------------------
" indentation
" ---------------------------------------------------------------------
" show existing tab with x spaces width
set tabstop=2
" when indenting with '>', use x spaces width
set shiftwidth=2
" indent new line like the previous one
set autoindent
" ---------------------------------------------------------------------
" display
" ---------------------------------------------------------------------
" show line number
set number
" whitespace characters are made visible
"set list
" don't allow wrap
set nowrap
" in wrap mode,
" show next lines instead of '@'
" break on words
set display=lastline
set lbr
" ---------------------------------------------------------------------
" file explorer (netrw)
" ---------------------------------------------------------------------
" using alternate buffer with Explore, ':b#'
" =0 ot go back to explore buffer
" =1 ot go back to last edited file
" see :help g:netrw_altfile
" ! not good :
" with =1 the alternate buffer is not changed, so
" las edited file is not last file before Explore, but the previous one
" use :Lexplore instead of :Explore
"let g:netrw_altfile = 0
" choose how to print list in :Explore window
" alternatively you can hit 'i' inside Explore window to switch between styles
" =0 is default
" =3 is tree style
let g:netrw_liststyle = 3
" ---------------------------------------------------------------------
" to use the syntax highlight of .ext on .ext2 files
" ---------------------------------------------------------------------
au BufRead *.tpp set syntax=cpp
au BufRead *.svelte set syntax=html
" ---------------------------------------------------------------------
" norminette
" ---------------------------------------------------------------------
" pour pouvoir utiliser la norminette partout
let g:norminette_exec = '~/.local/bin/norminette'
" ---------------------------------------------------------------------
" to move lines with Ctrl + arrow
" ---------------------------------------------------------------------
" normal mode : ':m+' moves the current line below the next one,
" ':m-2' moves it above the previous one (:help :move), and '>>'/'<<'
" indent / dedent it, keeping the cursor on the line with the
" trailing '<CR>k'. the C-h/j/k/l variants are the same without
" leaving the home row
nnoremap <C-Down> :m+<CR>
nnoremap <C-Up> :m-2<CR>
nnoremap <C-Right> >><CR>k
nnoremap <C-Left> <<<CR>k
nnoremap <C-j> :m+<CR>
nnoremap <C-k> :m-2<CR>
nnoremap <C-l> >><CR>k
nnoremap <C-h> <<<CR>k
" insert mode : escape, move the line, then come back to insert
" with 'gi' (resume at the last insert position). since the simple
" mapping loses replace mode, the <expr> versions check first if we
" are in replace mode ('R') and resume in the same mode
" for insert mode, check if replace mode before (both uses inoremap)
"inoremap <C-Down> <Esc>:m+<CR>gi
inoremap <expr> <C-Down> mode() ==# 'R' ? "\<Esc>:m+<CR>R" : "\<Esc>:m+<CR>gi"
"inoremap <C-Up> <Esc>:m-2<CR>gi
inoremap <expr> <C-Up> mode() ==# 'R' ? "\<Esc>:m-2<CR>R" : "\<Esc>:m-2<CR>gi"
"inoremap <C-Right> <Esc>>><CR>gi
inoremap <expr> <C-Right> mode() ==# 'R' ? "\<Esc>>><CR>kR" : "\<Esc>>><CR>gi"
"inoremap <C-Left> <Esc><<<CR>gi
inoremap <expr> <C-Left> mode() ==# 'R' ? "\<Esc><<<CR>kR" : "\<Esc><<<CR>gi"
inoremap <C-j> <Esc>:m+<CR>gi
inoremap <C-k> <Esc>:m-2<CR>gi
inoremap <C-l> <Esc>>><CR>gi
inoremap <C-h> <Esc><<<CR>gi
" visual mode : move the whole selection (using the marks '< and '>)
" or indent / dedent it, then reselect it with 'gv'
vnoremap <C-Down> :m'>+<CR>gv
vnoremap <C-Up> :m-2<CR>gv
vnoremap <C-Right> ><CR>gv
vnoremap <C-Left> <<CR>gv
vnoremap <C-j> :m'>+<CR>gv
vnoremap <C-k> :m-2<CR>gv
vnoremap <C-l> ><CR>gv
vnoremap <C-h> <<CR>gv
" move selection inside lines with Ctrl-Shift + left/right
vnoremap <C-S-Left> <Esc>`<<Left>i_<Esc>mz"_xgvx`zPgv<Left>o<Left>o
vnoremap <C-S-Right> <Esc>`><Right>gvxpgv<Right>o<Right>o
" ---------------------------------------------------------------------
" to move cursor inside wrapping
" ---------------------------------------------------------------------
" https://vim.fandom.com/wiki/Move_cursor_by_display_lines_when_wrapping
nnoremap <Down> gj
nnoremap <Up> gk
vnoremap <Down> gj
vnoremap <Up> gk
inoremap <Down> <C-o>gj
inoremap <Up> <C-o>gk
" ---------------------------------------------------------------------
" put swap files in a special directory
" ---------------------------------------------------------------------
" first create the needed directory
" https://stackoverflow.com/questions/1549263/how-can-i-create-a-folder-if-it-doesnt-exist-from-vimrc
silent !mkdir -p ~/.vim/swapfiles
" 'directory' tells vim where to put the swap files, instead of
" putting them in the current directory
" the double slash '//' ask vim to give to the swap file a name
" with its complete path, to avoid problems whene two files have
" the same name
set directory=~/.vim/swapfiles//
" ---------------------------------------------------------------------
" to autofill new files
" ---------------------------------------------------------------------
" to autofill a new Class.hpp file
function! HPPFile()
silent! 0r $HOME/.vim/templates/skeleton.hpp
%s/FileName/\=expand("%:t:r")/g
%s/FILENAME/\=toupper(expand("%:t:r"))/g
endfunction
" to autofill a new Class.cpp file
function! CPPFile()
silent! 0r $HOME/.vim/templates/skeleton.cpp
%s/FileName/\=expand("%:t:r")/g
endfunction
" to autofill a new main.cpp file
function! MAINCPPFile()
silent! 0r $HOME/.vim/templates/skeleton_main.cpp
endfunction
" to autofill a new Makefile file
function! MAKEFile()
silent! 0r $HOME/.vim/templates/skeleton_makefile
endfunction
" to autofill a new colors.h file
function! COLORFile()
silent! 0r $HOME/.vim/templates/skeleton_colors.h
endfunction
" to autofill a new tests.hpp file
function! TESTSFile()
silent! 0r $HOME/.vim/templates/skeleton_tests.hpp
endfunction
" to autofill a new html file
function! HTMLFile()
silent! 0r $HOME/.vim/templates/skeleton.html
endfunction
" autofill calls
autocmd BufNewFile *.hpp call HPPFile()
autocmd BufNewFile *.cpp if @% == 'main.cpp' | call MAINCPPFile() | else | call CPPFile()
autocmd BufNewFile Makefile call MAKEFile()
autocmd BufNewFile colors.h call COLORFile()
autocmd BufNewFile tests.hpp call TESTSFile()
autocmd BufNewFile *.html call HTMLFile()
" ---------------------------------------------------------------------
" pour mettre en gras dans des fichiers txt
" ---------------------------------------------------------------------
" BufEnter s'active quand un buffer est ouvert ou modifie
" setf = setfiletype defini un filetype text SI n'existe pas
" (!= 'set filetype=type') defini un new ft meme si existe
au BufEnter *.txt setf text
" conceal = hidden
" cocu (concealcursor) hidden in normal mode (v=visual i=insert)
" cole (conceallevel) hidden (0=not_hidden 1&2=replaced_by_smth)
au filetype text set cocu=n cole=3
" les trois lignes suivantes sont lancees par des auto commands
" pour declancher leur action malgre que les hilighting groups
" soient nettoyes par la commande 'hi clear' du fichier
" $VIMRUNTIME/color/default.vim
au filetype text hi AsteriskBold ctermfg=Green cterm=bold
au filetype text syn match Asterisks contained "\*\*" conceal
au filetype text syn match EscapedAsterisks contained "\\" conceal
au filetype text syn match AsteriskBold "\*\*.*\*\*" contains=Asterisks,EscapedAsterisks