From b5500d5e9e1b4dbae09014f7549e72e86df3130f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20B=C3=A4dorf?= Date: Mon, 29 Nov 2021 19:06:10 +0100 Subject: [PATCH] Better terminal editing experience * Decrease alacritty font size * Improve file previews in fzf-nvim by removing some copyright notices * Use reverse layout in fzf-nvim to align with zsh file completion --- modules/graphical/alacritty.nix | 2 +- modules/terminal-life/nvim/default.nix | 10 +++++ modules/terminal-life/nvim/init.vim | 41 --------------------- modules/terminal-life/nvim/plugins.vim | 32 ++++++++++++++++ modules/terminal-life/nvim/preview-file.nix | 35 ++++++++++++++++++ 5 files changed, 78 insertions(+), 42 deletions(-) create mode 100644 modules/terminal-life/nvim/preview-file.nix diff --git a/modules/graphical/alacritty.nix b/modules/graphical/alacritty.nix index ef6c6956..f08be710 100644 --- a/modules/graphical/alacritty.nix +++ b/modules/graphical/alacritty.nix @@ -55,7 +55,7 @@ style = "Italic"; }; - size = 18.0; + size = 16.0; offset = { x = 0; diff --git a/modules/terminal-life/nvim/default.nix b/modules/terminal-life/nvim/default.nix index f66ce597..d25c1173 100644 --- a/modules/terminal-life/nvim/default.nix +++ b/modules/terminal-life/nvim/default.nix @@ -3,6 +3,8 @@ let psCfg = config.pub-solar; xdg = config.home-manager.users."${psCfg.user.name}".xdg; + preview-file = pkgs.writeShellScriptBin "preview-file" (import ./preview-file.nix pkgs); + sonokai = pkgs.vimUtils.buildVimPlugin { name = "sonokai"; src = pkgs.fetchFromGitHub { @@ -66,6 +68,11 @@ in (builtins.readFile ./ui.vim) (builtins.readFile ./quickfixopenall.vim) (builtins.readFile ./lsp.vim) + '' + " fzf with file preview + command! -bang -nargs=? -complete=dir Files + \ call fzf#vim#files(, { 'options': ['--keep-right', '--cycle', '--layout', 'reverse', '--preview', '${preview-file}/bin/preview-file {}'] }, 0) + '' ]; extraPackages = with pkgs; [ @@ -93,6 +100,9 @@ in ]; plugins = with pkgs.vimPlugins; [ + # Lua async programming library + plenary-nvim + completion-nvim lsp_extensions-nvim nvim-lspconfig diff --git a/modules/terminal-life/nvim/init.vim b/modules/terminal-life/nvim/init.vim index b32a5022..9d4ac597 100644 --- a/modules/terminal-life/nvim/init.vim +++ b/modules/terminal-life/nvim/init.vim @@ -94,47 +94,6 @@ imap (fzf-complete-line) " Clear quickfix shortcut nmap c :ccl -" netrw -let g:netrw_fastbrowse=0 - -" fzf with file preview -command! -bang -nargs=? -complete=dir Files - \ call fzf#vim#files(, fzf#vim#with_preview(), 0) -"command! -bang -nargs=? -complete=dir Files -" \ call fzf#vim#files(, fzf#vim#with_preview({'options': '--preview "' . "grep -Pzo '.*See docs/COPYRIGHT.rdoc for more details(.*\n)*' {}" . '"'}), 0) - -" Auto-FMT rust code on save -let g:rustfmt_autosave = 1 - -" Indenting in html template tags -let g:html_indent_style1 = "inc" - -" yank highlight duration -let g:highlightedyank_highlight_duration = 200 - -" Markdown options -let g:vim_markdown_folding_disabled = 1 - -" Haskell options -let g:haskell_enable_quantification = 1 " to enable highlighting of `forall` -let g:haskell_enable_recursivedo = 1 " to enable highlighting of `mdo` and `rec` -let g:haskell_enable_arrowsyntax = 1 " to enable highlighting of `proc` -let g:haskell_enable_pattern_synonyms = 1 " to enable highlighting of `pattern` -let g:haskell_enable_typeroles = 1 " to enable highlighting of type roles -let g:haskell_enable_static_pointers = 1 " to enable highlighting of `static` -let g:haskell_backpack = 1 " to enable highlighting of backpack keywords - -" Emmet -let g:user_emmet_leader_key='' - -" Minimap settings -let g:minimap_auto_start = 1 - -" Ack -if executable('ag') - let g:ackprg = 'ag --vimgrep' -endif - " Remember cursor position " Vim jumps to the last position when reopening a file if has("autocmd") diff --git a/modules/terminal-life/nvim/plugins.vim b/modules/terminal-life/nvim/plugins.vim index 1ff28d6c..2386826a 100644 --- a/modules/terminal-life/nvim/plugins.vim +++ b/modules/terminal-life/nvim/plugins.vim @@ -41,3 +41,35 @@ nnoremap gP :! git push " git Push " http://vimcasts.org/episodes/fugitive-vim-resolving-merge-conflicts-with-vimdiff/ nmap [ :diffget //2 nmap ] :diffget //3 + +" netrw +let g:netrw_fastbrowse=0 + +" Auto-FMT rust code on save +let g:rustfmt_autosave = 1 + +" Indenting in html template tags +let g:html_indent_style1 = "inc" + +" yank highlight duration +let g:highlightedyank_highlight_duration = 200 + +" Markdown options +let g:vim_markdown_folding_disabled = 1 + +" Haskell options +let g:haskell_enable_quantification = 1 " to enable highlighting of `forall` +let g:haskell_enable_recursivedo = 1 " to enable highlighting of `mdo` and `rec` +let g:haskell_enable_arrowsyntax = 1 " to enable highlighting of `proc` +let g:haskell_enable_pattern_synonyms = 1 " to enable highlighting of `pattern` +let g:haskell_enable_typeroles = 1 " to enable highlighting of type roles +let g:haskell_enable_static_pointers = 1 " to enable highlighting of `static` +let g:haskell_backpack = 1 " to enable highlighting of backpack keywords + +" Emmet +let g:user_emmet_leader_key='' + +" Ack +if executable('ag') + let g:ackprg = 'ag --vimgrep' +endif diff --git a/modules/terminal-life/nvim/preview-file.nix b/modules/terminal-life/nvim/preview-file.nix new file mode 100644 index 00000000..35f608fd --- /dev/null +++ b/modules/terminal-life/nvim/preview-file.nix @@ -0,0 +1,35 @@ +self: with self; '' +IFS=':' read -r -a INPUT <<< "$1" +FILE=''${INPUT[0]} +CENTER=''${INPUT[1]} + +if [[ "$1" =~ ^[A-Za-z]:\\ ]]; then + FILE=$FILE:''${INPUT[1]} + CENTER=''${INPUT[2]} +fi + +if [[ -n "$CENTER" && ! "$CENTER" =~ ^[0-9] ]]; then + exit 1 +fi +CENTER=''${CENTER/[^0-9]*/} + +FILE="''${FILE/#\~\//$HOME/}" +if [ ! -r "$FILE" ]; then + echo "File not found ''${FILE}" + exit 1 +fi + +if [ -z "$CENTER" ]; then + CENTER=0 +fi + +exec cat "$FILE" \ + | sed -e '/[#|\/\/ ?]-- copyright/,/[#\/\/]++/c\\' \ + | ${pkgs.coreutils}/bin/tr -s '\n' \ + | ${pkgs.bat}/bin/bat \ + --style="''${BAT_STYLE:-numbers}" \ + --color=always \ + --pager=never \ + --file-name=''$FILE \ + --highlight-line=$CENTER +''