diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..b315925 --- /dev/null +++ b/.stylua.toml @@ -0,0 +1,7 @@ +column_width = 160 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferSingle" +no_call_parentheses = true + diff --git a/home.nix b/home.nix index afdd876..c93d3a7 100644 --- a/home.nix +++ b/home.nix @@ -6,6 +6,10 @@ imports = (import ./programs); + nixpkgs.overlays = [ + (import ./overlays/sumneko-lua-language-server) + ]; + home = { username = "salar"; homeDirectory = "/Users/salar"; @@ -107,6 +111,12 @@ set -xg JAVA_HOME /Users/salar/.nix-profile/bin + set -xg JDTLS_CONFIG /Users/salar/.config/jdt-language-server/config_mac + + set -xg JAR /Users/salar/.config/jdt-language-server/plugins/org.eclipse.equinox.launcher_1.6.200.v20210416-2027.jar + + set -xg WORKSPACE /Users/salar/Projects + set -xg NIX_PATH $HOME/.nix-defexpr/channels $NIX_PATH set -xg FZF_DEFAULT_OPTS "--preview='bat {} --color=always'" \n @@ -161,56 +171,68 @@ end ''; + # Neovim Configuration + xdg.configFile."nvim/lua/salargalaxyline.lua".source = programs/neovim/settings/salargalaxyline.lua; + xdg.configFile."nvim/init.lua".source = programs/neovim/init.lua; + home.packages = [ - pkgs.awscli - pkgs.pgcli - pkgs.tig - pkgs.ripgrep - pkgs.hugo - pkgs.jansson - pkgs.universal-ctags - pkgs.httpie - pkgs.global - pkgs.fd - pkgs.curlFull - pkgs.wget - pkgs.readline - pkgs.tree - pkgs.exa - pkgs.openssl - pkgs.xz - pkgs.gitAndTools.diff-so-fancy - pkgs.ranger - pkgs.gnupg - pkgs.niv - pkgs.ffmpeg - pkgs.gradle - pkgs.maven - pkgs.procs - pkgs.shellcheck - pkgs.cabal-install - pkgs.hlint - pkgs.ghcid - pkgs.pandoc - pkgs.multimarkdown - pkgs.direnv - pkgs.nixfmt - pkgs.cmake + pkgs.adoptopenjdk-bin pkgs.any-nix-shell pkgs.asciinema - pkgs.ncdu - pkgs.prettyping - pkgs.rnix-lsp pkgs.aspell - pkgs.procs + pkgs.awscli + pkgs.cabal-install + pkgs.cmake + pkgs.coursier + pkgs.curlFull + pkgs.direnv pkgs.dust - pkgs.tokei - pkgs.tealdeer - pkgs.hyperfine + pkgs.exa + pkgs.fd + pkgs.ffmpeg + pkgs.ghcid + pkgs.gitAndTools.diff-so-fancy + pkgs.global + pkgs.gnupg + pkgs.gradle pkgs.graphviz + pkgs.hlint + pkgs.httpie + pkgs.hugo + pkgs.hyperfine + pkgs.jansson + pkgs.luajit + pkgs.luajitPackages.luarocks + pkgs.maven + pkgs.multimarkdown + pkgs.ncdu pkgs.neofetch - pkgs.adoptopenjdk-openj9-bin-16 - pkgs.vscodium + pkgs.neovim + pkgs.niv pkgs.nixFlakes + pkgs.nixfmt + pkgs.nodePackages.pyright + pkgs.openssl + pkgs.pandoc + pkgs.pgcli + pkgs.prettyping + pkgs.procs + pkgs.procs + pkgs.ranger + pkgs.readline + pkgs.ripgrep + pkgs.rnix-lsp + pkgs.shellcheck + pkgs.stylua + pkgs.sumneko-lua-language-server + pkgs.tealdeer + pkgs.tig + pkgs.tokei + pkgs.tree + pkgs.universal-ctags + pkgs.vscodium + pkgs.wget + pkgs.xz + pkgs.yq ]; } diff --git a/overlays/sumneko-lua-language-server/default.nix b/overlays/sumneko-lua-language-server/default.nix new file mode 100644 index 0000000..6efa0bf --- /dev/null +++ b/overlays/sumneko-lua-language-server/default.nix @@ -0,0 +1,38 @@ +self: super: { + sumneko-lua-language-server = super.sumneko-lua-language-server.overrideAttrs ( + o: rec { + version = "2.2.3"; + + src = builtins.fetchurl { + url = "https://github.com/sumneko/vscode-lua/releases/download/v${version}/lua-${version}.vsix"; + sha256 = "16rpi6p7rslpdfi37ndy5g9qmvh22qljfk9w15kdrr668hfwp7nm"; + }; + + unpackPhase = '' + ${super.pkgs.unzip}/bin/unzip $src + ''; + + platform = if super.stdenv.isDarwin then "macOS" else "Linux"; + + preBuild = ""; + postBuild = ""; + nativeBuildInputs = [ + super.makeWrapper + ]; + + installPhase = '' + mkdir -p $out + cp -r extension $out/extras + chmod a+x $out/extras/server/bin/$platform/lua-language-server + makeWrapper $out/extras/server/bin/$platform/lua-language-server \ + $out/bin/lua-language-server \ + --add-flags "-E -e LANG=en $out/extras/server/main.lua \ + --logpath='~/.cache/sumneko_lua/log' \ + --metapath='~/.cache/sumneko_lua/meta'" + ''; + + meta.platforms = super.lib.platforms.all; + } + ); +} + diff --git a/programs/default.nix b/programs/default.nix index e087349..47ef687 100644 --- a/programs/default.nix +++ b/programs/default.nix @@ -1,4 +1,4 @@ [ ./git - ./neovim +# ./neovim ] diff --git a/programs/neovim/coc-settings.nix b/programs/neovim/coc-settings.nix deleted file mode 100644 index 358d3cf..0000000 --- a/programs/neovim/coc-settings.nix +++ /dev/null @@ -1,8 +0,0 @@ -{ - "languageserver" = { - "nix" = { - "command" = "rnix-lsp"; - "filetypes" = [ "nix" ]; - }; - }; -} diff --git a/programs/neovim/coc.vim b/programs/neovim/coc.vim deleted file mode 100644 index 1428def..0000000 --- a/programs/neovim/coc.vim +++ /dev/null @@ -1,138 +0,0 @@ -" START Configuration for coc.nvim -" -------------------------------- -" Better display for messages -set cmdheight=2 - -" You will have bad experience for diagnostic messages when it's default 4000. -set updatetime=300 - -" don't give |ins-completion-menu| messages. -set shortmess+=c - -" always show signcolumns -set signcolumn=yes - -" Use tab for trigger completion with characters ahead and navigate. -" Use command ':verbose imap ' to make sure tab is not mapped by other plugin. -inoremap - \ pumvisible() ? "\" : - \ check_back_space() ? "\" : - \ coc#refresh() -inoremap pumvisible() ? "\" : "\" - -function! s:check_back_space() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - -" Use to trigger completion. -inoremap coc#refresh() - -" Use to confirm completion, `u` means break undo chain at current position. -" Coc only does snippet and additional edit on confirm. -inoremap pumvisible() ? "\" : "\u\" -" Or use `complete_info` if your vim support it, like: -" inoremap complete_info()["selected"] != "-1" ? "\" : "\u\" - -" Use `[g` and `]g` to navigate diagnostics -nmap [g (coc-diagnostic-prev) -nmap ]g (coc-diagnostic-next) - -" Remap keys for gotos -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gi (coc-implementation) -nmap gr (coc-references) - -" Use K to show documentation in preview window -nnoremap K :call show_documentation() - -function! s:show_documentation() - if (index(['vim','help'], &filetype) >= 0) - execute 'h '.expand('') - else - call CocAction('doHover') - endif -endfunction - -" Highlight symbol under cursor on CursorHold -autocmd CursorHold * silent call CocActionAsync('highlight') - -" Remap for rename current word -nmap rn (coc-rename) - -" Remap for format selected region -xmap l (coc-format-selected) -nmap l (coc-format-selected) - -augroup mygroup - autocmd! - " Setup formatexpr specified filetype(s). - autocmd FileType typescript,json,scala setl formatexpr=CocAction('formatSelected') - " Update signature help on jump placeholder - autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp') -augroup end - -" Remap for do codeAction of selected region, ex: `aap` for current paragraph -xmap a (coc-codeaction-selected) -nmap a (coc-codeaction-selected) - -" Remap for do codeAction of current line -nmap ac (coc-codeaction) -" Fix autofix problem of current line -nmap qf (coc-fix-current) - -" Create mappings for function text object, requires document symbols feature of languageserver. -xmap if (coc-funcobj-i) -xmap af (coc-funcobj-a) -omap if (coc-funcobj-i) -omap af (coc-funcobj-a) - -" Use for select selections ranges, needs server support, like: coc-tsserver, coc-python -nmap (coc-range-select) -xmap (coc-range-select) - -" Use `:Format` to format current buffer -command! -nargs=0 Format :call CocAction('format') - -" Use `:Fold` to fold current buffer -command! -nargs=? Fold :call CocAction('fold', ) - -" use `:OR` for organize import of current buffer -command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport') - -" Using CocList -" Show all diagnostics -nnoremap a :CocList diagnostics -" Manage extensions -nnoremap e :CocList extensions -" Show commands -nnoremap c :CocList commands -" Find symbol of current document -nnoremap o :CocList outline -" Search workspace symbols -nnoremap s :CocList -I symbols -" Do default action for next item. -nnoremap j :CocNext -" Do default action for previous item. -nnoremap k :CocPrev -" Resume latest coc list -nnoremap p :CocListResume - -" Notify coc.nvim that has been pressed. -" Currently used for the formatOnType feature. -inoremap pumvisible() ? coc#_select_confirm() - \: "\u\\=coc#on_enter()\" - -" Toggle panel with Tree Views -nnoremap t :CocCommand metals.tvp -" Toggle Tree View 'metalsBuild' -nnoremap tb :CocCommand metals.tvp metalsBuild -" Toggle Tree View 'metalsCompile' -nnoremap tc :CocCommand metals.tvp metalsCompile -" Reveal current current class (trait or object) in Tree View 'metalsBuild' -nnoremap tf :CocCommand metals.revealInTreeView metalsBuild - -nmap ws (coc-metals-expand-decoration) - - diff --git a/programs/neovim/config.vim b/programs/neovim/config.vim deleted file mode 100644 index 884378d..0000000 --- a/programs/neovim/config.vim +++ /dev/null @@ -1,151 +0,0 @@ -set directory=$HOME/.vim/swapfiles/swap// -set undodir=~/.vim/swapfiles/undo// -set backupdir=~/.vim/swapfiles/backup// -" Make those folders automatically if they don't already exist. -if !isdirectory(expand(&undodir)) - call mkdir(expand(&undodir), "p") -endif -if !isdirectory(expand(&backupdir)) - call mkdir(expand(&backupdir), "p") -endif -if !isdirectory(expand(&directory)) - call mkdir(expand(&directory), "p") -endif -set t_Co=256 -set encoding=utf-8 -syntax on -set expandtab -set hidden -set showmatch -set colorcolumn=120 -set cursorcolumn -set cursorline -set cmdheight=2 -set smarttab -set linebreak -set hlsearch -set ignorecase -set incsearch -set guifont=SF\ Mono:h12 -set termguicolors -let g:clipboard = { - \ 'name': 'pbcopy', - \ 'copy': { - \ '+': 'pbcopy', - \ '*': 'pbcopy', - \ }, - \ 'paste': { - \ '+': 'pbpaste', - \ '*': 'pbpaste', - \ }, - \ 'cache_enabled': 0, - \ } -set clipboard=unnamed -let $NVIM_TUI_ENABLE_TRUE_COLOR=1 -let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1 -let g:seoul256_background = 233 -let g:seoul256_srgb = 1 -colorscheme seoul256 -set background=dark -set number -let g:netrw_banner=0 " disable annoying banner -let g:netrw_browse_split=4 " open in prior window -let g:netrw_altv=1 " open splits to the right -let g:netrw_liststyle=3 " tree view -let g:netrw_list_hide=netrw_gitignore#Hide() -let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+' -let g:netrw_list_hide= '.*\.pyc$' -au BufRead,BufNewFile *.sbt set filetype=scala -if executable("rg") - set grepprg=rg\ --vimgrep\ --no-heading - set grepformat=%f:%l:%c:%m,%f:%l:%m -endif -let g:ackprg='rg --vimgrep --no-heading' -set grepprg=rg\ --vimgrep -let g:rg_command = 'rg --vimgrep -S' -let mapleader = "\" -map! jj -" FZF -set rtp+=/Users/salar/.nix-profile/bin/fzf -imap (fzf-complete-line) -map b :Buffers -map f :Files -map g :GFiles -map y :Tags -autocmd! FileType fzf tnoremap q -nnoremap :FZF - -let g:rainbow_active = 1 -let g:rainbow_conf = { - \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'], - \ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'], - \ 'operators': '_,_', - \ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'], - \ 'separately': { - \ '*': {}, - \ 'tex': { - \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'], - \ }, - \ 'lisp': { - \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'], - \ }, - \ 'vim': { - \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'], - \ }, - \ 'html': { - \ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=## fold'], - \ }, - \ 'css': 0, - \ } - \} - let g:lightline = { - \ 'colorscheme': 'seoul256', - \ 'active': { - \ 'left': [ [ 'mode', 'paste' ], - \ [ 'gitbranch', 'readonly', 'filename', 'modified' ] ] - \ }, - \ 'component_function': { - \ 'gitbranch': 'FugitiveHead' - \ }, - \ } - -" Nerdtree Configuration -let NERDTreeIgnore=['\.pyc$', '\~$', 'target'] "ignore files in NERDTree -let NERDTreeRespectWildIgnore=1 -let NERDTreeQuitOnOpen=1 -map m :NERDTreeToggle -" jump back to nerdtree -map n :NERDTree -" reveal in side bar -map e :NERDTreeFind -let NERDTreeShowHidden=1 -"nerdtree-git-plugin -let g:NERDTreeGitStatusIndicatorMapCustom= { - \ "Modified" : "✹", - \ "Staged" : "✚", - \ "Untracked" : "✭", - \ "Renamed" : "➜", - \ "Unmerged" : "═", - \ "Deleted" : "✖", - \ "Dirty" : "✗", - \ "Clean" : "✔︎", - \ "Unknown" : "?" - \ } - -" Switch to previous buffer mapped to tab -function SwitchBuffer() - b# -endfunction - -nmap :call SwitchBuffer() - -" split-term -let g:split_term_default_shell = "fish" -let g:split_term_vertical = 1 - -let g:polyglot_disabled = ['markdown'] - -" vimwiki -let g:vimwiki_list = [{'path': '~/Documents/Notes/', - \ 'syntax': 'markdown', 'ext': '.md'}] - diff --git a/programs/neovim/custom-plugins.nix b/programs/neovim/custom-plugins.nix deleted file mode 100644 index e2001ff..0000000 --- a/programs/neovim/custom-plugins.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ buildVimPlugin }: - -{ - asyncrun-vim = buildVimPlugin { - name = "asyncrun-vim"; - src = builtins.fetchTarball { - name = "AsyncRun-Vim-v2.7.5"; - url = "https://github.com/skywind3000/asyncrun.vim/archive/2.7.5.tar.gz"; - sha256 = "02fiqf4rcrxbcgvj02mpd78wkxsrnbi54aciwh9fv5mnz5ka249m"; - }; - }; -} diff --git a/programs/neovim/default.nix b/programs/neovim/default.nix deleted file mode 100644 index 8e074cf..0000000 --- a/programs/neovim/default.nix +++ /dev/null @@ -1,58 +0,0 @@ -{ config, lib, pkgs, ... }: - -let - custom-plugins = pkgs.callPackage ./custom-plugins.nix { - inherit (pkgs.vimUtils) buildVimPlugin; - }; - - plugins = pkgs.vimPlugins // custom-plugins; - - overriddenPlugins = with pkgs; []; - - myVimPlugins = with plugins; [ - asyncrun-vim - ack-vim - coc-nvim - coc-java - coc-json - coc-metals - coc-pairs - coc-python - coc-tabnine - fzf-vim - git-messenger-vim - lightline-vim - nerdtree - nerdtree-git-plugin - rainbow - seoul256-vim - split-term-vim - vim-fugitive - vim-gitgutter - vim-polyglot - vimwiki - ] ++ overriddenPlugins; - - baseConfig = builtins.readFile ./config.vim; - cocConfig = builtins.readFile ./coc.vim; - cocSettings = builtins.toJSON (import ./coc-settings.nix); - vimConfig = baseConfig + cocConfig; - -in -{ - programs.neovim = { - enable = true; - extraConfig = vimConfig; - plugins = myVimPlugins; - viAlias = true; - vimAlias = true; - vimdiffAlias = true; - withNodeJs = true; # for coc.nvim - withPython3 = true; # for plugins - }; - - xdg.configFile = { - "nvim/coc-settings.json".text = cocSettings; - }; -} - diff --git a/programs/neovim/init.lua b/programs/neovim/init.lua new file mode 100644 index 0000000..e4d66b7 --- /dev/null +++ b/programs/neovim/init.lua @@ -0,0 +1,437 @@ +local fn = vim.fn + +local install_path = fn.stdpath 'data' .. '/site/pack/packer/start/packer.nvim' + +local function load_plugins() + local use = require('packer').use + require('packer').startup(function() + use 'wbthomason/packer.nvim' -- Package manager + use 'neovim/nvim-lspconfig' -- Collection of configurations for built-in LSP client + use 'nvim-treesitter/nvim-treesitter' + use 'nvim-treesitter/nvim-treesitter-textobjects' + use 'nvim-treesitter/playground' + use 'folke/which-key.nvim' + use 'folke/lua-dev.nvim' + use 'folke/tokyonight.nvim' -- Theme + use { 'folke/trouble.nvim', requires = 'kyazdani42/nvim-web-devicons' } + use { 'nvim-telescope/telescope.nvim', requires = { { 'nvim-lua/popup.nvim' }, { 'nvim-lua/plenary.nvim' } } } + use 'windwp/nvim-autopairs' -- Autopairs + use 'kyazdani42/nvim-tree.lua' -- File explorer + use { + 'glepnir/galaxyline.nvim', + config = function() + require 'salargalaxyline' + end, + requires = 'kyazdani42/nvim-web-devicons', + } + use 'lukas-reineke/indent-blankline.nvim' + use { 'lewis6991/gitsigns.nvim', requires = 'nvim-lua/plenary.nvim' } + use { 'TimUntersberger/neogit', requires = { { 'nvim-lua/plenary.nvim' }, { 'sindrets/diffview.nvim' } } } + use { 'hrsh7th/nvim-compe', requires = 'L3MON4D3/LuaSnip' } -- Autocompletion plugin + use 'kevinhwang91/nvim-bqf' + use 'mfussenegger/nvim-dap' + use 'sheerun/vim-polyglot' + use 'scalameta/nvim-metals' + use 'ray-x/lsp_signature.nvim' + use 'b3nj5m1n/kommentary' + use 'ckipp01/stylua-nvim' + use 'gennaro-tedesco/nvim-jqx' + use 'kristijanhusak/orgmode.nvim' + use 'p00f/nvim-ts-rainbow' + end) +end + +_G.load_config = function() + require('gitsigns').setup() + require('kommentary.config').use_extended_mappings() + require('nvim-autopairs').setup() + require 'salargalaxyline' + require('trouble').setup() + require('which-key').setup() + + local luadev = require('lua-dev').setup() + + -- orgmode.nvim + require('orgmode').setup({ + org_agenda_files = {'~/Documents/org'}, + org_default_notes_file = '~/Documents/org/notes.org' + }) + + -- Treesitter + require('nvim-treesitter.configs').setup { + query_linter = { + enable = true, + use_virtual_text = true, + lint_events = { 'BufWrite', 'CursorHold' }, + }, + ensure_installed = 'maintained', + highlight = { enable = true }, + incremental_selection = { + enable = true, + keymaps = { + init_selection = 'gnn', + node_incremental = 'grn', + scope_incremental = 'grc', + node_decremental = 'grm', + }, + }, + indent = { + enable = true, + }, + textobjects = { + select = { + enable = true, + lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['ac'] = '@class.outer', + ['ic'] = '@class.inner', + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + [']m'] = '@function.outer', + [']]'] = '@class.outer', + }, + goto_next_end = { + [']M'] = '@function.outer', + [']['] = '@class.outer', + }, + goto_previous_start = { + ['[m'] = '@function.outer', + ['[['] = '@class.outer', + }, + goto_previous_end = { + ['[M'] = '@function.outer', + ['[]'] = '@class.outer', + }, + }, + }, + playground = { + enable = true, + disable = {}, + updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code + persist_queries = false, -- Whether the query persists across vim sessions + keybindings = { + toggle_query_editor = 'o', + toggle_hl_groups = 'i', + toggle_injected_languages = 't', + toggle_anonymous_nodes = 'a', + toggle_language_display = 'I', + focus_language = 'f', + unfocus_language = 'F', + update = 'R', + goto_node = '', + show_help = '?', + }, + }, + rainbow = { + enable = true, + extended_mode = true, + max_file_lines = 1000, + }, + } + + -- neogit + require('neogit').setup { + integrations = { + diffview = true, + }, + } + + --Incremental live completion + vim.o.inccommand = 'nosplit' + + --Set highlight on search + vim.o.hlsearch = false + vim.o.incsearch = true + + --Make line numbers default + vim.wo.number = true + + --Do not save when switching buffers + vim.o.hidden = true + + --Enable mouse mode + vim.o.mouse = 'a' + + -- clipboard + vim.o.clipboard = 'unnamedplus' + + --Enable break indent + vim.o.breakindent = true + + --Save undo history + vim.cmd [[set undofile]] + + --Case insensitive searching UNLESS /C or capital in search + vim.o.ignorecase = true + vim.o.smartcase = true + + --Decrease update time + vim.o.updatetime = 250 + vim.wo.signcolumn = 'yes' + + --Set colorscheme (order is important here) + vim.g.tokyonight_style = 'night' + vim.g.tokyonight_italic_functions = true + vim.o.termguicolors = true + vim.cmd [[colorscheme tokyonight]] + + --Remap space as leader key + vim.api.nvim_set_keymap('', '', '', { noremap = true, silent = true }) + vim.g.mapleader = ' ' + vim.g.maplocalleader = ' ' + + --Remap for dealing with word wrap + vim.api.nvim_set_keymap('n', 'k', "v:count == 0 ? 'gk' : 'k'", { noremap = true, expr = true, silent = true }) + vim.api.nvim_set_keymap('n', 'j', "v:count == 0 ? 'gj' : 'j'", { noremap = true, expr = true, silent = true }) + + --Remap escape to leave terminal mode + vim.api.nvim_set_keymap('t', '', [[]], { noremap = true }) + + --Add map to enter paste mode + vim.o.pastetoggle = '' + + --Map blankline + vim.g.indent_blankline_char = '┊' + vim.g.indent_blankline_filetype_exclude = { 'help', 'packer' } + vim.g.indent_blankline_buftype_exclude = { 'terminal', 'nofile' } + vim.g.indent_blankline_char_highlight = 'LineNr' + + -- Toggle to disable mouse mode and indentlines for easier paste + ToggleMouse = function() + if vim.o.mouse == 'a' then + vim.cmd [[IndentBlanklineDisable]] + vim.wo.signcolumn = 'no' + vim.o.mouse = 'v' + vim.wo.number = false + print 'Mouse disabled' + else + vim.cmd [[IndentBlanklineEnable]] + vim.wo.signcolumn = 'yes' + vim.o.mouse = 'a' + vim.wo.number = true + print 'Mouse enabled' + end + end + + vim.api.nvim_set_keymap('n', '', 'lua ToggleMouse()', { noremap = true }) + + -- Telescope + require('telescope').setup { + defaults = { + mappings = { + i = { + [''] = false, + [''] = false, + }, + }, + generic_sorter = require('telescope.sorters').get_fzy_sorter, + file_sorter = require('telescope.sorters').get_fzy_sorter, + }, + } + --Add leader shortcuts + vim.api.nvim_set_keymap('n', 'f', [[lua require('telescope.builtin').find_files()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', '', [[lua require('telescope.builtin').buffers()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'l', [[lua require('telescope.builtin').current_buffer_fuzzy_find()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 't', [[lua require('telescope.builtin').tags()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', '?', [[lua require('telescope.builtin').oldfiles()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'sd', [[lua require('telescope.builtin').grep_string()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'sp', [[lua require('telescope.builtin').live_grep()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'o', [[lua require('telescope.builtin').tags{ only_current_buffer = true }]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'gc', [[lua require('telescope.builtin').git_commits()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'gb', [[lua require('telescope.builtin').git_branches()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'gs', [[lua require('telescope.builtin').git_status()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'gp', [[lua require('telescope.builtin').git_bcommits()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'm', [[lua require('nvim-tree').toggle()]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'ng', [[lua require('neogit').open({ kind = "split" })]], { noremap = true, silent = true }) + vim.api.nvim_set_keymap('n', 'nu', ':PackerUpdate', { noremap = true, silent = true }) + + -- Change preview window location + vim.g.splitbelow = true + + -- Highlight on yank + vim.api.nvim_exec( + [[ + augroup YankHighlight + autocmd! + autocmd TextYankPost * silent! lua vim.highlight.on_yank() + augroup end + ]], + false + ) + + -- Y yank until the end of line + vim.api.nvim_set_keymap('n', 'Y', 'y$', { noremap = true }) + -- + -- LSP settings + local nvim_lsp = require 'lspconfig' + local on_attach = function(_client, bufnr) + require('lsp_signature').on_attach() + + vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc') + + local opts = { noremap = true, silent = true } + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gm', 'lua vim.lsp.buf.implementation()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', '', 'lua vim.lsp.buf.signature_help()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'D', 'lua vim.lsp.buf.type_definition()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'rn', 'lua vim.lsp.buf.rename()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ca', 'lua vim.lsp.buf.code_action()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'e', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) + vim.api.nvim_buf_set_keymap(bufnr, 'n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) + end + + -- Enable the following language servers + local servers = { 'jdtls', 'pyright', 'rnix', 'sourcekit' } + for _, lsp in ipairs(servers) do + nvim_lsp[lsp].setup { on_attach = on_attach } + end + + -- lua language server + local sumneko_binary = vim.fn.getenv 'HOME' .. '/.nix-profile/bin/lua-language-server' + local runtime_path = vim.split(package.path, ';') + table.insert(runtime_path, 'lua/?.lua') + table.insert(runtime_path, 'lua/?/init.lua') + + require('lspconfig').sumneko_lua.setup { + cmd = { sumneko_binary }, + commands = { + Format = { + function() + require('stylua-nvim').format_file() + end, + }, + }, + on_attach = on_attach, + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = 'LuaJIT', + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { 'vim' }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = { + vim.api.nvim_get_runtime_file('', true), + luadev, + }, + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, + } + + -- metals + vim.opt_global.shortmess:remove('F'):append 'c' + Metals_config = require('metals').bare_config + Metals_config.init_options.statusBarProvider = 'on' + vim.cmd [[augroup lsp]] + vim.cmd [[au!]] + vim.cmd [[au FileType scala,sbt lua require("metals").initialize_or_attach(metals_config)]] + vim.cmd [[augroup end]] + + -- Map :Format to vim.lsp.buf.formatting() + vim.cmd [[ command! Format execute 'lua vim.lsp.buf.formatting()' ]] + + -- Set completeopt to have a better completion experience + vim.o.completeopt = 'menuone,noinsert' + + -- Compe setup + require('compe').setup { + enabled = true, + autocomplete = true, + debug = false, + min_length = 1, + preselect = 'enable', + throttle_time = 80, + source_timeout = 200, + incomplete_delay = 400, + max_abbr_width = 100, + max_kind_width = 100, + max_menu_width = 100, + documentation = true, + + source = { + path = true, + nvim_lsp = { + priority = 1000, + filetypes = { 'scala', 'sbt', 'java', 'python' }, + }, + nvim_lua = true, + buffer = true, + luasnip = true, + orgmode = true, + }, + } + + local t = function(str) + return vim.api.nvim_replace_termcodes(str, true, true, true) + end + + local check_back_space = function() + local col = vim.fn.col '.' - 1 + if col == 0 or vim.fn.getline('.'):sub(col, col):match '%s' then + return true + else + return false + end + end + + -- Use (s-)tab to: + --- move to prev/next item in completion menuone + --- jump to prev/next snippet's placeholder + _G.tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t '' + elseif check_back_space() then + return t '' + else + return vim.fn['compe#complete']() + end + end + _G.s_tab_complete = function() + if vim.fn.pumvisible() == 1 then + return t '' + else + return t '' + end + end + + vim.api.nvim_set_keymap('i', '', 'v:lua.tab_complete()', { expr = true }) + vim.api.nvim_set_keymap('s', '', 'v:lua.tab_complete()', { expr = true }) + vim.api.nvim_set_keymap('i', '', 'v:lua.s_tab_complete()', { expr = true }) + vim.api.nvim_set_keymap('s', '', 'v:lua.s_tab_complete()', { expr = true }) +end + +if fn.isdirectory(install_path) == 0 then + fn.system { 'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path } + load_plugins() + require('packer').sync() + vim.cmd 'autocmd User PackerComplete ++once lua load_config()' +else + load_plugins() + _G.load_config() +end diff --git a/programs/neovim/settings/salargalaxyline.lua b/programs/neovim/settings/salargalaxyline.lua new file mode 100644 index 0000000..1903b73 --- /dev/null +++ b/programs/neovim/settings/salargalaxyline.lua @@ -0,0 +1,197 @@ +local gl = require 'galaxyline' +local gls = gl.section +gl.short_line_list = { 'LuaTree', 'vista', 'dbui' } + +local colors = { + bg = '#282c34', + yellow = '#fabd2f', + cyan = '#008080', + darkblue = '#081633', + green = '#afd700', + orange = '#FF8800', + purple = '#5d4d7a', + magenta = '#d16d9e', + grey = '#c0c0c0', + blue = '#0087d7', + red = '#ec5f67', +} + +local buffer_not_empty = function() + if vim.fn.empty(vim.fn.expand '%:t') ~= 1 then + return true + end + return false +end + +gls.left[1] = { + FirstElement = { + provider = function() + return '▋' + end, + highlight = { colors.blue, colors.yellow }, + }, +} +gls.left[2] = { + ViMode = { + provider = function() + local alias = { n = 'NORMAL', i = 'INSERT', c = 'COMMAND', v = 'VISUAL', V = 'VISUAL LINE', [''] = 'VISUAL BLOCK' } + return alias[vim.fn.mode()] + end, + separator = '', + separator_highlight = { + colors.purple, + function() + if not buffer_not_empty() then + return colors.purple + end + return colors.darkblue + end, + }, + highlight = { colors.darkblue, colors.purple, 'bold' }, + }, +} +gls.left[3] = { + FileIcon = { + provider = 'FileIcon', + condition = buffer_not_empty, + highlight = { require('galaxyline.provider_fileinfo').get_file_icon_color, colors.darkblue }, + }, +} +gls.left[4] = { + FileName = { + provider = { 'FileName', 'FileSize' }, + condition = buffer_not_empty, + separator = '', + separator_highlight = { colors.purple, colors.darkblue }, + highlight = { colors.magenta, colors.darkblue }, + }, +} + +gls.left[5] = { + GitIcon = { + provider = function() + return '  ' + end, + condition = buffer_not_empty, + highlight = { colors.orange, colors.purple }, + }, +} +gls.left[6] = { + GitBranch = { + provider = 'GitBranch', + condition = buffer_not_empty, + highlight = { colors.grey, colors.purple }, + }, +} + +local checkwidth = function() + local squeeze_width = vim.fn.winwidth(0) / 2 + if squeeze_width > 40 then + return true + end + return false +end + +gls.left[7] = { + DiffAdd = { + provider = 'DiffAdd', + condition = checkwidth, + icon = ' ', + highlight = { colors.green, colors.purple }, + }, +} +gls.left[8] = { + DiffModified = { + provider = 'DiffModified', + condition = checkwidth, + icon = ' ', + highlight = { colors.orange, colors.purple }, + }, +} +gls.left[9] = { + DiffRemove = { + provider = 'DiffRemove', + condition = checkwidth, + icon = ' ', + highlight = { colors.red, colors.purple }, + }, +} +gls.left[10] = { + LeftEnd = { + provider = function() + return '' + end, + separator = '', + separator_highlight = { colors.purple, colors.bg }, + highlight = { colors.purple, colors.purple }, + }, +} +gls.left[11] = { + DiagnosticError = { + provider = 'DiagnosticError', + icon = '  ', + highlight = { colors.red, colors.bg }, + }, +} +gls.left[12] = { + Space = { + provider = function() + return ' ' + end, + }, +} +gls.left[13] = { + DiagnosticWarn = { + provider = 'DiagnosticWarn', + icon = '  ', + highlight = { colors.blue, colors.bg }, + }, +} +gls.right[1] = { + FileFormat = { + provider = 'FileFormat', + separator = '', + separator_highlight = { colors.bg, colors.purple }, + highlight = { colors.grey, colors.purple }, + }, +} +gls.right[2] = { + LineInfo = { + provider = 'LineColumn', + separator = ' | ', + separator_highlight = { colors.darkblue, colors.purple }, + highlight = { colors.grey, colors.purple }, + }, +} +gls.right[3] = { + PerCent = { + provider = 'LinePercent', + separator = '', + separator_highlight = { colors.darkblue, colors.purple }, + highlight = { colors.grey, colors.darkblue }, + }, +} +gls.right[4] = { + ScrollBar = { + provider = 'ScrollBar', + highlight = { colors.yellow, colors.purple }, + }, +} + +gls.short_line_left[1] = { + BufferType = { + provider = 'FileTypeName', + separator = '', + separator_highlight = { colors.purple, colors.bg }, + highlight = { colors.grey, colors.purple }, + }, +} + +gls.short_line_right[1] = { + BufferIcon = { + provider = 'BufferIcon', + separator = '', + separator_highlight = { colors.purple, colors.bg }, + highlight = { colors.grey, colors.purple }, + }, +}