From 2b55e78b3111ee943d02569a1794ab269a0fc424 Mon Sep 17 00:00:00 2001 From: Vanderson Rodrigues Date: Mon, 16 Dec 2024 21:31:01 -0300 Subject: [PATCH] [nvim] Update configuration --- nvim/.config/nvim/init.lua | 446 +++++++++++++++++++++++++++++++++---- nvim/colors | 1 - nvim/init.lua | 1 - 3 files changed, 400 insertions(+), 48 deletions(-) delete mode 120000 nvim/colors delete mode 120000 nvim/init.lua diff --git a/nvim/.config/nvim/init.lua b/nvim/.config/nvim/init.lua index aef30b2..798fe2f 100644 --- a/nvim/.config/nvim/init.lua +++ b/nvim/.config/nvim/init.lua @@ -1,12 +1,3 @@ --- File: init.lua --- Maintainer: Vanderson Rodrigues --- __ --- __ __ /\_\ ___ ___ _ __ ___ --- /\ \/\ \\/\ \ /' __` __`\/\`'__\/'___\ --- __\ \ \_/ |\ \ \/\ \/\ \/\ \ \ \//\ \__/ --- /\_\\ \___/ \ \_\ \_\ \_\ \_\ \_\\ \____\ --- \/_/ \/__/ \/_/\/_/\/_/\/_/\/_/ \/____/ - -- {{{ GENERAL SETTINGS vim.opt.foldmethod="marker" @@ -67,7 +58,7 @@ vim.opt.mouse="a" vim.opt.encoding="utf-8" -- Set terminal colors -vim.opt.termguicolors=false +vim.opt.termguicolors=true -- Disable modeline because security issues vim.opt.modeline=false @@ -89,52 +80,32 @@ vim.opt.ttimeoutlen=0 -- Character used on vertical splits -- NOTE: https://pt.piliapp.com/symbol/line/ --- Options:▕ │ ▏ vim.opt.fillchars=vim.opt.fillchars+"vert:▕" -- Removes '~' chars in the end of file --vim.opt.fillchars=vim.opt.fillchars+"eob: " -- Change the characters used in the folding ---vim.opt.fillchars=vim.opt.fillchars+"fold:—" -vim.opt.fillchars=vim.opt.fillchars+"fold:—" +vim.opt.fillchars=vim.opt.fillchars+"fold:-" -- Invisible characters --vim.opt.listchars="tab:→ ,space:·,trail:·,eol:↲,nbsp:␣" vim.opt.listchars="tab:→ ,trail:·,eol:↲,nbsp:␣" --- Start of default statusline ---vim.opt.statusline="" - --- NOTE: The line below has a trailing space character ---vim.opt.statusline="%<%{FilePath()} %h%w%m%r " - --- End of default statusline (with ruler) ---vim.opt.statusline=statusline+"%=%(%l,%c%V\ %=\ %P\ %)" - --- Set appearance of text folded ---vim.opt.foldtext=SetFoldText() +-- Show statusline only when are more than one pane +vim.opt.laststatus=1 -- Press F3 to enter paste insert mode -- This removes automatic indentation on pasting vim.opt.pastetoggle="" --- Performance things --- https://vi.stackexchange.com/questions/10495/most-annoying-slow-down-of-a-plain-text-editor/10496 --- vim.open.regexpengine=1 -vim.opt.lazyredraw=true --- vim.open.synmaxcol=200 - -- faster scrolling vim.opt.ttyfast=true --- http://bugs.debian.org/608242 --- vim.opt.t_RV="" - --- Automatically invoke completion mode in mappings --- This is necessary for the following: --- nnoremap B :buffer -vim.cmd("set wildcharm=") +-- This set the char used to behave like Tab in selection menus +-- This is useful for mappings like: +-- nnoremap b :buffer +vim.cmd("set wildcharm=") -- Set the working directory to wherever the open file lives vim.opt.autochdir=true @@ -152,18 +123,401 @@ vim.opt.undodir="/tmp//" -- Set tags option for the command ctags vim.opt.tags="tags;" -vim.opt.showmatch=true - -vim.opt.shellcmdflag="-ic" - -vim.opt.splitright=true - -vim.opt.splitbelow=true +-- Briefelly shows what is the matching par of character +--vim.opt.showmatch=false -- }}} -- {{{ DEFINE AND SET VARIABLES - +vim.cmd([[ + +" Define leader keys +let mapleader="\" +let maplocalleader="," + +" Regular expression to catch dotfiles +let dotfiles_regex = '\(^\|\s\s\)\zs\.\S\+' + +" Netrw plugin configuration +let g:netrw_banner = 0 +let g:netrw_hide = 0 +let g:netrw_list_hide = netrw_gitignore#Hide() +let g:netrw_list_hide .= ',' . dotfiles_regex +let g:netrw_keepdir = 0 +let g:netrw_winsize = 30 +let g:netrw_localcopydircmd = 'cp -r' +let g:netrw_special_syntax= 1 +let g:netrw_cursor = 2 +let g:netrw_fastbrowse = 0 + +" Explore status +let g:explore_is_open = 0 + +" Quickfix status +let g:quickfix_is_open = 0 + +" Value used in colorcolumn option +let g:limit_column_start = 81 +let g:limit_column_end = g:limit_column_start * 2 +let g:cc = join(range(g:limit_column_start,g:limit_column_end),",") + +" Termdebug plugin configuration +let g:termdebug_popup = 0 +let g:termdebug_wide = 163 + +" Solarized themes configuration +let g:solarized_termcolors = 256 +let g:solarized_italics = 1 +let g:solarized_bold = 1 +let g:solarized_underline = 1 +let g:solarized_visibility = 'low' +let g:solarized_statusline = 'flat' +let g:solarized_extra_hi_groups = 1 + +]]) +-- }}} +-- {{{ UTILITY FUNCTIONS +vim.cmd([[ + +function! ActivateAllComponentsDisplay() + tabdo windo set laststatus=2 + tabdo windo set showtabline=1 + tabdo windo set number relativenumber +endfunction + +function! ToggleColorColumnDisplay() + if &colorcolumn == g:cc + tabdo windo set colorcolumn=0 + else + execute "tabdo windo set colorcolumn=" . g:cc + endif +endfunction + +function! ToggleStatusBarDisplay() + if &laststatus == 2 || &laststatus == 1 + tabdo windo set laststatus=0 + else + tabdo windo set laststatus=2 + endif +endfunction + +function! ToggleTabLineDisplay() + if &showtabline == 2 || &showtabline == 1 + tabdo windo set showtabline=0 + else + tabdo windo set showtabline=2 + endif +endfunction + +function! ActivateRelativeNumber() + if &number=='nonumber' + set norelativenumber + else + set relativenumber + endif +endfunction + +function! ToggleAllComponentsDisplay() + if &cc == g:cc && &stal == 0 && &ls == 0 && &nu == 'nu' && &rnu == 'rnu' && &cul == 'cul' || + \ &cc == 0 && &stal == 1 && &ls == 0 && &nu == 'nu' && &rnu == 'rnu' && &cul == 'cul' || + \ &cc == 0 && &stal == 0 && &ls == 2 && &nu == 'nu' && &rnu == 'rnu' && &cul == 'cul' || + \ &cc == 0 && &stal == 0 && &ls == 0 && &nu && &rnu == 'rnu' && &cul == 'cul' || + \ &cc == 0 && &stal == 0 && &ls == 0 && &nu == 'nu' && &rnu && &cul == 'cul' || + \ &cc == 0 && &stal == 0 && &ls == 0 && &nu == 'nu' && &rnu == 'rnu' && &cul + :call ActivateAllComponentsDisplay() + :call ToggleColorColumnDisplay() + endif + :call ToggleStatusBarDisplay() + :call ToggleColorColumnDisplay() + :call ToggleTabLineDisplay() + :tabdo windo set number! relativenumber! +endfunction + +function! ToggleInvisibleChars() + if &list + set nolist + else + set list + endif +endfunction + +function! ToggleSpellLang() + if &spelllang == "pt_br" + set spelllang=en_us + echo "Spell language is now English!" + else + set spelllang=pt_br + echo "Spell language is now Portuguese!" + endif +endfunction + +function! ToggleWrapLines() + if &wrap + set nowrap + else + set wrap + endif +endfunction + +function! ToggleQuickfix() + if g:quickfix_is_open + let g:quickfix_is_open = 0 + :cclose + else + let g:quickfix_is_open = 1 + :copen + endif +endfunction + +" Call the fuzzy finder command inside vim +" SOURCE: https://www.reddit.com/r/vim/comments/orfpbd/interactive_fuzzy_finder_in_vim_without_plugins/ +function! FZF() abort + let l:tempname = tempname() + " fzf | awk '{ print $1":1:0" }' > file + execute 'silent !fzf --multi ' . '| awk ''{ print $1":1:0" }'' > ' . fnameescape(l:tempname) + try + execute 'cfile ' . l:tempname + redraw! + finally + call delete(l:tempname) + endtry +endfunction + +function! OpenExternalExplore() + "let l:tempname = tempname() + " ranger --choosefile=file + "execute 'silent !ranger --choosefile=' . fnameescape(l:tempname) + execute 'silent :enew' + execute 'silent !ranger' + "try + " execute 'cfile ' . l:tempname + " redraw! + " finally + " call delete(l:tempname) + " endtry +endfunction + +" Print the syntax group of the text where the cursor is +" SOURCE: shorturl.at/ckEJZ +function! PrintSyntaxGroup() abort + :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' + \ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" + \ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" +endfunction + +]]) +-- }}} +-- {{{ CUSTOM COMMANDS +vim.cmd([[ +"command! FZF call FZF() +"command! Ranger call OpenExternalExplore() +"command! PrintSyntaxGroup call PrintSyntaxGroup() +]]) -- }}} +--{{{ AUTOMATIC COMMANDS +vim.cmd([[ + +inoremap +augroup number + autocmd number InsertEnter * :set norelativenumber + autocmd number InsertLeave * :call ActivateRelativeNumber() +augroup END + +augroup cursor + autocmd! + autocmd VimLeave * !SetCursorShape() +augroup END + +" autocmd BufWritePost *.md silent !toemoji % + +]]) +--}}} +--{{{ KEYBOARD SHORTCUT MAPPINGS +vim.cmd([[ + +" Use this when clipboard not working properly +" nnoremap yy "+y +" vnoremap y "+y +" nnoremap p "+p + +" Open my configuration file +nnoremap v :edit $MYVIMRC +nnoremap vv :edit $MYVIMRC + +" Source my configuration file +nnoremap s :source $MYVIMRC +nnoremap ss :source $MYVIMRC + +" List buffers and ask for the target buffer +nnoremap B :ls:b + +" List buffers and ask for the target buffer (with completion mode) +" is set to behave like using the 'wildcharm' option +nnoremap b :buffer +nnoremap bb :buffer + +" Navigate to next and previous buffers +nnoremap bn :bnext +nnoremap bp :bprevious + +" List marks and ask for the target mark +nnoremap m :marks:' + +" Open builtin terminal +nnoremap t :term +nnoremap tt :term + +" Quick fix operations +nnoremap qq :call ToggleQuickfix() +nnoremap qn :cnext +nnoremap qp :cprevious + +" Toggle the spell checking +nnoremap sp :set spell! + +" Toggle the spell language between Portuguese and English +nnoremap sl :call ToggleSpellLang() + +" Open file explorer (Netrw) on the current directory +nnoremap e :call ToggleExplore() +nnoremap ee :call ToggleExplore() +nnoremap ex :call OpenExternalExplore() +nnoremap el :Lexplore + +" Clear the highlights from the search +nmap ns :nohlsearch + +" Re-apply the syntax highlight +nmap sy :syntax sync fromstart + +" Open search on the current directory +nnoremap ff :FZF +nnoremap f :find * +nnoremap sf :sfind * +nnoremap vf :vert sfind * +nnoremap tf :tabfind * +nnoremap F :find =expand('%:h').'/*' +nnoremap Sf :sfind =expand('%:h').'/*' +nnoremap Vf :vert sfind =expand('%:h').'/*' +nnoremap Tf :tabfind =expand('%:h').'/*' + +" Find all occurrences of a word in all project files +nnoremap * :grep -R * --exclude-dir={.git,tmp,log,node_modules} + +" Open a new fresh tab +nnoremap tn :tabnew + +" Re-size windows +nnoremap :resize +10 +nnoremap :resize -10 +nnoremap :vertical resize -10 +nnoremap :vertical resize +10 + +" Move lines up and down +" SOURCE: https://github.com/noopkat/dotfiles/blob/master/.vimrc +nnoremap :m .+1== +nnoremap :m .-2== +inoremap :m .+1==gi +inoremap :m .-2==gi +vnoremap :m '>+1gv=gv +vnoremap :m '<-2gv=gv + +" Generate tags file on the current directory +nnoremap gt :!ctags -R . + +" Generate list of files in the current directory and sub-directories +" Useful for index +inoremap gi =glob('**/*') + +" Utilities +nnoremap i :call ToggleInvisibleChars() +nnoremap w :call ToggleWrapLines() + +" Output the current syntax group +nnoremap :PrintSyntaxGroup + +" Shortcut for typing commands +nnoremap ;; : + +" Shortcut for close all windows +nnoremap ;q :qa + +" Uppercase the current word +inoremap viwUea + +" Uppercase the current line +inoremap VUA + +" Add double quotes at the current word +nnoremap " viwa"bi"lel + +" Add single quotes at the current word +nnoremap ' viwa'bi'lel + +]]) +--}}} +--{{{ KEYBOARD SHORTCUT MAPPINGS FOR MOVEMENT +vim.cmd([[ + +" Translate from 'inside parentheses' +" to 'parameters' +onoremap p i( + +" Until find the word return +onoremap b /return + +]]) +--}}} +--{{{ KEYBOARD SHORTCUT MAPPINGS FOR DISPLAY SETTINGS +vim.cmd([[ + +nnoremap :call ToggleAllComponentsDisplay() +nnoremap :call ToggleTabLineDisplay() +nnoremap :call ToggleStatusBarDisplay() +nnoremap :call ToggleColorColumnDisplay() +nnoremap :tabdo windo set number! +nnoremap :tabdo windo set relativenumber! + +]]) +--}}} +--{{{ SNIPPETS +--}}} +--{{{ ABBREVIATIONS AND CORRECTIONS +vim.cmd([[ + +" Common typos +iabbrev heigth height +iabbrev heigths heights +iabbrev lenght length +iabbrev lenghts lengths +iabbrev widht width +iabbrev widhts widths + +]]) +--}}} +--{{{ FILETYPE OPTIONS +vim.cmd([[ + +" Detect type of file +filetype on + +" Load plugin file for specific file type +filetype plugin on + +" Load indent file for specific file type +filetype indent on + +]]) +--}}} -- {{{ SYNTAX AND COLORS -vim.cmd("colorscheme solarized8") +vim.cmd([[ + +" Turn syntax highlighting on by default +syntax on + +" Set my color theme +colorscheme solarized8 + +]]) +-- }}} +-- {{{ PLUGINS -- }}} diff --git a/nvim/colors b/nvim/colors deleted file mode 120000 index 96f4f6d..0000000 --- a/nvim/colors +++ /dev/null @@ -1 +0,0 @@ -.config/nvim/colors \ No newline at end of file diff --git a/nvim/init.lua b/nvim/init.lua deleted file mode 120000 index 766342e..0000000 --- a/nvim/init.lua +++ /dev/null @@ -1 +0,0 @@ -.config/nvim/init.lua \ No newline at end of file