1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

10 Commits

Author SHA1 Message Date
jdhao
3040fa7969 use a cmp-fork for now
Until cmp is maintained again or switch??
2024-10-09 17:37:21 +02:00
jdhao
b9cf3cc6ed update conf for plugin live-command.nvim 2024-09-20 21:26:28 +02:00
jdhao
154cde3d71 Add plugin live-command.nvim 2024-09-19 22:07:03 +02:00
jdhao
81f64ed32e Use absolute path for viml config
Full path should be used to load viml config, otherwise, when we open
nvim in other directories, we see errors that the viml config can not be
found.
2024-09-02 22:19:52 +02:00
jdhao
db380ca7a7 remove inspect() from lua _G table
Nvim nows provides `vim.inspect()` and `vim.print()`.
2024-09-01 21:47:21 +02:00
jdhao
51f81093da restructure init.lua 2024-08-31 21:25:18 +02:00
jdhao
a9fc298063 update documentation for resuming cursor position 2024-08-30 01:03:13 +02:00
jdhao
9071e045eb Make * and # search case aware
By default, when you press `*` to search word under the cursor, the
option `smartcase` is ignored. This means that if you press `*` when
your cursor is on `The`, the lower case one `the` is also searched.

In this commit, we translate star and # search into normal search so that
'smartcase' option is respected.
2024-08-30 01:01:04 +02:00
jdhao
fa79647a63 Fix type for option relativenumber
"relativenumber" should be window local option, not buffer local option.
2024-08-29 21:45:07 +02:00
jdhao
4b4ff5f549 Add error handling for resuming the cursor
This will close issue #328.
2024-08-29 21:41:13 +02:00
7 changed files with 63 additions and 38 deletions

View File

@@ -16,25 +16,18 @@ local utils = require("utils")
local expected_version = "0.10.1" local expected_version = "0.10.1"
utils.is_compatible_version(expected_version) utils.is_compatible_version(expected_version)
local core_conf_files = { local config_dir = vim.fn.stdpath("config")
"globals.lua", -- some global settings ---@cast config_dir string
"options.vim", -- setting options in nvim
"custom-autocmd.lua", -- various autocommands
"mappings.lua", -- all the user-defined mappings
"plugins.vim", -- all the plugins installed and their configurations
"colorschemes.lua", -- colorscheme settings
}
local viml_conf_dir = vim.fn.stdpath("config") .. "/viml_conf" -- some global settings
-- source all the core config files require("globals")
for _, file_name in ipairs(core_conf_files) do -- setting options in nvim
if vim.endswith(file_name, 'vim') then vim.cmd("source " .. vim.fs.joinpath(config_dir, "viml_conf/options.vim"))
local path = string.format("%s/%s", viml_conf_dir, file_name) -- various autocommands
local source_cmd = "source " .. path require("custom-autocmd")
vim.cmd(source_cmd) -- all the user-defined mappings
else require("mappings")
local module_name, _ = string.gsub(file_name, "%.lua", "") -- all the plugins installed and their configurations
package.loaded[module_name] = nil vim.cmd("source ".. vim.fs.joinpath(config_dir, "viml_conf/plugins.vim"))
require(module_name) -- colorscheme settings
end require("colorschemes")
end

View File

@@ -35,33 +35,48 @@ keymap.set("n", "N", "", {
end, end,
}) })
local no_word_under_cursor = function() local check_cursor_word = function()
local cursor_word = vim.fn.expand("<cword>") local cursor_word = vim.fn.expand("<cword>")
local result = cursor_word == "" local result = cursor_word == ""
if result then if result then
local msg = "E348: No string under cursor" local msg = "E348: No string under cursor"
api.nvim_err_writeln(msg) api.nvim_err_writeln(msg)
end end
return result return result, cursor_word
end end
keymap.set("n", "*", "", { keymap.set("n", "*", "", {
callback = function() callback = function()
if no_word_under_cursor() then local cursor_word_empty, cursor_word = check_cursor_word()
if cursor_word_empty then
return return
end end
vim.fn.execute("normal! *N")
local cmd = string.format([[normal! /\v<%s>]], cursor_word)
-- In order to say that we are pressing Enter key, instead of typing literally the character,
-- we need to replace special notation with their internal representation.
local escaped_enter = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
-- character `N` is used to keep the cursor when pressing `*`
local full_cmd = cmd .. escaped_enter .. "N"
vim.fn.execute(full_cmd)
hlslens.start() hlslens.start()
end, end,
}) })
keymap.set("n", "#", "", { keymap.set("n", "#", "", {
callback = function() callback = function()
if no_word_under_cursor() then local cursor_word_empty, cursor_word = check_cursor_word()
if cursor_word_empty then
return return
end end
vim.fn.execute("normal! #N")
local cmd = string.format([[normal! ?\v<%s>]], cursor_word)
local escaped_enter = vim.api.nvim_replace_termcodes("<CR>", true, false, true)
local full_cmd = cmd .. escaped_enter .. "N"
vim.fn.execute(full_cmd)
hlslens.start() hlslens.start()
end, end,
}) })

View File

@@ -0,0 +1,4 @@
require("live-command").setup {
enable_highlighting = true,
inline_highlighting = true,
}

View File

@@ -43,7 +43,7 @@ local custom_attach = function(client, bufnr)
map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" }) map("n", "<space>wa", vim.lsp.buf.add_workspace_folder, { desc = "add workspace folder" })
map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" }) map("n", "<space>wr", vim.lsp.buf.remove_workspace_folder, { desc = "remove workspace folder" })
map("n", "<space>wl", function() map("n", "<space>wl", function()
inspect(vim.lsp.buf.list_workspace_folders()) vim.print(vim.lsp.buf.list_workspace_folders())
end, { desc = "list workspace folder" }) end, { desc = "list workspace folder" })
-- Set some key bindings conditional on server capabilities -- Set some key bindings conditional on server capabilities

View File

@@ -163,8 +163,16 @@ api.nvim_create_autocmd("FileType", {
-- vim.print(string.format("mark_pos: %s", vim.inspect(mark_pos))) -- vim.print(string.format("mark_pos: %s", vim.inspect(mark_pos)))
-- it seems that without vim.schedule, the cursor position can not be set correctly -- it seems that without vim.schedule, the cursor position can not be set correctly
vim.schedule(function() vim.schedule(function()
api.nvim_win_set_cursor(0, mark_pos) local status, result = pcall(api.nvim_win_set_cursor, 0, mark_pos)
if not status then
api.nvim_err_writeln(string.format("Failed to resume cursor position. Context %s, error: %s",
vim.inspect(ev), result))
end
end) end)
-- the following two ways also seem to work,
-- ref: https://www.reddit.com/r/neovim/comments/104lc26/how_can_i_press_escape_key_using_lua/
-- vim.api.nvim_feedkeys("g`\"", "n", true)
-- vim.fn.execute("normal! g`\"")
end end
end, end,
}) })
@@ -257,7 +265,7 @@ api.nvim_create_autocmd("BufReadPre", {
if fn.getfsize(f) > file_size_limit or fn.getfsize(f) == -2 then if fn.getfsize(f) > file_size_limit or fn.getfsize(f) == -2 then
vim.o.eventignore = "all" vim.o.eventignore = "all"
-- turning off relative number helps a lot -- turning off relative number helps a lot
vim.bo.relativenumber = false vim.wo.relativenumber = false
vim.bo.swapfile = false vim.bo.swapfile = false
vim.bo.bufhidden = "unload" vim.bo.bufhidden = "unload"

View File

@@ -3,11 +3,6 @@ local api = vim.api
local utils = require('utils') local utils = require('utils')
-- Inspect something
function _G.inspect(item)
vim.print(item)
end
------------------------------------------------------------------------ ------------------------------------------------------------------------
-- custom variables -- -- custom variables --
------------------------------------------------------------------------ ------------------------------------------------------------------------

View File

@@ -23,7 +23,8 @@ end
local plugin_specs = { local plugin_specs = {
-- auto-completion engine -- auto-completion engine
{ {
"hrsh7th/nvim-cmp", "iguanacucumber/magazine.nvim",
name = "nvim-cmp",
-- event = 'InsertEnter', -- event = 'InsertEnter',
event = "VeryLazy", event = "VeryLazy",
dependencies = { dependencies = {
@@ -38,7 +39,6 @@ local plugin_specs = {
require("config.nvim-cmp") require("config.nvim-cmp")
end, end,
}, },
{ {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
event = { "BufRead", "BufNewFile" }, event = { "BufRead", "BufNewFile" },
@@ -563,6 +563,16 @@ local plugin_specs = {
require("copilot").setup {} require("copilot").setup {}
end, end,
}, },
{
"smjonas/live-command.nvim",
-- live-command supports semantic versioning via Git tags
-- tag = "2.*",
cmd = "Preview",
config = function()
require("config.live-command")
end,
event = "VeryLazy",
},
} }
require("lazy").setup { require("lazy").setup {