From 0d397e4d3d204a1e016c0863815f0b5dc516c46b Mon Sep 17 00:00:00 2001 From: Vikas Kushwaha Date: Wed, 21 May 2025 14:30:00 +0530 Subject: added some new scripts and cleaned up nvim directory --- .config/nvim/init.vim | 124 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 80 insertions(+), 44 deletions(-) (limited to '.config/nvim/init.vim') diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index e9772ee..eeedeae 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -32,9 +32,14 @@ if filereadable(config_dir . "autoload/plug.vim") call plug#end() endif +packadd fzf.vim +source ~/.config/nvim/user/fzf.vim +set rtp+=/usr/share/vim/vimfiles + let g:Verdin#autocomplete = 1 let g:livepreview_previewer = 'zathura' let g:tex_flavor = 'latex' +let g:session_filename = '.session.vim' set title showmatch nowrap mouse=a scrolloff=5 set tabstop=2 shiftwidth=0 @@ -51,33 +56,19 @@ colorscheme vim highlight NonText ctermfg=242 highlight ColorColumn ctermbg=238 highlight! link CursorColumn ColorColumn +highlight FloatermBorder guibg=orange guifg=cyan autocmd FileType text,fstab setlocal tabstop=8 shiftwidth=8 autocmd FileType html setlocal tabstop=2 shiftwidth=2 list nolinebreak autocmd FileType sql setlocal commentstring=--\ %s +autocmd BufWritePre * %s/\s\+$//e autocmd BufEnter bm-files,bm-dirs setlocal tabstop=8 shiftwidth=8 autocmd BufWritePost bm-files,bm-dirs silent !shortcuts -autocmd VimLeave *.tex !dev clean "%" autocmd BufWritePost config.def.h !cd "%:h"; rm -f config.h; sudo make install autocmd BufWritePost config.h !cd "%:h"; sudo make install -autocmd BufWritePre * %s/\s\+$//e -au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif - -autocmd BufWritePost */Documents/Notes/*.md silent !pandoc % -o "$HOME/Documents/Notes/.out/$(basename % .md).html" -" autocmd BufWritePost */Documents/latex/resume/resume.tex !cd "%:h"; pdflatex resume.tex; cp -v resume.pdf ~/Dev/vikas.rocks/static/dox/ autocmd BufWritePost *Xresources silent !xrdb "%" autocmd BufRead,BufNewFile *.yt* set filetype=conf - -function SourceTemplate() - let b:template = glob("${XDG_CONFIG_HOME:-$HOME/.config}/nvim/templates/_default." . expand('%:e')) - if !empty(b:template) - execute('0r' . b:template) - endif -endfunction - -autocmd BufNewFile * call SourceTemplate() - -autocmd TermOpen * startinsert -command! -nargs=* T split | terminal +autocmd VimLeave *.tex !dev clean "%" +au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif " --> Scratch buffer if exists('g:loaded_scratch') @@ -98,6 +89,44 @@ nnoremap o :LfWorkingDirectory nnoremap l :LfCurrentFileNewTab nnoremap o :LfWorkingDirectoryExistingOrNewTab +" --> Sessions + +fu! SaveSess() + execute 'mksession! ' . getcwd() . '/' . g:session_filename +endfunction + +fu! RestoreSess() +if filereadable(getcwd() . '/' . g:session_filename) + execute 'so ' . getcwd() . '/' . g:session_filename + if bufexists(1) + for l in range(1, bufnr('$')) + if bufwinnr(l) == -1 + exec 'sbuffer ' . l + endif + endfor + endif +endif +endfunction + +command! -nargs=0 Mksess :call SaveSess() +command! -nargs=0 Resess :call RestoreSess() + +" --> Template Management + +function SourceTemplate() + let b:template = glob("${XDG_CONFIG_HOME:-$HOME/.config}/nvim/templates/_default." . expand('%:e')) + if !empty(b:template) + execute('0r' . b:template) + endif +endfunction + +autocmd BufNewFile * call SourceTemplate() + +autocmd TermOpen * startinsert +command! -nargs=* T split | terminal + +" --> Bindings and configs + if !exists('g:lasttab') let g:lasttab = 1 endif @@ -124,25 +153,37 @@ inoremap jk inoremap ;n /<++>c4l nnoremap n /<++>c4l -inoremap ;s >bi<ea -inoremap ;c >biea -inoremap ;i b"tywi<ea>PFb"tywi<ea><++>P2F>i -inoremap ;b b"tywi<ea>"tpa><++>kO -inoremap ;B b"tywi<ea><++>"tpa><++>3k$i -inoremap ;ap

<++>

<++>3k$i -inoremap ;aa <++><++>3k$hi +augroup Web + autocmd! + autocmd FileType html,javascript call SetWebBindings() + function SetWebBindings() + inoremap ;s >bi<ea + inoremap ;c >biea + inoremap ;i b"tywi<ea>PFb"tywi<ea><++>P2F>i + inoremap ;b b"tywi<ea>"tpa><++>kO + inoremap ;B b"tywi<ea><++>"tpa><++>3k$i + inoremap ;ap

<++>kO + inoremap ;aP

F<++><++>3k$hi + inoremap ;aA <++>F"i + inoremap ;cl console.log("");F"i + endfunction +augroup END augroup Tex autocmd! - autocmd FileType tex inoremap ;b b"tywi\begin{ea}\end{"tpa}kA - autocmd FileType tex inoremap ;s \section{}i - autocmd FileType tex inoremap ;at \begin{tikzpicture}\end{tikzpicture}O - autocmd FileType tex inoremap ;ap \usepackage{}i - autocmd FileType tex inoremap ;aP \usepackage[]{}F[a - autocmd FileType tex inoremap ;ab \textbf{}i - autocmd FileType tex inoremap ;ai \textit{}i - autocmd FileType tex inoremap ;au \underline{}i + autocmd FileType tex call SetTexBindings() + function SetTexBindings() + inoremap ;b b"tywi\begin{ea}\end{"tpa}kA + inoremap ;s \section{}i + inoremap ;at \begin{tikzpicture}\end{tikzpicture}O + inoremap ;ap \usepackage{}i + inoremap ;aP \usepackage[]{}F[a + inoremap ;ab \textbf{}i + inoremap ;ai \textit{}i + inoremap ;au \underline{}i + endfunction augroup END autocmd FileType go inoremap ;ae err:=<++>iferr!=nil{returnerr}3kI @@ -163,23 +204,18 @@ nnoremap Fe :w:T dev run "%" nnoremap Ft :w:T dev test "%" nnoremap Fr :w:T dev clean "%" -autocmd BufEnter * nmap b :w:se nornu:!dev build "%":se rnu -autocmd BufEnter * nmap B :w:se nornu:T dev build "%" -autocmd BufEnter * nmap t :w:se nornu:!dev test "%":se rnu -autocmd BufEnter * nmap T :w:se nornu:T dev test "%" - -autocmd BufEnter vartak-results-data.pl nmap t :w:se nornu:!vartak-results-data.pl ~/GDrive/vartak/results/university/1S002557.pdf:se rnu +nnoremap b :w:se nornu:!dev build "%":se rnu +nnoremap B :w:se nornu:T dev build "%" +nnoremap t :w:se nornu:!dev test "%":se rnu +nnoremap T :w:se nornu:T dev test "%" nnoremap w :set wrap! nnoremap fo :!opout "%:p" -nnoremap ei :tabnew ~/.config/nvim/init.vim -nnoremap eo :tabnew ~/.config/nvim/coc/coc-onload.vim -nnoremap ec :tabnew ~/.config/nvim/coc/coc-settings.json -nnoremap ed :tabnew ~/.config/nvim/dev.vim nnoremap :source ~/.config/nvim/init.vim nnoremap s :%s//gc nnoremap gc :T git add --all && git commit +nnoremap gp :T gitpush let shortcuts = config_dir . "shortcuts.vim" if filereadable(shortcuts) -- cgit v1.2.3