dotfiles/.config/vim/vim_uni

121 lines
3.4 KiB
Text

" vim: filetype=vim
" ==============================
" Universal (Works on any OS... probably) Configuration
" ==============================
" ----- Vim Initial Config
let mapleader=" "
set encoding=UTF-8
set hls
set number
set ignorecase
set smartcase
set mouse=a
set background=dark
set complete+=kspell
set completeopt=menuone,longest
highlight VertSplit cterm=NONE ctermbg=0 ctermfg=0
hi! EndOfBuffer ctermbg=8 ctermfg=8
syntax on
filetype indent plugin on
map <C-n> :NERDTreeToggle<CR>
" ----- Mapping
" Norm but in shortcut
vnoremap . :normal .<CR>
" Map ctrl + u as U
noremap <C-u> U
" Map U as redo (ctrl + r)
noremap U <C-r>
" Yank and Put to/from clipboard/primary
noremap <C-y> "+y
noremap <C-p> "+p
noremap <C-Y> "+y
noremap <C-P> "+P
" Shortcut to comment a line
" <C-_> means ctrl+/ for vim, for some reason...
map <C-_> gcc
vmap <C-_> gc
imap <C-_> <esc>gc
" Clear last search result
map <leader>c :noh<CR>
" TwiddleCase
function! TwiddleCase(str)
if a:str ==# toupper(a:str)
let result = tolower(a:str)
elseif a:str ==# tolower(a:str)
let result = substitute(a:str,'\(\<\w\+\>\)', '\u\1', 'g')
else
let result = toupper(a:str)
endif
return result
endfunction
vnoremap ~ y:call setreg('', TwiddleCase(@"), getregtype(''))<CR>gv""Pgv
" ----- 'vim -b' = edit binary using xxd-format!
augroup Binary
au!
au BufReadPre *.bin let &bin=1
au BufReadPost *.bin if &bin | %!xxd
au BufReadPost *.bin set ft=xxd | endif
au BufWritePre *.bin if &bin | %!xxd -r
au BufWritePre *.bin endif
au BufWritePost *.bin if &bin | %!xxd
au BufWritePost *.bin set nomod | endif
augroup END
" ----- indent for corresponding extension
autocmd BufEnter *.py set ai sw=4 ts=4 sta et fo=croql
autocmd BufEnter *.c set ai sw=4 ts=4 sta et fo=croql
autocmd BufEnter *.md set ai sw=4 ts=4 sta et fo=croql
" ----- Auto refresh vimrc
augroup myvimrc
au!
au BufWritePost vimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
au BufWritePost vim_nix so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
au BufWritePost vim_plug so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
au BufWritePost vim_uni so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
au BufWritePost vim_win so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
augroup END
" ----- Discord Rich Presences API
let g:vimsence_client_id = '733622032901603388'
let g:vimsence_small_text = 'Neovim'
let g:vimsence_small_image = 'nvim'
" let g:vimsence_large_image = 'ts'
let g:vimsence_editing_details = 'Editing {}'
let g:vimsence_editing_state = 'Workspace: {}'
let g:vimsence_file_explorer_text = 'In NERDTree'
let g:vimsence_file_explorer_details = 'Looking for files'
" Split opens at the bottom and right
set splitbelow splitright
" Split navigation shortcuts
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Complete menu mappings
" Up and Down act like ctrl+p and ctrl+n
inoremap <expr><Up> pumvisible() ? "<C-n>" : "<Up>"
inoremap <expr><Down> pumvisible() ? "<C-n>" : "<Down>"
" Enter to complete
inoremap <expr><CR> pumvisible() ? "<C-y>" : "<CR>"
" Left or Right to cancel
inoremap <expr><Right> pumvisible() ? "<C-e><Right>" : "<Right>"
inoremap <expr><Left> pumvisible() ? "<C-e><Left>" : "<Left>"
" Tab act like ctrl+p and ctrl+n
inoremap <expr><Tab> pumvisible() ? "<C-n><C-n>" : "<Tab>"
inoremap <expr><S-Tab> pumvisible() ? "<C-p><C-p>" : "<S-Tab>"