rust-analyzer key bindings for neovim

master
Jordan Orelli 1 year ago
parent 0de916d700
commit 5c906df1d5

@ -24,3 +24,4 @@ let g:terminal_color_15 = '#ffffff'
lua require('term')
lua require('git')
lua require('lsp')

@ -0,0 +1,43 @@
local lspconfig = require('lspconfig')
-- global configurations
-- vim.api.nvim_set_keymap("n", "<F2>", vim.diagnostic.open_float, {noremap = true, silent = false })
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float)
-- rust-specific configurations
-- lspconfig.rust_analyzer.setup {
-- settings = {
-- ['rust-analyzer'] = {},
-- },
-- }
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
callback = function(ev)
-- Enable completion triggered by <c-x><c-o>
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
-- Buffer local mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
local opts = { buffer = ev.buf }
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
vim.keymap.set('n', '<space>wl', function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, opts)
-- vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
vim.keymap.set('n', '<F2>', vim.lsp.buf.rename, opts)
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action, opts)
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format { async = true }
end, opts)
end,
})

@ -14,14 +14,15 @@ end
-- if you only want these mappings for toggle term use term://*toggleterm#* instead
vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()')
local shell = Terminal:new({
function shell(direction)
Terminal:new({
dir = vim.fn.expand('%p'),
direction = "float",
direction = direction,
hidden = true,
})
function _shell_toggle()
shell:toggle()
end
vim.api.nvim_set_keymap("n", "<F1>", "<cmd>lua _shell_toggle()<CR>", {noremap = true, silent = true})
-- This shit didn't work, I dunno what I was trying to do here:
-- vim.api.nvim_set_keymap("n", "<F1>", "<cmd>lua shell('float')()<CR>", {noremap = true, silent = true})
-- vim.api.nvim_set_keymap("n", "<F2>", "<cmd>lua shell('below')()<CR>", {noremap = true, silent = true})
-- vim.api.nvim_set_keymap("n", "<F3>", "<cmd>lua shell('vertical')()<CR>", {noremap = true, silent = true})

@ -131,6 +131,9 @@ set hlsearch
" press escape twice to clear highlight search
nnoremap <silent> <Esc><Esc> <Esc>:nohlsearch<CR><Esc>
" press ctrl+L to clear highlight search
nnoremap <C-l> :nohlsearch<CR>
nnoremap <C-L> :nohlsearch<CR>
" ---------------------------------------------------------------------------}}}
" Backup --------------------------------------------------------------------{{{
@ -539,8 +542,8 @@ let g:NERDDefaultAlign='left'
" insert a space after comment markers
let g:NERDSpaceDelims=1
vmap K <Plug>NERDCommenterToggle('n', 'Toggle')<Cr>
nmap KK <Plug>NERDCommenterToggle('n', 'Toggle')<Cr>
" vmap K <Plug>NERDCommenterToggle('n', 'Toggle')<Cr>
" nmap KK <Plug>NERDCommenterToggle('n', 'Toggle')<Cr>
" ---------------------------------------------------------------------------}}}
" Misc ----------------------------------------------------------------------{{{

Loading…
Cancel
Save