diff --git a/.config/nvim/init.vim b/.config/nvim/init.vim index 8c0fbad..99e193d 100644 --- a/.config/nvim/init.vim +++ b/.config/nvim/init.vim @@ -1,188 +1,4 @@ -"" -"_____ ______ _____ _______ . _ _ _____ _________ -" | | | | \ \ | | | | | | | | | | | | | | | \ -" | | | | | | | | | | \ \ / / | | | | | | | | -"_|_|_ |_| |_| _|_|_ |_| [] \_\_/_/ _|_|_ |_| |_| |_| -"" - -" Plugins {{{ -if empty(glob('~/.local/share/nvim/site/autoload/plug.vim')) - silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs - \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim - autocmd VimEnter * PlugInstall --sync | source $MYVIMRC -endif - -call plug#begin() - -" Editing - " text objects -Plug 'xerus2000/argtextobj.vim' " arguments in brackets as text objects -Plug 'bkad/CamelCaseMotion' " -Plug 'tpope/vim-surround' " edit surroundings - cs, ds, ys - " commands -Plug 'inkarkat/vim-ReplaceWithRegister' " gr to replace with register -Plug 'tpope/vim-commentary' " gc to comment out (gcap for paragraph) -Plug 'terryma/vim-multiple-cursors' " new coursor+selection on match, skip, remove cursor & back - " libs -Plug 'tpope/vim-repeat' -Plug 'inkarkat/vim-ingo-library' - -" Ex commands -Plug 'DataWraith/auto_mkdir' " mkdir parent dirs when saving -Plug 'AndrewRadev/bufferize.vim' " Command to buffer -Plug 'tpope/vim-eunuch' " OS helpers -Plug 'tpope/vim-fugitive' " Git commands in vim -Plug 'jreybert/vimagit' " Magit for vim - git stage individual changes -Plug 'doy/vim-diff-changes' " Commands for diffing - :DiffAgainstFilesystem :DiffAgainstVCS :DiffStop -Plug 'junegunn/fzf' " File selection with :FZF - " Browse -Plug 'tyru/open-browser.vim' " :OpenBrowser, :OpenBrowserSearch -let g:openbrowser_default_search="duckduckgo" -Plug 'tyru/open-browser-github.vim' -let g:netrw_nogx = 1 " disable netrw's gx mapping. -nmap gs (openbrowser-smart-search) -vmap gs (openbrowser-smart-search) -nmap gx yi':OpenGithubProject " -command! S OpenBrowserSmartSearch " -command! GH OpenGithubProject " - -" QOL -Plug 'farmergreg/vim-lastplace' " Automatically jump to last edit position -Plug 'chrisbra/Recover.vim' " Add Recover options for swap files - " Remove trailing whitespace on save -Plug 'ntpeters/vim-better-whitespace' -highlight ExtraWhitespace ctermbg=4 -let g:strip_whitespace_on_save=1 -let g:show_spaces_that_precede_tabs=1 -let g:better_whitespace_skip_empty_lines=1 -autocmd FileType taskedit if exists(":DisableWhitespace") | execute ":DisableWhitespace" | endif -autocmd BufRead $MYVIMRC DisableStripWhitespaceOnSave - -" Aesthetic -Plug 'vim-airline/vim-airline' " Status bar on the bottom -Plug 'psliwka/vim-smoothie' " Smooth scrolling -Plug 'romainl/vim-cool' " Automatically stop highlighting search results when moving - https://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting -Plug 'airblade/vim-gitgutter' " Git info on the left -Plug 'norcalli/nvim-colorizer.lua' " Highlights color literals - " Visual indent guides -Plug 'nathanaelkane/vim-indent-guides' -let g:indent_guides_enable_on_vim_startup = 1 - -" Integrations -Plug 'neoclide/coc.nvim', {'branch': 'release' } -Plug 'udalov/kotlin-vim' -Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' } -Plug 'glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } } - -call plug#end() - -" Colors -set termguicolors -lua require'colorizer'.setup() - -command! PU PlugInstall | PlugUpdate | PlugUpgrade -" }}} - -" Config {{{ - -" FILETYPES -syntax on -filetype plugin on -autocmd BufRead,BufNewFile $SHELL_CONFIG/* set filetype=zsh -autocmd FileType json syntax match Comment +\/\/.\+$+ " Comment highlighting in JSON -autocmd Filetype * set formatoptions-=o " Don't automatically comment on o - -set number relativenumber " Relative line numbering on the left -set clipboard+=unnamedplus " Merge with system clipboard -set scrolloff=7 sidescrolloff=5 " Keep some context when scrolling -set tabstop=4 shiftwidth=4 " Indentation -set splitright " Vertical split to right by default -set cursorline cursorcolumn - -set incsearch hlsearch " Handier search, even though nvim seems to enable it by default -set ignorecase smartcase " Only search case-sensitive when searching with uppercase - -set wildmode=longest,list,full " Auto-completion -set mouse=a " Enable mouse in all modes - -set showmatch " Highlight matching parenthesis -set mps+=<:> " More pairings for '%' - -" Folding -set foldmethod=marker " Use triple curly braces for folds -set foldopen+=jump " Automatically open folds on jump - -set noshowmode " Don't show current mode because airline already does and it inhibits echo in visual mode - -set diffopt+=vertical -command! DiffSwap :diffsp % " Diff for swap - somewhat obsolete by 'chrisbra/Recover.vim' - -set spelllang=en_us,de_de -autocmd FileType markdown setlocal spell " Spell checking in markdown - - " Center on insert mode -autocmd InsertEnter * norm zz - -" }}} - -" Mappings {{{ - - " Allow saving of files as root when I forgot to use sudoedit -cnoremap w!! execute 'write !sudo tee % >/dev/null' edit! -command! WS write source $MYVIMRC -command! FormatJSON %!python -m json.tool - -" Add shebang - https://www.reddit.com/r/vim/comments/4z7z7s/add_shebang_lines_to_your_vim_files_automatically/d6v7op8 and https://stackoverflow.com/a/52135425 -inoreabbrev #!! "#!/usr/bin/env" . (empty(&filetype) ? '' : ' '.&filetype) -"autocmd BufNewFile * if !empty(&filetype) | execute 'silent! 1s/.*/#!\/usr\/bin\/' . &filetype . '\r\r'| :startinsert | endif - -" Sane yanking -map Y y$ -" Disable Ex mode - https://vi.stackexchange.com/q/457 -nnoremap Q - -let mapleader=" " - - " Alias write and quit to leader -nnoremap q :wq -nnoremap w :w - - " Easy split navigation -nnoremap -nnoremap -nnoremap -nnoremap - " Shortcut split opening -nnoremap h :split -nnoremap v :vsplit - - " Alias replace all to S -nnoremap S :%s//gI - - " Jump around without shift -nnoremap gl $ -nnoremap gh 0 -nnoremap gk H -nnoremap gj L -nnoremap gt gg -nnoremap gb G - - " Enable and disable auto comment -map c :setlocal formatoptions-=cro -map C :setlocal formatoptions=cro - -map i :setlocal autoindent! -map s :setlocal spell! - -function! ShowPosition() - return ":\echo 'start=" . string(getpos("v")) . " end=" . string(getpos(".")) . "'\gv" -endfunction -vmap ;j ShowPosition() - -function! MoveTest() - exe 'silent! normal! ^va"' - normal! :\\ - echo getpos('.') getpos("'<") getpos("'>") -endfunction - -" }}} +source $XDG_CONFIG_HOME/nvim/init/plug.vim +source $XDG_CONFIG_HOME/nvim/init/general.vim +source $XDG_CONFIG_HOME/nvim/init/pluginConfig.vim +source $XDG_CONFIG_HOME/nvim/init/keys.vim diff --git a/.config/nvim/init/general.vim b/.config/nvim/init/general.vim new file mode 100644 index 0000000..185c824 --- /dev/null +++ b/.config/nvim/init/general.vim @@ -0,0 +1,47 @@ +set termguicolors +set mouse=a " Enable mouse in all modes + +set undofile +set wildmode=longest,list,full " Auto-completion +set clipboard+=unnamedplus " Merge with system clipboard + +set tabstop=4 shiftwidth=4 " Indentation + +" visuals +set number relativenumber " Relative line numbering on the left +set wrap linebreak +set cursorline cursorcolumn +set scrolloff=7 sidescrolloff=20 " Keep some context when scrolling + +set colorcolumn=81,121 +highlight ColorColumn ctermbg=grey guibg=#888888 +" call matchadd('ColorColumn', '\%81v', 100) + +" search +set incsearch hlsearch " Handier search, even though nvim seems to enable it by default +set ignorecase smartcase " Only search case-sensitive when searching with uppercase +" matching +set showmatch " Highlight matching parenthesis +set matchpairs+=<:> " More pairings for '%' + +set splitright " Vertical split to right by default +set diffopt+=vertical + +" Folding +set foldmethod=marker " Use triple curly braces for folds +set foldopen+=jump " Automatically open folds on jump + +" FILETYPES +syntax on +filetype plugin on +autocmd FileType json syntax match Comment +\/\/.\+$+ " Comment highlighting in JSON +autocmd Filetype * set formatoptions-=o " Don't automatically comment on o +" custom hardcoded types +autocmd BufRead,BufNewFile $SHELL_CONFIG/* set filetype=zsh +autocmd BufRead,BufNewFile www.mixxx.org_wiki* set filetype=dokuwiki scrolloff=1 + +set spelllang=en_us,de_de +autocmd FileType markdown setlocal spell " Spell checking in markdown + + " Center on insert mode +autocmd InsertEnter * norm zz diff --git a/.config/nvim/init/keys.vim b/.config/nvim/init/keys.vim new file mode 100644 index 0000000..fb43b32 --- /dev/null +++ b/.config/nvim/init/keys.vim @@ -0,0 +1,52 @@ +" Save file as root when I forgot to use sudoedit +cnoremap w!! execute 'write !sudo tee % >/dev/null' edit! +" Write file & source vimrc (really only makes sense from within vimrc to quickly test changes) +command! WS write source $MYVIMRC + +command! FormatJSON %!python -m json.tool +command! DiffSwap :diffsp % " Diff for swap - replaced by 'chrisbra/Recover.vim' + +" shebang shortcut - https://www.reddit.com/r/vim/comments/4z7z7s/add_shebang_lines_to_your_vim_files_automatically/d6v7op8 and https://stackoverflow.com/a/52135425 +inoreabbrev #!! "#!/usr/bin/env" . (empty(&filetype) ? '' : ' '.&filetype) +autocmd BufNewFile *.sh execute 'silent! 1s/.*/#!\/bin\/sh\r\r'| :startinsert +"autocmd BufNewFile * if !empty(&filetype) | execute 'silent! 1s/.*/#!\/usr\/bin\/' . &filetype . '\r\r'| :startinsert | endif + +" Sane yanking +map Y y$ +" Disable Ex mode - https://vi.stackexchange.com/q/457 +nnoremap Q + +let mapleader=" " + + " Alias write and quit to leader +nnoremap q :wq +nnoremap w :w + + " Easy split navigation +nnoremap +nnoremap +nnoremap +nnoremap + " Shortcut split opening +nnoremap h :split +nnoremap v :vsplit + + " Alias replace all to S +nnoremap S :%s//gI + + " Jump around without shift +nnoremap gl $ +nnoremap gh 0 +nnoremap gk H +nnoremap gj L +nnoremap gt gg +nnoremap gb G + + " Enable and disable auto comment +map c :setlocal formatoptions-=cro +map C :setlocal formatoptions=cro + +map i :setlocal autoindent! +map s :setlocal spell! + +" }}} diff --git a/.config/nvim/init/plug.vim b/.config/nvim/init/plug.vim new file mode 100644 index 0000000..d9abe0b --- /dev/null +++ b/.config/nvim/init/plug.vim @@ -0,0 +1,62 @@ +" Plug +if empty(glob('~/.local/share/nvim/site/autoload/plug.vim')) + silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs + \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim + + autocmd VimEnter * PlugInstall --sync | source $MYVIMRC +endif + +call plug#begin() + +" Editing + " text objects +Plug 'xerus2000/argtextobj.vim' " arguments in brackets as text objects +Plug 'tpope/vim-surround' " edit surroundings - cs, ds, ys +Plug 'bkad/CamelCaseMotion' " move through camel case words + " commands +Plug 'inkarkat/vim-ReplaceWithRegister' " gr to replace with register +Plug 'tpope/vim-commentary' " gc to comment out (gcap for paragraph) +Plug 'terryma/vim-multiple-cursors' " new coursor+selection on match, skip, remove cursor & back +Plug 'junegunn/vim-easy-align' " ga to align stuff +xmap ga (EasyAlign) +nmap ga (EasyAlign) + " libs +Plug 'tpope/vim-repeat' +Plug 'inkarkat/vim-ingo-library' + +" Ex commands +Plug 'DataWraith/auto_mkdir' " mkdir parent dirs when saving +Plug 'AndrewRadev/bufferize.vim' " Command to buffer +Plug 'tpope/vim-eunuch' " OS helpers +Plug 'tpope/vim-fugitive' " Git commands in vim +Plug 'jreybert/vimagit' " Magit for vim - git stage individual changes +Plug 'doy/vim-diff-changes' " Commands for diffing - :DiffAgainstFilesystem :DiffAgainstVCS :DiffStop +Plug 'junegunn/fzf' " File selection with :FZF + " Browse +Plug 'tyru/open-browser.vim' " :OpenBrowser, :OpenBrowserSearch +Plug 'tyru/open-browser-github.vim' + +" QOL +Plug 'farmergreg/vim-lastplace' " Automatically jump to last edit position +Plug 'chrisbra/Recover.vim' " Add Recover options for swap files +Plug 'ntpeters/vim-better-whitespace' " Tools for trailing whitespace & mixed indents + +" Aesthetic +Plug 'vim-airline/vim-airline' " Status bar on the bottom +Plug 'psliwka/vim-smoothie' " Smooth scrolling +Plug 'romainl/vim-cool' " Automatically stop highlighting search results when moving - https://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting +Plug 'airblade/vim-gitgutter' " Git info on the left +Plug 'norcalli/nvim-colorizer.lua' " Highlights color literals + " Visual indent guides +Plug 'nathanaelkane/vim-indent-guides' +let g:indent_guides_enable_on_vim_startup = 1 + +" Integrations +Plug 'xerus2000/vim-dokuwiki' +Plug 'neoclide/coc.nvim', {'branch': 'release' } +Plug 'udalov/kotlin-vim' +Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' } +Plug 'glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } } + +call plug#end() + diff --git a/.config/nvim/init/pluginConfig.vim b/.config/nvim/init/pluginConfig.vim new file mode 100644 index 0000000..d9e816f --- /dev/null +++ b/.config/nvim/init/pluginConfig.vim @@ -0,0 +1,61 @@ +" Don't show current mode because airline already does and it inhibits echo in visual mode +set noshowmode + +command! PU PlugUpdate | PlugUpgrade + +lua require 'colorizer'.setup({ '*'; markdown = { names = false; }; }) + +let g:strip_whitespace_on_save=1 +let g:show_spaces_that_precede_tabs=1 +let g:better_whitespace_skip_empty_lines=1 +let g:better_whitespace_guicolor=$THEME == 'light' ? 'LightGrey' : 'DarkGrey' +autocmd FileType taskedit,markdown DisableWhitespace +" see https://github.com/ntpeters/vim-better-whitespace/issues/134 - autocmd OptionSet background let g:better_whitespace_guicolor=&background == 'light' ? 'LightYellow' : 'Brown' + +map w CamelCaseMotion_w +map b CamelCaseMotion_b +map e CamelCaseMotion_e +map ge CamelCaseMotion_ge +omap iw CamelCaseMotion_iw +xmap iw CamelCaseMotion_iw +omap ib CamelCaseMotion_ib +xmap ib CamelCaseMotion_ib +omap ie CamelCaseMotion_ie +xmap ie CamelCaseMotion_ie + +" open-browser +let g:openbrowser_default_search="duckduckgo" +let g:netrw_nogx = 1 " disable netrw's gx mapping. +nmap gs (openbrowser-smart-search) +vmap gs (openbrowser-smart-search) +nmap gx yi':OpenGithubProject " +command! S OpenBrowserSmartSearch " +command! GH OpenGithubProject " + +" firenvim +let g:firenvim_config = { + \ 'globalSettings': { + \ 'alt': 'all', + \ }, + \ 'localSettings': { + \ '.*': { + \ 'cmdline': 'neovim', + \ 'priority': 0, + \ 'selector': 'textarea:not([readonly]):not([class="handsontableInput"]), div[role="textbox"]', + \ 'takeover': 'always', + \ }, + \ '.*notion\.so.*': { 'priority': 1, 'takeover': 'never', }, + \ '.*openstreetmap\.org.*': { 'priority': 1, 'takeover': 'never', }, + \ } +\ } +if exists('g:started_by_firenvim') + autocmd FocusLost,InsertLeave,BufLeave * ++nested call WriteSilent() + function WriteSilent() + let tmp=b:better_whitespace_enabled + let b:better_whitespace_enabled=0 + write + let b:better_whitespace_enabled=tmp + endfunction + nnoremap :call firenvim#focus_page() + let g:strip_whitespace_on_save=0 +endif