rc/config/nvim/init.old.vim
nemirwen b275d74db5 Transition setup to modern neovim
Abandon common config for both vim and neovim, as the neovim ecosystem
is just diverging more and more. For now the goals is to have an
IDE-like neovim config, with a fallback minimal vimrc.

As of this config, only the first part has been started
2024-04-29 10:41:02 +02:00

273 lines
7.8 KiB
VimL

set nocompatible
if &shell =~# 'fish$'
set shell=sh
endif
" Allow backspacing over everything in insert mode.
set backspace=indent,eol,start
set number
set relativenumber
"[Hide/show the white-space and more invisible symbols]"
set list
set listchars=tab:▸\ ,nbsp,trail:-
" | | + Trailing spaces
" | + Non breakable spaces
" + Tabulations: `tab xy`, x: first char, y: following chars
set nojoinspaces
"[Indent & Tab/mode-line settings]"
set breakindent
set nopaste
set smarttab
set tabstop=4 " tabs size on screen "
set expandtab " <tab> inserts spaces "
set autoindent
set copyindent " copy existing tab/spaces mix on newline "
set smartindent " overruled by cindent "
set cinwords=except,finally,def,class,with,do,if,elif,else,for,while,try,switch
set cinoptions+=l1 " switch case label alignement, :h cinoptions-values "
set shiftwidth=4 " number of space to use on indent. Use tabstop if 0"
"set softtabstop=4
"[Matching chars]"
set showmatch
set matchpairs=\":\"
set matchpairs+=(:)
set matchpairs+={:}
set matchpairs+=[:]
"[TextWidth settings]"
set textwidth=0
"[Look for a single modeline in files]"
set modeline
set modelines=1
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set laststatus=2
set noshowmode
"[Command mode autocompletion]"
set wildmenu
set wildmode=longest:full,full
" `------------|---- First complete till longest common string, open wildmenu
" `---- Then, complete next full match
set ttimeout " time out for key codes
set ttimeoutlen=100 " wait up to 100ms after Esc for special key
"[Turn backup off and value of history]"
set nobackup
set noswapfile
set history=1000
set nowritebackup
set undolevels=5000
"[Setup history file]"
set viminfo=%,<0,'10,/16,:16,h,f0
" | | | | | | + file marks 0-9,A-Z 0=NOT stored
" | | | | | + disable 'hlsearch' loading viminfo
" | | | | + command-line history saved
" | | | + search history saved
" | | + files marks saved
" | + lines saved each register (old name for <, vi6.2): NOT STORED
" + save/restore buffer list
if !has('nvim')
"[Declutter $HOME]"
set viminfo+=n~/.vim/cache/.viminfo
endif
" Show @@@ in the last line if it is truncated.
set display=truncate
"[Splitting rules]"
set splitbelow
set splitright
set equalalways
" Show a few lines of context around the cursor.
set scrolloff=5
" Try to keep the cursor in the same column while scrolling
set nostartofline
set autochdir
set autoread
set autowrite
"[Shared with OS clipboard]"
set clipboard=unnamed
"[For regular expressions turn magic on, use \v to get regex parent]"
set magic
"[Search settings]"
set hlsearch
set incsearch
set smartcase
set ignorecase
set wrapscan
"[When on, the ":substitute" flag 'g' is default on]"
set nogdefault
"[Enable realtime feedback for substitution]"
if has("nvim")
set inccommand=nosplit
endif
"[Kitty doesn't support background color erase]"
let &t_ut=''
let base16colorspace=256
set background=dark
colorscheme base16-default-dark
"[Fix background transparency]"
if has("autocmd")
autocmd ColorScheme * highlight Normal ctermbg=None
autocmd ColorScheme * highlight NonText ctermbg=None
endif
"[Define the leader key]"
let mapleader=","
let maplocalleader=","
"[Reselect visual block after indent/outdent]"
vnoremap < <gv
vnoremap > >gv
"[Improve up/down movement on wrapped lines]"
"[If preceded by a count, jump actual lines. Also if > 5, save to jumplist]"
nnoremap <expr> j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj'
nnoremap <expr> k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk'
"[Easy split navigation]"
nnoremap <C-j> <C-W>j
nnoremap <C-k> <C-W>k
nnoremap <C-h> <C-W>h
nnoremap <C-l> <C-W>l
nnoremap <C-Up> <C-W>k
nnoremap <C-Down> <C-W>j
nnoremap <C-Left> <C-W>h
nnoremap <C-Right> <C-W>l
"[Locate the desired objects in the center of the screen]"
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
"[New line under/bellow current line without jump to insert-mode]"
nnoremap <leader>o o<Esc>
nnoremap <leader>O O<Esc>
"[Clear search highlights]"
nnoremap // :nohlsearch<CR>
"[Reflow current paragraph]"
"[http://stevelosh.com/blog/2010/09/coming-home-to-vim/]"
nnoremap <silent> <leader>q :call ReflowParagraph()<CR>
" http://stackoverflow.com/questions/1005/getting-root-permissions-on-a-file-inside-of-vi
cmap w!! w !sudo tee >/dev/null %
"[To disable the arrow keys]"
for prefix in ['i', 'n', 'v']
for key in ['<Up>', '<Down>', '<Left>', '<Right>']
execute prefix . "noremap " . key . " <Nop>"
endfor
endfor
"[Switch quickly between source and header]"
nnoremap <leader>f :e <C-r>=SwapExtension()<CR><CR>
" Do incremental searching when it's possible to timeout.
if has('reltime')
set incsearch
endif
" LaTeX ftdetect
let g:tex_flavor = "latex"
" Switch syntax highlighting on when the terminal has colors or when using the
" GUI (which always has colors).
if &t_Co > 2 || has("gui_running")
" Revert with ":syntax off".
syntax on
" I like highlighting strings inside C comments.
" Revert with ":unlet c_comment_strings".
let c_comment_strings=1
endif
"[Reflow current paragraph]"
function! ReflowParagraph()
let l:view = winsaveview()
normal gwip
call winrestview(l:view)
endfunction
"[Remove tabs and spaces at the end of lines]"
function! DeleteTrailingTWS()
"[Do not clean up trailing spaces in binary mode or in diff files]"
if &binary || &ft =~ 'diff'
return
endif
let l:view = winsaveview()
silent %s/[ \t]*$//g
silent %s/\s\+$//ge
call winrestview(l:view)
endfunction
"[Make the scripts executable]"
function! ChangeScriptMode()
if getline(1) =~ "#!"
if getline(1) =~ "bin/"
silent !chmod +x <afile>
endif
endif
endfunction
"[Swap file extensions, for example cpp/h]"
"https://stackoverflow.com/a/22145246"
function! SwapExtension()
let [rest, ext] = [expand('%:r'), expand('%:e')]
if ext ==? 'h'
if filereadable(rest . '.c')
let ext = 'c'
elseif filereadable(rest . '.cpp')
let ext = 'cpp'
endif
elseif ext ==? 'cpp' || ext ==? 'c'
let ext = 'h'
"swap between vertex and fragment shader"
elseif ext ==? 'vsh'
let ext = 'fsh'
elseif ext ==? 'fsh'
let ext = 'vsh'
endif
return rest . '.' . ext
endfunction
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection. Use the default filetype settings, so that
" mail gets 'tw' set to 72, 'cindent' is on in C files, etc. Also load
" indent files, to automatically do language-dependent indenting.
" Revert with ":filetype off".
filetype plugin indent on
" Put these in an autocmd group, so that you can revert them with:
" ":augroup vimStartup | au! | augroup END"
augroup vimStartup
au!
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid, when inside an event handler
" (happens when dropping a file on gvim) and for a commit message (it's
" likely a different one than last time).
autocmd BufReadPost *
\ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' |
\ exe "normal! g`\"" |
\ endif
augroup END
"[Try not to pollute the undo tree (https://vi.stackexchange.com/a/13401)]"
autocmd BufWritePre *
\ try |
\ undojoin |
\ catch /^Vim\%((\a\+)\)\=:E790/ |
\ finally |
\ call DeleteTrailingTWS() |
\ endtry
if has("unix") || has("mac")
autocmd BufWritePost * call ChangeScriptMode()
endif
endif " has("autocmd")