dotfiles

Config files from my daily system
Index Commits Files Refs README
commit 209e075d2734a3e3fbece6cf50f6269fba45e2e2
parent 72ad0357ba4999dc56d26b34a841950f098bc273
Author: mjkloeckner <martin.cachari@gmail.com>
Date:   Tue,  7 Feb 2023 23:58:04 -0300

updated neovim config file

Diffstat:
M.config/nvim/init.vim | 207+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 170 insertions(+), 37 deletions(-)
diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim
@@ -6,24 +6,31 @@
 "
 "        by github.com/mjkloeckner
 
-
 " Plugins call
     call plug#begin('~/.config/nvim/plugged')
 
+    Plug 'PhilRunninger/nerdtree-visual-selection'
     Plug 'alvan/vim-closetag'
+    Plug 'ayosec/hltermpaste.vim'
     Plug 'chrisbra/Colorizer'
     Plug 'christoomey/vim-tmux-navigator'
     Plug 'flazz/vim-colorschemes'
     Plug 'flw-cn/vim-nerdtree-l-open-h-close'
     Plug 'hattya/vcs-info.vim'
     Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': 'markdown' }
+    Plug 'junegunn/vim-easy-align'
     Plug 'justinmk/vim-syntax-extra'
+    Plug 'mbbill/undotree'
     Plug 'preservim/nerdtree'
     Plug 'ryanoasis/vim-devicons'
     Plug 'sainnhe/edge'
     Plug 'sainnhe/gruvbox-material'
+    Plug 'skywind3000/asyncrun.vim'
+    Plug 'tikhomirov/vim-glsl'
     Plug 'tpope/vim-commentary'
     Plug 'tpope/vim-surround'
+    Plug 'tpope/vim-fugitive'
+    Plug 'vim-python/python-syntax'
 
     call plug#end()
 
@@ -37,6 +44,8 @@
     set shiftwidth=4
     set scrolloff=5
     set path+=./**
+    set lcs+=space:ยท
+    set iskeyword-=(,)
     set wildmenu
     set incsearch
     set smartcase
@@ -51,32 +60,23 @@
     set backupdir=~/.cache/nvim/backup
     set clipboard=unnamedplus
 
-    " Enable blinking together with different cursor shapes for insert/command mode,
-    " and cursor highlighting:
+    " Enable blinking together with different cursor shapes for insert/command mode, and cursor highlighting:
     set guicursor=n-v:block,i-ci-ve-c:ver25,r-cr:hor20,o:hor50
     \,a:blinkwait700-blinkoff4000-blinkon2500-Cursor/lCursor
     \,sm:block-blinkwait175-blinkoff150-blinkon175
 
-    " Plugins settings
-    " source "$HOME/.config/nvim/plugins.vim"
-
     " Set colorscheme and transparent background
     function! AdaptColorscheme()
-        " hi clear CursorLine
         hi Normal guibg=NONE ctermbg=NONE
         hi LineNr guibg=NONE ctermbg=NONE
         hi Folded guibg=NONE ctermbg=NONE
-        " hi EndOfBuffer guibg=NONE ctermbg=NONE
         hi EndOfBuffer guibg=NONE ctermbg=NONE ctermfg=12
         hi SpecialKey guibg=NONE ctermbg=NONE
         hi VertSplit guibg=NONE ctermbg=NONE
         hi SignColumn guibg=NONE ctermbg=NONE
-
         hi TabLineSel ctermfg=LightGreen ctermbg=NONE
         hi TabLineFill ctermfg=Gray ctermbg=NONE
         hi Title ctermfg=LightBlue ctermbg=NONE
-
-        " hi CursorLine cterm=NONE ctermbg=235
     endfunction
 
     function! DarkTheme()
@@ -104,51 +104,46 @@
         call DarkTheme()
     endif
 
-    " Key remaps
+" Key remaps
     let mapleader =' '
-
-    "" Open file tree
-    map <leader>f :NERDTreeToggle %<CR>
-
-    "" Focus file tree
+    map <leader>f :NERDTreeToggle<CR>
     map <leader>F :NERDTreeFocus<CR>
-
-    "" Open current dir in NERDTree
     map <leader>r :NERDTreeFind<CR>
 
-    "" Source nvim config file
     map <leader>s :source $HOME/.config/nvim/init.vim<CR>
 
-    "" Open current dir in NERDTree
-    map <leader>c :make
-
-    "" Disable ex-mode keybinding (type visual thing)
+    " Disable ex-mode keybinding (type visual thing)
     map Q <NOP>
 
-    "" Improves indenting chunks of code with '<' '>' keys
+    " Improves indenting chunks of code with '<' '>' keys
     vnoremap < <gv
     vnoremap > >gv
 
-    "" Stops highlight after a search hitting return;
-    nnoremap <silent> <CR> :noh<CR><CR>
+    " Type a replacement term and press . to repeat the replacement again. Useful
+    " for replacing a few instances of the term (comparable to multiple cursors).
+    nnoremap <silent> s* :let @/='\<'.expand('<cword>').'\>'<CR>cgn
+    xnoremap <silent> s* "sy:let @/=@s<CR>cgn
+
+    " Stops highlight after a search hitting return;
+    nnoremap <silent> <CR> :nohlsearch<CR>
 
-    "" Shortcut for split navigation
+    " Shortcut for split navigation
     noremap <C-Down> <C-W>j<CR>
     noremap <C-Up> <C-W>k<CR>
     noremap <C-Left> <C-W>h<CR>
     noremap <C-Right> <C-W>l<CR>
 
-    "" Move between windows with Ctrl + hjkl
+    " Move between windows with Ctrl + hjkl
     noremap <C-h> <C-w>h
     noremap <C-j> <C-w>j
     noremap <C-k> <C-w>k
     noremap <C-l> <C-w>l
 
-    "" Go to next/prev quickfix
+    " Go to next/prev quickfix
     nnoremap <C-n> :cnext<CR>zz
     nnoremap <C-p> :cprev<CR>zz
 
-    "" Go to tab by number
+    " Go to tab by number
     noremap <leader>1 1gt
     noremap <leader>2 2gt
     noremap <leader>3 3gt
@@ -160,6 +155,12 @@
     noremap <leader>9 9gt
     noremap <leader>0 :tablast<cr>
 
+    " Start interactive EasyAlign in visual mode (e.g. vipga)
+    xmap ga <Plug>(EasyAlign)
+
+    " Start interactive EasyAlign for a motion/text object (e.g. gaip)
+    nmap ga <Plug>(EasyAlign)
+
     " Highlight whitespace problems.
     " flags is '' to clear highlighting, or is a string to
     " specify what to highlight (one or more characters):
@@ -210,7 +211,6 @@
     endfunction
 
     nnoremap <Leader>ws :call ToggleShowWhitespace()<CR>
-
     highlight ExtraWhitespace ctermbg=red guibg=red
 
     nnoremap <A-j> :m .+1<CR>==
@@ -242,11 +242,12 @@
     autocmd VimEnter * set laststatus=1
 
     let NERDTreeHijackNetrw=1
+    let NERDTreeMinimalUI=1
 
     " Highjack nerdtree's highjacking to keep normal nerdtree from loading on directories
     " let g:NERDTreeHijackNetrw=0
     " augroup NERDTreeHijackNetrw
-    "     autocmd VimEnter * silent! autocmd! FileExplorer
+    " autocmd VimEnter * silent! autocmd! FileExplorer
     " augroup END
 
     " autocmd VimEnter * call CloseExtraNERDTree()
@@ -258,23 +259,128 @@
     "   let l:main_bufnr = bufnr('%')
     "   let l:fname = expand('%') " get name of current buffer
     "   if l:fname ==# 'NERD_tree_1'
-    "     exe bufwinnr(l:main_bufnr) . "wincmd w"
-    "     bd
+    "   exe bufwinnr(l:main_bufnr) . "wincmd w"
+    "   bd
     "   endif
     " endfunction
 
-    " :echo '' | let c = nr2char(getchar()) | exe "ma" c | echon "created mark '" c "' at line " line(".")
+    " Start NERDTree when Vim is started without file arguments.
+    " autocmd StdinReadPre * let s:std_in=1
+    " autocmd VimEnter * if argc() == 0 && !exists('s:std_in') | NERDTree | only | endif
+
     function VerboseMark()
         echo ''
         let c = getchar()
         if ((c >= 0x41) && (c <= 0x5A)) || ((c >= 0x61) && (c <= 0x7A))
             exe "mark" nr2char(c)
-            echon "created mark '" nr2char(c) "' at line " line(".")
+            echon "Created mark at key '" nr2char(c) "' in line " line(".")
+        else
+            return
+        endif
+    endfunction
+
+    let g:asyncrun_open = 12
+
+    " Pressing Ctrl-C when input prompt breaks highlight
+    cnoremap <C-c> <Esc>
+
+    " Oposite of <Shift-k>
+    nnoremap K :m-2<CR>J
+
+    function Compile()
+        echohl Question
+        let l:input = split(input("Compile command: ", &makeprg, "filetype"), ' ')
+        echohl None
+
+        if empty(l:input)
+            return
+        endif
+        redraw
+
+        if(!empty(matchstr(l:input, "%")))
+            if(empty(expand('%')))
+                echohl Question
+                echo 'Filename empty'
+                echohl None
+                return
+            endif
+        endif
+
+        let string = join(l:input, ' ')
+        " exe "set makeprg = " .. string
+        let &makeprg = string
+        let l:s = &makeprg
+        exe "AsyncRun " .. l:s
+        mod
+    endfunction
+
+    " autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif
+    function SearchHelp()
+        echohl Question
+        let l:input = substitute(input("Search vim help: ", "", "help"), "\\\'\\\|\\\"", '', 'g')
+        echohl None
+        mod
+
+        if empty(l:input)
+            return
+        endif
+
+        let l:error = execute('silent help ' .. l:input)
+
+        if !empty(l:error)
+            echohl WarningMsg
+            echon "No help found for: '" .. l:input "'."
+            echohl None
         else
+            exe "wincmd T | set relativenumber"
+        endif
+    endfunction
+
+    " autocmd BufEnter *.txt if &filetype == 'man' | wincmd T | endif
+    function SearchMan()
+        echohl Question
+        " let l:input = input("Search man page: ")
+        let l:input = substitute(input("Search man page: "), "\\\'\\\|\\\"", '', 'g')
+        echohl None
+        mod
+
+        if empty(l:input)
             return
         endif
+
+        " let l:string = join(l:input, ' ')
+        let l:cmd = "man " .. l:input .. " > /dev/null 2>&1"
+        call system(l:cmd)
+        if v:shell_error == 0
+            exe "Man " .. l:input
+            exe "wincmd T | set relativenumber"
+        else
+            echohl WarningMsg
+            echon l:input .. ": nothing appropriate."
+            echohl None
+        endif
     endfunction
 
+    function Search()
+        echohl Question
+        let l:input = split(input("Search keyword in CWD: "), ' ')
+        echohl None
+        if empty(l:input)
+            return
+        endif
+        mod
+
+        let l:string = join(l:input, ' ')
+        echo l:string
+        exe "silent grep -r -I -s --exclude-dir=.git " .. l:string .. " *"
+        copen
+    endfunction
+
+    nnoremap <Leader>C :call Compile()<CR>
+    nnoremap <Leader>v :call Search()<CR>
+    nnoremap <Leader>m :call SearchMan()<CR>
+    nnoremap <Leader>h :call SearchHelp()<CR>
+
     function Text()
         set tw=80
         set colorcolumn=80
@@ -285,3 +391,30 @@
 
     nnoremap <Leader>t :call Text()<CR>
     nnoremap m :call VerboseMark()<CR>
+
+    " close if quickfix is the last window
+    au BufEnter * call MyLastWindow()
+    function! MyLastWindow()
+      " if the window is quickfix go on
+      if &buftype=="quickfix"
+        " if this window is last on screen quit without warning
+        if winbufnr(2) == -1
+          quit!
+        endif
+      endif
+    endfunction
+
+    " Switch to last-active tab
+    if !exists('g:Lasttab')
+        let g:Lasttab = 1
+        let g:Lasttab_backup = 1
+    endif
+    autocmd! TabLeave * let g:Lasttab_backup = g:Lasttab | let g:Lasttab = tabpagenr()
+    autocmd! TabClosed * let g:Lasttab = g:Lasttab_backup
+    nmap <silent> <Leader>; :exe "tabn " . g:Lasttab<cr>
+
+    au TextYankPost * silent! lua vim.highlight.on_yank()
+    let g:python_highlight_all = 1
+
+    " delete word in command/prompt mode with Ctrl + Backspace
+    cnoremap <C-H> <C-w>