Merge pull request #11 from jaydamani/main
Added keybinds and some more stuff (bufferline changes , tab completion )
This commit is contained in:
commit
42fe8583a9
|
@ -57,6 +57,11 @@ local opt = {silent = true}
|
||||||
|
|
||||||
vim.g.mapleader = " "
|
vim.g.mapleader = " "
|
||||||
|
|
||||||
|
--command that adds new buffer and moves to it
|
||||||
|
vim.api.nvim_command "com -nargs=? -complete=file_in_path New badd <args> | blast"
|
||||||
|
vim.api.nvim_set_keymap("n","<S-b>",":New ", opt)
|
||||||
|
--removing a buffer
|
||||||
|
vim.api.nvim_set_keymap("n","<S-f>",[[<Cmd>bdelete<CR>]], opt)
|
||||||
-- tabnew and tabprev
|
-- tabnew and tabprev
|
||||||
vim.api.nvim_set_keymap("n", "<Leader>tn", [[<Cmd>BufferLineCycleNext<CR>]], opt)
|
vim.api.nvim_set_keymap("n", "<S-l>", [[<Cmd>BufferLineCycleNext<CR>]], opt)
|
||||||
vim.api.nvim_set_keymap("n", "<Leader>tp", [[<Cmd>BufferLineCyclePrev<CR>]], opt)
|
vim.api.nvim_set_keymap("n", "<S-s>", [[<Cmd>BufferLineCyclePrev<CR>]], opt)
|
||||||
|
|
|
@ -33,6 +33,26 @@ require "compe".setup {
|
||||||
local t = function(str)
|
local t = function(str)
|
||||||
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
||||||
end
|
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
|
||||||
|
|
||||||
|
|
||||||
|
_G.tab_complete = function()
|
||||||
|
if vim.fn.pumvisible() == 1 then
|
||||||
|
return t "<C-n>"
|
||||||
|
elseif check_back_space() then
|
||||||
|
return t "<Tab>"
|
||||||
|
else
|
||||||
|
return vim.fn['compe#complete']()
|
||||||
|
end
|
||||||
|
end
|
||||||
_G.s_tab_complete = function()
|
_G.s_tab_complete = function()
|
||||||
if vim.fn.pumvisible() == 1 then
|
if vim.fn.pumvisible() == 1 then
|
||||||
return t "<C-p>"
|
return t "<C-p>"
|
||||||
|
@ -45,6 +65,7 @@ end
|
||||||
|
|
||||||
-- mappings
|
-- mappings
|
||||||
|
|
||||||
|
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||||
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||||
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
||||||
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
||||||
|
|
|
@ -1,35 +1,42 @@
|
||||||
vim.cmd [[packadd nvim-lspconfig]]
|
vim.cmd [[packadd nvim-lspconfig]]
|
||||||
vim.cmd [[packadd nvim-compe]]
|
vim.cmd [[packadd nvim-compe]]
|
||||||
|
local nvim_lsp = require('lspconfig')
|
||||||
|
function on_attach(client)
|
||||||
|
|
||||||
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")
|
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')
|
||||||
|
|
||||||
-- Mappings.
|
-- Mappings.
|
||||||
local opts = { noremap=true, silent=true }
|
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.declaration()<CR>', opts)
|
||||||
buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<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', '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', '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', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||||||
buf_set_keymap("n", "<space>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts)
|
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
|
||||||
buf_set_keymap("n", "<space>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
|
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
|
||||||
buf_set_keymap("n", "<space>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts)
|
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
|
||||||
buf_set_keymap("n", "<space>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
|
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
||||||
buf_set_keymap("n", "<space>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
|
buf_set_keymap('n', '<space>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', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
|
||||||
buf_set_keymap("n", "<space>e", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts)
|
buf_set_keymap('n', '<space>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_prev()<CR>', opts)
|
||||||
buf_set_keymap("n", "]d", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
|
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
||||||
buf_set_keymap("n", "<space>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
|
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
|
||||||
|
|
||||||
-- lsp for html , css and js/ts
|
-- Set some keybinds conditional on server capabilities
|
||||||
require "lspconfig".tsserver.setup {}
|
if client.resolved_capabilities.document_formatting then
|
||||||
require "lspconfig".cssls.setup {}
|
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
|
||||||
require "lspconfig".html.setup {}
|
elseif client.resolved_capabilities.document_range_formatting then
|
||||||
require "lspconfig".pyls.setup {}
|
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
local servers = { "tsserver", "cssls", "pyls", "html" }
|
||||||
|
for _, lsp in ipairs(servers) do
|
||||||
|
nvim_lsp[lsp].setup { on_attach = on_attach }
|
||||||
|
end
|
Loading…
Reference in New Issue