~damien/dotfiles

049aeef81ba7ae64df3f82b06a6690f8e9ad97ed — Damien Radtke 15 days ago 6f4da80 master
Small vim improvements
3 files changed, 87 insertions(+), 65 deletions(-)

M .gitignore
M vim/.config/nvim/init.vim
M vim/.vimrc
M .gitignore => .gitignore +1 -0
@@ 1,1 1,2 @@
.*.swp
Session.vim

M vim/.config/nvim/init.vim => vim/.config/nvim/init.vim +78 -63
@@ 3,90 3,105 @@ let &packpath=&runtimepath
source ~/.vimrc

if has('nvim-0.5')
  " Inspired by https://github.com/neovim/nvim-lspconfig/#keybindings-and-completion,
  " but with <leader> instead of <space>
	" Inspired by https://github.com/neovim/nvim-lspconfig/#keybindings-and-completion,
	" but with <leader> instead of <space>
lua << EOF
local nvim_lsp = require('lspconfig')
local on_attach = function(client, bufnr)
  local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
  local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
	local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
	local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end

  buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
	buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

  -- Mappings.
  local opts = { noremap=true, silent=true }
  buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
  buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
  buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
  buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
  buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
  buf_set_keymap('n', '<Leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
  buf_set_keymap('n', '<Leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
  buf_set_keymap('n', '<Leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
  buf_set_keymap('n', '<Leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
  buf_set_keymap('n', '<Leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
  buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
  buf_set_keymap('n', '<Leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
  buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
  buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
  buf_set_keymap('n', '<Leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
  buf_set_keymap('n', '<Leader>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
	-- Mappings.
	local opts = { noremap=true, silent=true }
	buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
	buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
	buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
	buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
	buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
	buf_set_keymap('n', '<Leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
	buf_set_keymap('n', '<Leader>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
	buf_set_keymap('n', '<Leader>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
	buf_set_keymap('n', '<Leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
	buf_set_keymap('n', '<Leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
	buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
	buf_set_keymap('n', '<Leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
	buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
	buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
	buf_set_keymap('n', '<Leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
	buf_set_keymap('n', '<Leader>ca', '<cmd>lua require("telescope.builtin").lsp_code_actions{}<CR>', opts)

  -- Set some keybinds conditional on server capabilities
  if client.resolved_capabilities.document_formatting then
    buf_set_keymap("n", "<Leader>df", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
  elseif client.resolved_capabilities.document_range_formatting then
    buf_set_keymap("n", "<Leader>df", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
  end
	-- Set some keybinds conditional on server capabilities
	if client.resolved_capabilities.document_formatting then
		buf_set_keymap('n', '<Leader>df', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
	elseif client.resolved_capabilities.document_range_formatting then
		buf_set_keymap('n', '<Leader>df', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
	end

  -- Set autocommands conditional on server_capabilities
  if client.resolved_capabilities.document_highlight then
    vim.api.nvim_exec([[
      hi LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow
      hi LspReferenceText cterm=bold ctermbg=red guibg=LightYellow
      hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow
      augroup lsp_document_highlight
        autocmd!
        autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
        autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
      augroup END
    ]], false)
  end
	-- Set autocommands conditional on server_capabilities
	-- if client.resolved_capabilities.document_highlight then
	--	 vim.api.nvim_exec([[
	--		 hi LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow
	--		 hi LspReferenceText cterm=bold ctermbg=red guibg=LightYellow
	--		 hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow
	--		 augroup lsp_document_highlight
	--			 autocmd!
	--			 autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
	--			 autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
	--		 augroup END
	--	 ]], false)
	-- end
end

nvim_lsp.jdtls.setup{
  cmd = { "java-language-server", "--heap-max", "8G" };
  init_options = {
    bundles = {vim.env.HOME.."/language-servers/java/extensions/debug.jar"};
  };
  on_attach = on_attach;
	cmd = { 'java-language-server', '--heap-max', '8G' };
	init_options = {
		bundles = {vim.env.HOME..'/language-servers/java/extensions/debug.jar'};
	};
	on_attach = on_attach;
}

nvim_lsp.gopls.setup{
  on_attach = on_attach;
	on_attach = on_attach;
}

-- Use fzf for native LSP selection requests, i.e. code actions
require('fzf_lsp').setup()
if not nvim_lsp.lemminx then
	require('lspconfig/configs').lemminx = {
		default_config = {
			cmd = { 'xml-language-server' },
			filetypes = { 'xml' },
			root_dir = require('lspconfig/util').root_pattern('.git'),
		}
	};
end
nvim_lsp.lemminx.setup{
	on_attach = on_attach;
}

nvim_lsp.ccls.setup{
	on_attach = on_attach;
};

local status, treesitter = pcall(require, 'nvim-treesitter.configs')
if status then
  treesitter.setup{
    ensure_installed = "maintained",
    highlight = {
      enable = true
    },
    indent = {
      enable = true
    },
  }
	treesitter.setup{
		ensure_installed = 'maintained',
		highlight = {
			enable = true
		},
		indent = {
			enable = true,
			disable = { "zig" },
		},
	}
end

require('telescope').setup{
  defaults = {
    prompt_position = "top",
    sorting_strategy = "ascending",
  }
	defaults = {
		prompt_position = 'top',
		sorting_strategy = 'ascending',
	}
}
EOF


M vim/.vimrc => vim/.vimrc +8 -2
@@ 8,15 8,16 @@ Plug 'junegunn/fzf.vim'
Plug 'rust-lang/rust.vim'
Plug 'scrooloose/nerdtree'
Plug 'thomd/vim-wasabi-colorscheme'
Plug 'mhartington/oceanic-next'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-sensible'
Plug 'jvirtanen/vim-hcl'
Plug 'ziglang/zig.vim'
if has('nvim')
	Plug 'nvim-lua/popup.nvim'
	Plug 'nvim-lua/plenary.nvim'
endif
if has('nvim-0.5')
	Plug 'gfanto/fzf-lsp.nvim'
	Plug 'neovim/nvim-lspconfig'
	Plug 'nvim-telescope/telescope.nvim'
	Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}


@@ 40,8 41,13 @@ au FileType go command! Imports call s:go_imports()
au FileType html setlocal expandtab tabstop=2 shiftwidth=2
au FileType json setlocal expandtab tabstop=2 shiftwidth=2
au FileType javascript setlocal expandtab tabstop=4 shiftwidth=4
au BufNewFile,BufRead *.xaml set filetype=xml

silent! colorscheme wasabi256
if has('nvim-0.5')
	silent! colorscheme OceanicNext
else
	silent! colorscheme wasabi256
endif
highlight! link NonText NONE

function! s:set_make_go() abort