dotfiles/.config/vim/vim_uni

146 lines
4.2 KiB
Text

" vim: filetype=vim
" ==============================
" Universal (Works on any OS... probably) Configuration
" ==============================
" ----- Vim Initial Config
set encoding=utf-8
set hls
set number relativenumber " -- converted
set ignorecase
set smartcase
set mouse=a
set background=dark
set ffs=unix
" set complete+=kspell
" set completeopt=menuone,longest
" set list lcs=trail:·,tab:··\|,nbsp:·
hi VertSplit cterm=NONE ctermbg=0 ctermfg=0
hi NonText ctermfg=0
hi Folded ctermfg=White
hi Folded ctermbg=Black
" hi! EndOfBuffer ctermbg=NONE ctermfg=8
set fillchars=eob:\
syntax on
filetype indent plugin on
map <C-n> :NERDTreeToggle<CR>
let mapleader=" " " -- converted
set guifont=Iosevka:h15 " -- converted
" ----- Folding stuff
set foldnestmax=10
" don't fold by default
set nofoldenable
set foldlevel=1
" python
autocmd FileType python setlocal foldmethod=indent
" ----- Mapping
" Norm but in shortcut -- converted
vnoremap . :normal .<CR>
" Map ctrl + u as U -- converted
noremap <C-u> U
" Map U as redo (ctrl + r) -- converted
noremap U <C-r>
" Yank and Put to/from clipboard/primary -- converted
noremap <C-y> "+y
noremap <C-p> "+p
noremap <C-Y> "+y
noremap <C-P> "+P
" Shortcut to comment a line -- converted
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
" Format with by pressing Q useful for markdown / other markup languages
map Q gq
" ----- '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
" in C files, tabs looks like 4 spaces, but it's actually tabs
autocmd Filetype c set ai sw=4 ts=4 sta noet fo=croql
autocmd BufEnter *.md set ai sw=3 ts=3 sta et fo=croql
autocmd Filetype html* set ai sw=4 ts=4 sta et fo=croql
autocmd Filetype *css set ai sw=4 ts=4 sta et fo=croql
autocmd Filetype javascript* set ai sw=4 ts=4 sta et fo=croql
autocmd Filetype json set ai sw=4 ts=4 sta et fo=croql
autocmd Filetype vue set ai sw=4 ts=4 sta et fo=croql
autocmd Filetype php 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-p>" : "<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>" : "<Tab>"
inoremap <expr><S-Tab> pumvisible() ? "<C-p>" : "<S-Tab>"