Updated config
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
local on = vim.api.nvim_create_autocmd
|
||||
local group = vim.api.nvim_create_augroup("autocmds", {clear = true})
|
||||
|
||||
on({ "BufNewFile", "BufRead" }, {
|
||||
desc = "Enable word wrap in text files and markdown documents",
|
||||
group = group,
|
||||
pattern = { "*.txt", "*.md" },
|
||||
callback = function()
|
||||
vim.opt_local.wrap = true
|
||||
@ -9,6 +12,8 @@ on({ "BufNewFile", "BufRead" }, {
|
||||
})
|
||||
|
||||
on({ "TermOpen", "TermEnter" }, {
|
||||
desc = "Disable sign column in terminals",
|
||||
group = group,
|
||||
callback = function()
|
||||
vim.opt_local.signcolumn = "no"
|
||||
end,
|
||||
@ -16,35 +21,42 @@ on({ "TermOpen", "TermEnter" }, {
|
||||
|
||||
on({ "TextYankPost" }, {
|
||||
desc = "Highlight when copying text",
|
||||
group = vim.api.nvim_create_augroup("highlight-yank", { clear = true }),
|
||||
group = group,
|
||||
callback = function()
|
||||
vim.highlight.on_yank()
|
||||
end,
|
||||
})
|
||||
|
||||
on({ "VimEnter" }, {
|
||||
desc = "Allow opening a directory and jumping to project root",
|
||||
group = group,
|
||||
callback = function()
|
||||
-- Change file to its directory if needed
|
||||
local file = vim.api.nvim_buf_get_name(0)
|
||||
local name = vim.api.nvim_buf_get_name(0)
|
||||
|
||||
if vim.fn.isdirectory(file) == 0 then
|
||||
file = vim.fs.dirname(file)
|
||||
if vim.fn.isdirectory(name) == 0 then
|
||||
name = vim.fs.dirname(name)
|
||||
end
|
||||
|
||||
-- Switch to root directory of the project
|
||||
local root_patterns = { ".git", "go.mod", "init.lua" }
|
||||
local root_dir = vim.fs.dirname(vim.fs.find(root_patterns, {
|
||||
upward = true,
|
||||
path = file,
|
||||
path = name,
|
||||
})[1])
|
||||
|
||||
if root_dir then
|
||||
vim.api.nvim_set_current_dir(root_dir)
|
||||
else
|
||||
vim.api.nvim_set_current_dir(file)
|
||||
vim.api.nvim_set_current_dir(name)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- Open file explorer if we have enough space
|
||||
on({ "VimEnter" }, {
|
||||
desc = "Open file explorer if there is enough horizontal space",
|
||||
group = group,
|
||||
callback = function()
|
||||
local files = require("nvim-tree.api")
|
||||
local width = vim.go.columns
|
||||
|
||||
|
@ -45,55 +45,55 @@ return {
|
||||
"hrsh7th/nvim-cmp",
|
||||
event = "InsertEnter",
|
||||
dependencies = {
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
-- "hrsh7th/cmp-nvim-lsp",
|
||||
-- "hrsh7th/cmp-buffer",
|
||||
-- "hrsh7th/cmp-path",
|
||||
-- "L3MON4D3/LuaSnip",
|
||||
},
|
||||
config = function()
|
||||
opts = {
|
||||
completion = {
|
||||
autocomplete = true,
|
||||
completeopt = "menu,menuone,noinsert",
|
||||
},
|
||||
formatting = {
|
||||
fields = { "abbr", "kind", "menu" },
|
||||
format = function(_, item)
|
||||
local icon = icons[item.kind] or ""
|
||||
item.kind = string.format(" %s %s", icon, item.kind)
|
||||
return item
|
||||
end,
|
||||
},
|
||||
-- snippet = {
|
||||
-- expand = function(args)
|
||||
-- require("luasnip").lsp_expand(args.body)
|
||||
-- end,
|
||||
-- },
|
||||
-- preselect = cmp.PreselectMode.None,
|
||||
sources = {
|
||||
-- { name = "nvim_lsp" },
|
||||
-- { name = "luasnip" },
|
||||
{ name = "buffer" },
|
||||
-- { name = "path" },
|
||||
},
|
||||
window = {
|
||||
completion = {
|
||||
border = "rounded",
|
||||
scrollbar = false,
|
||||
},
|
||||
documentation = {
|
||||
border = "rounded",
|
||||
}
|
||||
},
|
||||
},
|
||||
config = function(_, opts)
|
||||
local cmp = require("cmp")
|
||||
|
||||
local opts = {
|
||||
completion = {
|
||||
-- autocomplete = false,
|
||||
completeopt = "menu,menuone,noinsert",
|
||||
},
|
||||
formatting = {
|
||||
fields = { "abbr", "kind", "menu" },
|
||||
format = function(_, item)
|
||||
local icon = icons[item.kind] or ""
|
||||
item.kind = string.format(" %s %s", icon, item.kind)
|
||||
return item
|
||||
end,
|
||||
},
|
||||
mapping = {
|
||||
["<C-space>"] = cmp.mapping.complete(),
|
||||
["<C-up>"] = cmp.mapping.select_prev_item(),
|
||||
["<C-down>"] = cmp.mapping.select_next_item(),
|
||||
["<C-x>"] = cmp.mapping.abort(),
|
||||
["<cr>"] = cmp.mapping.confirm({ select = true }),
|
||||
},
|
||||
-- snippet = {
|
||||
-- expand = function(args)
|
||||
-- require("luasnip").lsp_expand(args.body)
|
||||
-- end,
|
||||
-- },
|
||||
-- preselect = cmp.PreselectMode.None,
|
||||
sources = {
|
||||
{ name = "nvim_lsp" },
|
||||
-- { name = "luasnip" },
|
||||
-- { name = "buffer" },
|
||||
-- { name = "path" },
|
||||
},
|
||||
window = {
|
||||
completion = {
|
||||
border = "rounded",
|
||||
scrollbar = false,
|
||||
},
|
||||
documentation = {
|
||||
border = "rounded",
|
||||
}
|
||||
},
|
||||
opts.mapping = {
|
||||
["<C-space>"] = cmp.mapping.complete(),
|
||||
["<C-up>"] = cmp.mapping.select_prev_item(),
|
||||
["<C-down>"] = cmp.mapping.select_next_item(),
|
||||
["<C-x>"] = cmp.mapping.abort(),
|
||||
["<cr>"] = cmp.mapping.confirm({ select = true }),
|
||||
}
|
||||
|
||||
cmp.setup(opts)
|
||||
|
11
.config/nvim/lua/disabled/luasnip.lua
Normal file
11
.config/nvim/lua/disabled/luasnip.lua
Normal file
@ -0,0 +1,11 @@
|
||||
return {
|
||||
"L3MON4D3/LuaSnip",
|
||||
dependencies = {
|
||||
"rafamadriz/friendly-snippets"
|
||||
},
|
||||
event = "InsertEnter",
|
||||
version = "v2.*",
|
||||
config = function()
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
end,
|
||||
}
|
@ -6,7 +6,16 @@ end
|
||||
map("n", ";", ":", "Command mode")
|
||||
map("n", "U", "<cmd>redo<cr>", "Redo")
|
||||
map({ "i", "n" }, "<esc>", "<cmd>noh<cr><esc>", "Clear search")
|
||||
map({"n", "v"}, "qq", "<cmd>qa!<cr>", "Quit all")
|
||||
map({"n", "v"}, "<leader>q", "<cmd>qa!<cr>", "Quit all")
|
||||
|
||||
-- Buffer management
|
||||
map("n", "<C-n>", "<cmd>enew<cr>", "New file")
|
||||
map({ "i", "n", "s", "v" }, "<C-s>", "<cmd>w<cr><esc>", "Save file")
|
||||
map("n", "<C-q>", "<cmd>bd<cr>", "Delete buffer")
|
||||
|
||||
-- Copy and paste
|
||||
map("v", "<C-c>", "y")
|
||||
map("n", "<C-v>", '"+P<right>')
|
||||
|
||||
-- Editing lines
|
||||
map({ "n", "v" }, "<C-b>", "^", "Beginning of line")
|
||||
@ -15,6 +24,7 @@ map({ "i", "n", "v" }, "<C-e>", "<end>", "End of line")
|
||||
map("n", "<C-l>", "^Da", "Rewrite line")
|
||||
map("i", "<C-l>", "<esc>^Da", "Rewrite line")
|
||||
map("v", "<C-l>", "V", "Select line")
|
||||
map("n", "<C-Enter>", "i<Enter>", "Split line")
|
||||
map({"n", "v"}, "<C-a>", "<esc>ggVG", "Select all")
|
||||
|
||||
-- Editing multiple instances
|
||||
@ -25,27 +35,22 @@ map("v", "<C-d>", "y/<C-r>\"<cr>N", "Search selection")
|
||||
map("n", "<C-r>", "*#:%s//<C-r><C-w>/g<left><left>", "Replace word under cursor")
|
||||
map("v", "<C-r>", "y/<C-r>\"<cr>N:%s//<C-r>\"/g<left><left>", "Replace selection")
|
||||
|
||||
-- Increasing and decreasing numbers
|
||||
map("n", "+", "<C-a>", "Increase number")
|
||||
map("n", "-", "<C-x>", "Decrease number")
|
||||
map("n", "<kPlus>", "<C-a>", "Increase number")
|
||||
map("n", "<kMinus>", "<C-x>", "Decrease number")
|
||||
|
||||
-- Buffer management
|
||||
map("n", "<C-n>", "<cmd>enew<cr>", "New file")
|
||||
map({ "i", "n", "s", "v" }, "<C-s>", "<cmd>w<cr><esc>", "Save file")
|
||||
map("n", "<C-q>", "<cmd>bd<cr>", "Delete buffer")
|
||||
|
||||
-- Copy and paste
|
||||
map("v", "<C-c>", "y")
|
||||
map("n", "<C-v>", '"+p')
|
||||
|
||||
-- Indenting
|
||||
map("n", "<Tab>", "V>gv<esc>")
|
||||
map("n", "<S-Tab>", "V<gv<esc>")
|
||||
map("v", "<Tab>", ">gv")
|
||||
map("v", "<S-Tab>", "<gv")
|
||||
|
||||
-- Increasing and decreasing numbers
|
||||
map("n", "+", "<C-a>", "Increase number")
|
||||
map("n", "-", "<C-x>", "Decrease number")
|
||||
map("n", "<kPlus>", "<C-a>", "Increase number")
|
||||
map("n", "<kMinus>", "<C-x>", "Decrease number")
|
||||
map("n", "<Bslash>", "<cmd>ToggleWord<cr>", "Toggle word")
|
||||
|
||||
-- Package manager
|
||||
map("n", "<leader>l", "<cmd>Lazy<cr>", "Lazy")
|
||||
|
||||
-- Shift arrow selection
|
||||
map("n", "<S-Up>", "v<Up>")
|
||||
map("n", "<S-Down>", "v<Down>")
|
||||
@ -61,6 +66,3 @@ map("i", "<S-Up>", "<Esc>v<Up>")
|
||||
map("i", "<S-Down>", "<Esc>v<Down>")
|
||||
map("i", "<S-Left>", "<Esc>v<Left>")
|
||||
map("i", "<S-Right>", "<Esc>v<Right>")
|
||||
|
||||
-- Package manager
|
||||
map("n", "<leader>l", "<cmd>Lazy<cr>", "Lazy")
|
||||
|
7
.config/nvim/lua/plugins/monokai.lua
Normal file
7
.config/nvim/lua/plugins/monokai.lua
Normal file
@ -0,0 +1,7 @@
|
||||
return {
|
||||
"tanvirtin/monokai.nvim",
|
||||
lazy = false,
|
||||
priority = 1000,
|
||||
opts = {},
|
||||
config = true,
|
||||
}
|
@ -6,7 +6,7 @@ return {
|
||||
-- "nvim-telescope/telescope-ui-select.nvim",
|
||||
},
|
||||
keys = {
|
||||
{"<leader>b", "<cmd>Telescope buffers<cr>", desc = "Buffers"},
|
||||
{"<C-Tab>", "<cmd>Telescope buffers<cr>", desc = "Buffers"},
|
||||
{"<leader>f", "<cmd>Telescope find_files<cr>", desc = "Find files"},
|
||||
{"<leader>h", "<cmd>Telescope help_tags<cr>", desc = "Help"},
|
||||
{"<leader>p", "<cmd>Telescope project<cr>", desc = "Projects"},
|
||||
|
31
.config/nvim/lua/usercmds.lua
Normal file
31
.config/nvim/lua/usercmds.lua
Normal file
@ -0,0 +1,31 @@
|
||||
-- ToggleWord
|
||||
vim.api.nvim_create_user_command("ToggleWord", function()
|
||||
local inverse = {
|
||||
["true"] = "false",
|
||||
["True"] = "False",
|
||||
["TRUE"] = "FALSE",
|
||||
["Yes"] = "No",
|
||||
["YES"] = "NO",
|
||||
["1"] = "0",
|
||||
["<"] = ">",
|
||||
["("] = ")",
|
||||
["["] = "]",
|
||||
["{"] = "}",
|
||||
['"'] = "'",
|
||||
['""'] = "''",
|
||||
["+"] = "-",
|
||||
["==="] = "!==",
|
||||
["=="] = "!="
|
||||
}
|
||||
|
||||
vim.tbl_add_reverse_lookup(inverse)
|
||||
vim.cmd("normal! yiw")
|
||||
local yanked = vim.fn.getreg('"')
|
||||
local flipped = inverse[yanked]
|
||||
|
||||
if flipped == nil then
|
||||
return
|
||||
end
|
||||
|
||||
vim.cmd("normal! ciw" .. flipped)
|
||||
end, {})
|
Reference in New Issue
Block a user