From ba01aa4f0f2a1822df4cc77194d2668dfdaa7780 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 4 Nov 2021 21:34:20 +0100 Subject: Added neovim draft config in lua --- config/nvim/init.lua | 355 ++++++++----------------------------------- config/nvim/lua/mappings.lua | 182 ++++++++++++++++++++++ config/nvim/lua/plugins.lua | 25 +++ config/vim/vimrc | 20 +-- config/zsh/aliases.zsh | 3 +- 5 files changed, 285 insertions(+), 300 deletions(-) create mode 100644 config/nvim/lua/mappings.lua create mode 100644 config/nvim/lua/plugins.lua diff --git a/config/nvim/init.lua b/config/nvim/init.lua index fc5c561..9113752 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -1,61 +1,31 @@ --- xdg --- set runtimepath^=$XDG_CONFIG_HOME/vim --- set runtimepath+=$XDG_DATA_HOME/vim --- set runtimepath+=$XDG_CONFIG_HOME/vim/after --- --- set packpath^=$XDG_DATA_HOME/vim,$XDG_CONFIG_HOME/vim --- set packpath+=$XDG_CONFIG_HOME/vim/after,$XDG_DATA_HOME/vim/after --- --- let g:netrw_home = $XDG_DATA_HOME . '/vim' --- call mkdir($XDG_DATA_HOME . '/vim/spell', 'p') --- set viewdir=$XDG_DATA_HOME/vim/view | call mkdir(&viewdir, 'p') --- --- set backupdir=$XDG_CACHE_HOME/vim/backup | call mkdir(&backupdir, 'p') --- set directory=$XDG_CACHE_HOME/vim/swap | call mkdir(&directory, 'p') --- set undodir=$XDG_CACHE_HOME/vim/undo | call mkdir(&undodir, 'p') - -source $XDG_CONFIG_HOME/vim/pluggins.vim -- load pluggins - --- TODO --- vim.fn <-- functions --- vim.opt <-- options --- replace fzf by telescope --- better syntax highlight with tree-sitter --- .......................................................... +require('plugins') -- common -let mapleader = ' ' -- set leader key to space -let maplocalleader = '-' -- set file local leader key to backslash +-- let mapleader = ' ' -- set leader key to space +-- let maplocalleader = '-' -- set file local leader key to backslash -- vint: -ProhibitSetNoCompatible -vim.opt.nocompatible = true -- not compatible with vi -vim.opt.number =true -- line number --- set relativenumber " line number relative to cursor +vim.opt.compatible = false -- not compatible with vi +vim.opt.number = true -- line number vim.opt.numberwidth = 1 -- line numbers gutter autowidth vim.opt.cursorline = true -- highlight current line -vim.opt.noshowmatch = true -- dont jump to pair bracket +vim.opt.showmatch = false -- dont jump to pair bracket vim.opt.autoread = true -- reload files when changes happen outside vim vim.opt.autowrite = true -- auto write buf on certain events vim.opt.hidden = true -- keep change in buffer when quitting window -vim.opt.noswapfile = true -- disable swap files -vim.opt.scrolloff=2 = true -- line padding when scrolling -vim.opt.textwidth=0 = true -- when line wrap occurs -vim.opt.wrapmargin=0 = true -- disable auto line wrapping +vim.opt.swapfile = false -- disable swap files +vim.opt.scrolloff = 2 -- line padding when scrolling +vim.opt.textwidth = 0 -- when line wrap occurs +vim.opt.wrapmargin = 0 -- disable auto line wrapping vim.opt.encoding = "utf-8" -- utf-8 encoding --- scriptencoding "utf-8" +-- vim.opt.scriptencoding = "utf-8" -- vim.opt.formatoptions -= 't' -- do not auto break line > 89 character -filetype plugin indent on -- allow to add specific rules for certain type of file +-- filetype plugin indent on -- allow to add specific rules for certain type of file -- set mouse=a " mouse scrolling (heretic) -vim.opt.shellredir=> -- don't inclue stderr when reading a command - --- browse list with tab -vim.opt.wildmode=longest,list,full -vim.opt.wildmenu -- tab to cycle through completion options -vim.opt.path+=** -- recursive :find - +vim.opt.shellredir = ">" -- don't inclue stderr when reading a command -- intuitif split opening -vim.opt.splitbelow -vim.opt.splitright -vim.opt.fillchars+=vert:│ -- split separator +vim.opt.splitbelow = true +vim.opt.splitright = true +-- vim.opt.fillchars = "vert:│" -- split separator -- tab vim.opt.expandtab = true -- tab to space @@ -68,252 +38,59 @@ vim.opt.smartindent = true -- file search vim.opt.ignorecase = true -- case insensitive vim.opt.smartcase = true -vim.opt.hlsearch -- match highlight +vim.opt.hlsearch = true -- match highlight vim.opt.incsearch = true -- status vim.opt.laststatus=2 -- always a statusline (all window) -vim.opt.showcmd -- show current partial command in the bottom right -vim.opt.noshowmode -- dont show current mode (i.e --INSERT--) - --- fold -vim.opt.foldmethod=indent -- create fold based on the text indent -vim.opt.nofoldenable -- not folded by default - ---"""""""""""""" --- colorscheme " ---"""""""""""""" - -vim.opt.background=dark --- one --- let g:onedark_terminal_italics=1 --- colorscheme onedark --- dracula --- let g:dracula_bold = 1 --- let g:dracula_italic = 1 --- let g:dracula_colorterm = 0 --- silent! colorscheme dracula --- solarized --- set t_Co=16 --- let g:solarized_termcolors=16 --- let g:solarized_visibility='low' " visibility of invisible chars with set list --- silent! colorscheme solarized - -let g:gruvbox_italic=1 -let g:gruvbox_bold=1 -let g:gruvbox_termcolors=256 -let g:gruvbox_contrast_dark='medium' -let g:gruvbox_contrast_light='hard' -let g:gruvbox_invert_selection=0 -colorscheme gruvbox - --- lightline -let g:lightline = {} --- let g:lightline.colorscheme = 'solarized' " lightline theme to solarized --- let g:lightline.colorscheme = 'jellybeans' " lightline theme to onedark -let g:lightline = { - \ 'colorscheme': 'gruvbox', - \ 'active': { - \ 'left': [ [ 'mode', 'paste' ], - \ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ] - \ }, - \ 'component_function': { - \ 'gitbranch': 'FugitiveHead' - \ }, - \ } - ---""""""""""" --- mappings " ---""""""""""" - --- split navigation -nnoremap -nnoremap -nnoremap -nnoremap --- nnoremap --- nnoremap --- nnoremap --- nnoremap -nnoremap s= = - --- common --- 'Y' yank to the end of the line -noremap Y y$ --- solves annoying delay went exiting insert mode -inoremap --- kj to exit insert mode -inoremap kj --- remove visual mode keybinding -noremap Q --- search with very magic -nnoremap / /\v -nnoremap ? ?\v --- move line up and down -nnoremap _ ddkP -nnoremap + ddp --- long move up/down -nnoremap ( 10k -nnoremap ) 10j --- tag nagigation -nnoremap ] -nnoremap t --- common change until -nnoremap cu ct_ -nnoremap cp ct) -nnoremap c, ct, - --- buffer navigation -nnoremap bn :bn -nnoremap bp :bp -nnoremap :b# -nnoremap bl :ls - -nnoremap sc :source $MYVIMRC -- source vimrc - --- c --- create c function body from prototype -nnoremap gcf A{}j - --- initialise a school header file -function PutHeaderBoilerPlate() - let l:filename = join(split(toupper(expand('%:t')), '\.'), '_') - -- echom l:filename - call append(12, '#ifndef ' . l:filename) - call append(13, '# define ' . l:filename) - call append(15, '#endif') -endfunction -nnoremap gch :Stdheader:call PutHeaderBoilerPlate() - --- put semicolon at the end of line -nnoremap ; mqA;`q - --- cpp --- Put Coplien Form boilerplate class -function PutCoplienFormFunc(name) - let l:default_constructor = a:name . '();\n' - let l:copy_constructor = a:name . '(const ' . a:name . '& other);\n' - let l:copy_operator = a:name . '& operator=(const ' . a:name . '& other);\n' - let l:destructor = '~' . a:name . '();\n' - - execute 'normal iclass ' . a:name . '\n{\npublic:\n' . l:default_constructor . l:copy_constructor . l:copy_operator . l:destructor . '\nprivate:\n};\n' - execute 'normal <2{' -endfunction --- Put Coplien Form boilerplate according to filename -command! PutCoplienFormFile call PutCoplienFormFunc(split(expand('%:t'), '\.')[0]) -command! -nargs=1 PutCoplienForm call PutCoplienFormFunc(--") +vim.opt.showcmd = true -- show current partial command in the bottom right +vim.opt.showmode = false -- dont show current mode (i.e --INSERT--) + +-- -- fold +-- vim.opt.foldmethod=indent -- create fold based on the text indent +-- vim.opt.nofoldenable -- not folded by default + +-- colorscheme +vim.opt.termguicolors = true +vim.opt.background = "dark" +vim.cmd [[ colorscheme gruvbox ]] +vim.g.gruvbox_italic = 1 +vim.g.gruvbox_bold = 1 +vim.g.gruvbox_termcolors = 256 +vim.g.gruvbox_contrast_dark = 'medium' +vim.g.gruvbox_contrast_light = 'hard' +vim.g.gruvbox_invert_selection = 0 + +require('lualine').setup { + options = { + theme = 'gruvbox', + section_separators = '', + component_separators = '' + } +} + +require('nvim-treesitter.configs').setup { + highlight = { + enable = true + }, + indent = { + enable = true + }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = "gnn", + node_incremental = "grn", + scope_incremental = "grc", + node_decremental = "grm", + } + } +} + +require('mappings') --- quickfix window toggle -nnoremap q :call QuickfixToggle() -nnoremap n :cnext -nnoremap p :cprevious -let g:quickfix_is_open = 0 -function! QuickfixToggle() - if g:quickfix_is_open - cclose - let g:quickfix_is_open = 0 - else - copen - let g:quickfix_is_open = 1 - endif -endfunction - -function! CountScopeLines() - normal! mq - execute '/^}' - let l:end_brace = line('.') - execute '?^{' - let l:start_brace = line('.') - normal! k - let l:scope_len = l:end_brace - l:start_brace - 1 - let l:scope_name = substitute(getline('.'), '\t', ' ', 'g') - echom l:scope_len . ' lines in |' . l:scope_name . '|' - normal! `q -endfunction -command! CountScopeLines call CountScopeLines() - --- make -nnoremap m :make all - -augroup vimrc - autocmd! -augroup END - --- hook --- remove trailing white space on save -autocmd vimrc BufWritePre * %s/\s\+$//e --- dirty hack to disable this feature on markdown (autocmd! wouldn't work) -autocmd vimrc BufReadPre *.md autocmd! BufWritePre - --- filetype --- real tab in c file for school projects -let g:c_syntax_for_h = 1 -- filetype=c in header files instead of filetype=cpp - -augroup vimrc_files - autocmd! - -- school c - autocmd Filetype c setlocal noexpandtab - autocmd Filetype c setlocal comments=s:/**,m:**,e:*/,s:/*,m:**,e:*/ - -- std::cout << ... << std::endl; shortcut - autocmd Filetype cpp nnoremap cout istd::cout << << std::endl;2Fp :CtrlPTag - --- fzf.vim -nnoremap :GFiles --exclude-standard --others --cached -nnoremap p :Tags - --- quick-scope --- let g:qs_highlight_on_keys = ['f', 'F', 't', 'T'] - --- man-plugin --- runtime! ftplugin/man.vim --- let g:ft_man_open_mode = 'vert' " open in a vertical split --- let g:ft_man_no_sect_fallback = 2 " if page specified fallback to page 2 (syscall pages) --- autocmd Filetype man unmap q: hmmmm?? - --- eazy-align -xmap ga (EasyAlign) -nmap ga (EasyAlign) - -vnoremap c y:call system(--xclip -selection clipboard", getreg("\"")) -nnoremap v :call setreg(--\"", system("xclip -selection clipboard -o"))p - -let g:c_formatter_42_format_on_save = 0 - -let g:gutentags_ctags_exclude = ['doc/*', 'docs/*', 'Makefile', '.mypy_cache', '.pytest_cache', '.tox', 'build/*', 'dist/*'] --- let g:gutentags_ctags_exclude_wildignore = 1 - -let g:goyo_height = 90 -let g:goyo_width = 100 - -vim.opt.viminfo+=n$XDG_CACHE_HOME/vim/viminfo - -let g:python_highlight_all = 1 - -nnoremap l :SidewaysRight -nnoremap h :SidewaysLeft -nnoremap w :ArgWrap -nnoremap ss :setlocal spell! - -hi link juliaFunctionCall Identifier -hi link juliaParDelim Delimiter - -autocmd Filetype markdown nnoremap r :execute 'silent !pandoc % -o %:r.pdf &' \| redraw! \| echom 'Converting to pdf: ' . expand('%:r') . '.pdf' +-- hi link juliaFunctionCall Identifier +-- hi link juliaParDelim Delimiter +-- +-- autocmd Filetype markdown nnoremap r :execute 'silent !pandoc % -o %:r.pdf &' \| redraw! \| echom 'Converting to pdf: ' . expand('%:r') . '.pdf' diff --git a/config/nvim/lua/mappings.lua b/config/nvim/lua/mappings.lua new file mode 100644 index 0000000..b609fbd --- /dev/null +++ b/config/nvim/lua/mappings.lua @@ -0,0 +1,182 @@ +local map = vim.api.nvim_set_keymap + +-- split navigation +map('n', '', '', '', '', 's=', '=' {}) + +-- common +-- -- 'Y' yank to the end of the line +-- noremap Y y$ +-- -- kj to exit insert mode +map('i', 'kj', '', {}) +-- -- remove visual mode keybinding +-- noremap Q +-- -- search with very magic +-- nnoremap / /\v +-- nnoremap ? ?\v +-- -- move line up and down +-- nnoremap _ ddkP +-- nnoremap + ddp +-- -- long move up/down +-- nnoremap ( 10k +-- nnoremap ) 10j +-- -- tag nagigation +-- nnoremap ] +-- nnoremap t +-- -- common change until +-- nnoremap cu ct_ +-- nnoremap cp ct) +-- nnoremap c, ct, +-- +-- -- buffer navigation +-- nnoremap bn :bn +-- nnoremap bp :bp +-- nnoremap :b# +-- nnoremap bl :ls +-- +-- nnoremap sc :source $MYVIMRC -- source vimrc +-- +-- -- c +-- -- create c function body from prototype +-- nnoremap gcf A{}j +-- +-- -- initialise a school header file +-- function PutHeaderBoilerPlate() +-- let l:filename = join(split(toupper(expand('%:t')), '\.'), '_') +-- -- echom l:filename +-- call append(12, '#ifndef ' . l:filename) +-- call append(13, '# define ' . l:filename) +-- call append(15, '#endif') +-- endfunction +-- nnoremap gch :Stdheader:call PutHeaderBoilerPlate() +-- +-- -- put semicolon at the end of line +-- nnoremap ; mqA;`q +-- +-- -- cpp +-- -- Put Coplien Form boilerplate class +-- function PutCoplienFormFunc(name) +-- let l:default_constructor = a:name . '();\n' +-- let l:copy_constructor = a:name . '(const ' . a:name . '& other);\n' +-- let l:copy_operator = a:name . '& operator=(const ' . a:name . '& other);\n' +-- let l:destructor = '~' . a:name . '();\n' +-- +-- execute 'normal iclass ' . a:name . '\n{\npublic:\n' . l:default_constructor . l:copy_constructor . l:copy_operator . l:destructor . '\nprivate:\n};\n' +-- execute 'normal <2{' +-- endfunction +-- -- Put Coplien Form boilerplate according to filename +-- command! PutCoplienFormFile call PutCoplienFormFunc(split(expand('%:t'), '\.')[0]) +-- command! -nargs=1 PutCoplienForm call PutCoplienFormFunc(--") +-- +-- -- quickfix window toggle +-- nnoremap q :call QuickfixToggle() +-- nnoremap n :cnext +-- nnoremap p :cprevious +-- let g:quickfix_is_open = 0 +-- function! QuickfixToggle() +-- if g:quickfix_is_open +-- cclose +-- let g:quickfix_is_open = 0 +-- else +-- copen +-- let g:quickfix_is_open = 1 +-- endif +-- endfunction +-- +-- function! CountScopeLines() +-- normal! mq +-- execute '/^}' +-- let l:end_brace = line('.') +-- execute '?^{' +-- let l:start_brace = line('.') +-- normal! k +-- let l:scope_len = l:end_brace - l:start_brace - 1 +-- let l:scope_name = substitute(getline('.'), '\t', ' ', 'g') +-- echom l:scope_len . ' lines in |' . l:scope_name . '|' +-- normal! `q +-- endfunction +-- command! CountScopeLines call CountScopeLines() +-- +-- -- make +-- nnoremap m :make all +-- +-- augroup vimrc +-- autocmd! +-- augroup END +-- +-- -- hook +-- -- remove trailing white space on save +-- autocmd vimrc BufWritePre * %s/\s\+$//e +-- -- dirty hack to disable this feature on markdown (autocmd! wouldn't work) +-- autocmd vimrc BufReadPre *.md autocmd! BufWritePre +-- +-- -- filetype +-- -- real tab in c file for school projects +-- let g:c_syntax_for_h = 1 -- filetype=c in header files instead of filetype=cpp +-- +-- augroup vimrc_files +-- autocmd! +-- -- school c +-- autocmd Filetype c setlocal noexpandtab +-- autocmd Filetype c setlocal comments=s:/**,m:**,e:*/,s:/*,m:**,e:*/ +-- -- std::cout << ... << std::endl; shortcut +-- autocmd Filetype cpp nnoremap cout istd::cout << << std::endl;2Fp :CtrlPTag +-- +-- -- fzf.vim +-- nnoremap :GFiles --exclude-standard --others --cached +-- nnoremap p :Tags +-- +-- -- quick-scope +-- -- let g:qs_highlight_on_keys = ['f', 'F', 't', 'T'] +-- +-- -- man-plugin +-- -- runtime! ftplugin/man.vim +-- -- let g:ft_man_open_mode = 'vert' " open in a vertical split +-- -- let g:ft_man_no_sect_fallback = 2 " if page specified fallback to page 2 (syscall pages) +-- -- autocmd Filetype man unmap q: hmmmm?? +-- +-- -- eazy-align +-- xmap ga (EasyAlign) +-- nmap ga (EasyAlign) +-- +-- vnoremap c y:call system(--xclip -selection clipboard", getreg("\"")) +-- nnoremap v :call setreg(--\"", system("xclip -selection clipboard -o"))p +-- +-- let g:c_formatter_42_format_on_save = 0 +-- +-- let g:gutentags_ctags_exclude = ['doc/*', 'docs/*', 'Makefile', '.mypy_cache', '.pytest_cache', '.tox', 'build/*', 'dist/*'] +-- -- let g:gutentags_ctags_exclude_wildignore = 1 +-- +-- let g:goyo_height = 90 +-- let g:goyo_width = 100 +-- +-- vim.opt.viminfo+=n$XDG_CACHE_HOME/vim/viminfo +-- +-- let g:python_highlight_all = 1 +-- +-- nnoremap l :SidewaysRight +-- nnoremap h :SidewaysLeft +-- nnoremap w :ArgWrap +-- nnoremap ss :setlocal spell! diff --git a/config/nvim/lua/plugins.lua b/config/nvim/lua/plugins.lua new file mode 100644 index 0000000..7bdb86f --- /dev/null +++ b/config/nvim/lua/plugins.lua @@ -0,0 +1,25 @@ +vim.cmd [[packadd packer.nvim]] + +return require('packer').startup(function() + use 'wbthomason/packer.nvim' + + use {"ellisonleao/gruvbox.nvim", requires = {"rktjmp/lush.nvim"}} + + use { + 'nvim-lualine/lualine.nvim', + requires = {'kyazdani42/nvim-web-devicons', opt = true} + } + + use { + 'nvim-treesitter/nvim-treesitter', + run = ':TSUpdate' + } + + use { + 'nvim-telescope/telescope.nvim', + requires = { {'nvim-lua/plenary.nvim'} } + } + + use 'terrortylor/nvim-comment' + require('nvim_comment').setup() +end) diff --git a/config/vim/vimrc b/config/vim/vimrc index 585e5bf..6822f78 100644 --- a/config/vim/vimrc +++ b/config/vim/vimrc @@ -342,17 +342,17 @@ nnoremap gf :vsp " from: https://vim.fandom.com/wiki/Autocomplete_with_TAB_when_typing_words -function! TabOrComplete(direction) - if col('.') > 1 && strpart(getline('.'), col('.') - 2, 3) =~# '^\w' - return a:direction ==# 'next' ? "\" : "\" - else - return "\" - endif -endfunction - -inoremap =TabOrComplete('next') +" function! TabOrComplete(direction) +" if col('.') > 1 && strpart(getline('.'), col('.') - 2, 3) =~# '^\w' +" return a:direction ==# 'next' ? "\" : "\" +" else +" return "\" +" endif +" endfunction + +" inoremap =TabOrComplete('next') " st maps Shift-Tab to [Z (and it's discouraged to change it) -inoremap [Z =TabOrComplete('prev') +" inoremap [Z =TabOrComplete('prev') command! LaTeXtoUnicodeToggle call LaTeXtoUnicode#Toggle() diff --git a/config/zsh/aliases.zsh b/config/zsh/aliases.zsh index 6541211..3abbf03 100644 --- a/config/zsh/aliases.zsh +++ b/config/zsh/aliases.zsh @@ -14,6 +14,7 @@ alias yay='yay --color=auto' # common commands alias less='less -N' # enable line number alias v='vim' +alias nvim='VIMINIT="" nvim' # alias vim='nvim' # alias mkdir='mkdir -p' alias gdb='gdb -q' # disable long intro message @@ -95,7 +96,7 @@ alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' -alias norminette='ruby ~/git/norminette/norminette.rb' +# alias norminette='ruby ~/git/norminette/norminette.rb' alias norm='norminette' # bluetooth -- cgit