Skip to content

Commit

Permalink
Update fzf configuration and keymaps, add token counting function, an…
Browse files Browse the repository at this point in the history
…d update completion configuration for lsp servers
  • Loading branch information
finnng committed Nov 11, 2023
1 parent 0e4c4a2 commit c09b79c
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 38 deletions.
17 changes: 10 additions & 7 deletions nvim/init.lua
Expand Up @@ -8,7 +8,7 @@ local plugins = {
"neovim/nvim-lspconfig",
"madox2/vim-ai",
"jesseleite/vim-agriculture",
"jiangmiao/auto-pairs",
--"jiangmiao/auto-pairs",
"junegunn/fzf",
"junegunn/fzf.vim",
"lambdalisue/suda.vim",
Expand All @@ -34,6 +34,13 @@ local plugins = {
"RRethy/nvim-base16",
"shaunsingh/nord.nvim",
"hood/popui.nvim",
"ibhagwan/fzf-lua",
-- optional for icon support
dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
-- calling `setup` is optional for customization
require("fzf-lua").setup({})
end,
}

-- Lazy loading configuration
Expand Down Expand Up @@ -67,15 +74,11 @@ require("nvimtree")
require("aichat")
require("format_config")
require("linting_config")
require("change_theme")
--require("change_theme")
require("popui_config")
require("fzf_config")
require("scratch_config")

vim.ui.select = require("popui.ui-overrider")
vim.ui.input = require("popui.input-overrider")
vim.api.nvim_set_keymap("n", ",d", ':lua require"popui.diagnostics-navigator"()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", ",m", ':lua require"popui.marks-manager"()<CR>', { noremap = true, silent = true })
vim.api.nvim_set_keymap("n", ",r", ':lua require"popui.references-navigator"()<CR>', { noremap = true, silent = true })

vim.cmd("colorscheme nord")

Expand Down
14 changes: 7 additions & 7 deletions nvim/lazy-lock.json
@@ -1,25 +1,25 @@
{
"auto-pairs": { "branch": "master", "commit": "39f06b873a8449af8ff6a3eee716d3da14d63a76" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" },
"cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"copilot.vim": { "branch": "release", "commit": "309b3c803d1862d5e84c7c9c5749ae04010123b8" },
"formatter.nvim": { "branch": "master", "commit": "34dcdfa0c75df667743b2a50dd99c84a557376f0" },
"fzf": { "branch": "master", "commit": "108493524110c8f996231eb5e51b93da7a9b57ca" },
"fzf": { "branch": "master", "commit": "38e3694d1ca5f138f26fbbffb7c0122b58eee8dc" },
"fzf-lua": { "branch": "main", "commit": "e1046726cf0cedf15ae0ff40537a421b79968c3e" },
"fzf.vim": { "branch": "master", "commit": "1e054c1d075d87903647db9320116d360eb8b024" },
"gruvbox": { "branch": "master", "commit": "f1ecde848f0cdba877acb0c740320568252cc482" },
"lazy.nvim": { "branch": "main", "commit": "96584866b9c5e998cbae300594d0ccfd0c464627" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "40301e1c74bc0946eece13edf2b1c561cc497491" },
"mason.nvim": { "branch": "main", "commit": "eabf6d347fdb75be360d4c0ced1145670a171453" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "6eb8cae80f2e4322ec82cd9f8fa423f6d1eb02c3" },
"mason.nvim": { "branch": "main", "commit": "41e75af1f578e55ba050c863587cffde3556ffa6" },
"nerdcommenter": { "branch": "master", "commit": "da948e160d9f54c2967c7927b9c74c5a68c8dc49" },
"nord.nvim": { "branch": "master", "commit": "0a22a387c92bb3b46e3d245522712ae7497bec38" },
"nvim-base16": { "branch": "master", "commit": "010bedf0b7c01ab4d4e4e896a8527d97c222351d" },
"nvim-blame-line": { "branch": "master", "commit": "b3d94f0ed5882d3d1c843c69788b9670476e1f42" },
"nvim-cmp": { "branch": "main", "commit": "0b751f6beef40fd47375eaf53d3057e0bfa317e4" },
"nvim-lspconfig": { "branch": "master", "commit": "37457f268af5cd6765e589b0dcd7cbd192d8da00" },
"nvim-tree.lua": { "branch": "master", "commit": "4ee6366ff1fc5d66231516ed05beffb50004261b" },
"nvim-treesitter": { "branch": "master", "commit": "9a746b4b6a1ef215943f07e6aa2ec35fb14097d4" },
"nvim-lspconfig": { "branch": "master", "commit": "b0852218bc5fa6514a71a9da6d5cfa63a263c83d" },
"nvim-tree.lua": { "branch": "master", "commit": "a2aaf8b430c11af36b869cf1c0ad2f7c8ceeaf2c" },
"nvim-treesitter": { "branch": "master", "commit": "42053b9db3275e1c17ace0da6beb57aa50023ae1" },
"popui.nvim": { "branch": "master", "commit": "19c61223927d6f174848c0e5f866d72044c5a0e1" },
"suda.vim": { "branch": "master", "commit": "8b0fc3711760195aba104e2d190cff9af8267052" },
"vim-agriculture": { "branch": "master", "commit": "84636fa47e38d79e61378e7113ab05e068fbd8d1" },
Expand Down
32 changes: 16 additions & 16 deletions nvim/lua/aichat.lua
@@ -1,29 +1,29 @@
-- AI configurations and global settings
vim.g.copilot_node_command = vim.fn.expand('~/.nvm/versions/node/v18.18.2/bin/node')
vim.g.copilot_node_command = vim.fn.expand("~/.nvm/versions/node/v18.18.2/bin/node")

-- vim-ai-chat
vim.g.vim_ai_chat = {
options = {
model = "gpt-4-0613",
temperature = 0.5,
max_tokens = -1,
},
options = {
model = "gpt-4-0613",
temperature = 0.5,
max_tokens = -1,
},
}
vim.api.nvim_set_keymap('n', '<leader>h1',
'iAI, please condense the conversation up to this point into a single title and format it in snake_case.<esc>:AIC<cr>',
{ noremap = true })
vim.api.nvim_set_keymap('n', '<leader>h2', 'yi"O~/aichat/<C-r>+.aichat<esc>dd:w <C-r>+<cr>', { noremap = true })
'iAI, please condense the conversation up to this point into a single title and format it in snake_case.<esc>:AIC<cr>',
{ noremap = true })
vim.api.nvim_set_keymap('n', '<leader>h2', 'yiwO~/aichat/<C-r>+.aichat<esc>dd:w <C-r>+<cr>', { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>h3',
':echo system(\'python3 ~/scripts/count_token_vim.py\', getline(1, \'$\'))<cr>', { noremap = true })
vim.api.nvim_set_keymap('n', '<leader>h4', ':AIN right<cr>', { noremap = true })

vim.api.nvim_set_keymap('i', '<c-enter>', '<esc>:AIC<cr>', { noremap = true })
':echo system(\'python3 ~/scripts/count_token_vim.py\', getline(1, \'$\'))<cr>', { noremap = true })
vim.api.nvim_set_keymap("n", "<leader>h4", ":AIN right<cr>", { noremap = true })
vim.api.nvim_set_keymap("i", "<c-enter>", "<esc>:AIC<cr>", { noremap = true })

-- Token counting function definition
function CountTokens()
local script_path = vim.fn.expand('~/scripts/count_token_vim.py')
local output = vim.fn.system('python3 ' .. script_path, table.concat(vim.fn.getline(1, '$'), "\n"))
print(output)
local script_path = vim.fn.expand("~/scripts/count_token_vim.py")
local output = vim.fn.system("python3 " .. script_path, table.concat(vim.fn.getline(1, "$"), "\n"))
print(output)
end

vim.cmd("command! TokenCount lua CountTokens()")

2 changes: 1 addition & 1 deletion nvim/lua/completion_config.lua
Expand Up @@ -68,7 +68,7 @@ local capabilities = require("cmp_nvim_lsp").default_capabilities()
--end
--require("lspconfig")["tsserver"].setup({ capabilities = capabilities, on_attach = onAttachFunc })

local servers = { "tsserver", "pyright", "gopls", "bashls", "yamlls", "html", "cssls" }
local servers = { "tsserver", "pyright", "gopls", --[["bashls",]] "yamlls", "html", "cssls" }

-- Loop over the servers and set them up
for _, lsp in ipairs(servers) do
Expand Down
3 changes: 2 additions & 1 deletion nvim/lua/fzf_config.lua
Expand Up @@ -4,8 +4,9 @@ vim.g.fzf_history_dir = vim.fn.expand("~/.vim/fzf_history")
vim.cmd([[ let g:fzf_preview_window = 'up:70%' ]])
vim.cmd([[ let g:fzf_layout = { 'window': { 'width': 0.9, 'height': 0.9 } } ]])
vim.cmd([[
let $FZF_DEFAULT_OPTS="-m --height 80% --layout=reverse --border
let $FZF_DEFAULT_OPTS="-m --height 80% --border
\ --bind ctrl-y:preview-up,ctrl-e:preview-down,
\ctrl-a:select-all,ctrl-z:deselect-all,
\ctrl-b:preview-page-up,ctrl-f:preview-page-down,
\ctrl-u:preview-half-page-up,ctrl-d:preview-half-page-down"
]])
Expand Down
2 changes: 1 addition & 1 deletion nvim/lua/linting_config.lua
@@ -1,7 +1,7 @@
local function setup_eslint_autocmd()
vim.api.nvim_create_autocmd("BufWritePre", {
pattern = { "*.js", "*.jsx", "*.ts", "*.tsx", "*.svelte", "*.html", "*.json", "*.css", "*.scss" },
command = "EslintFixAll",
command = "silent! EslintFixAll",
})
end

Expand Down
24 changes: 19 additions & 5 deletions nvim/lua/lsp.lua
@@ -1,5 +1,18 @@
local lspconfig = require("lspconfig")

local configs = require("lspconfig/configs")

if not lspconfig.htmx then
configs.htmx = {
default_config = {
cmd = { "htmx-lsp" },
filetypes = { "html", "htm" },
root_dir = lspconfig.util.root_pattern(".git/", ".hg/"),
},
}
end

lspconfig.htmx.setup({})
require("mason-lspconfig").setup_handlers({
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
Expand All @@ -12,11 +25,12 @@ require("mason-lspconfig").setup_handlers({
end,
})
end,
-- Next, you can provide a dedicated handler for specific servers.
-- For example, a handler override for the `rust_analyzer`:
--["rust_analyzer"] = function ()
--require("rust-tools").setup {}
--end
-- Not support yet
--htmx = {
--cmd = { "htmx-lsp" },
--filetypes = { "html", "htm" },
--root_dir = require("lspconfig/util").root_pattern(".git/", ".hg/"),
--},
})

-- Global mappings.
Expand Down
34 changes: 34 additions & 0 deletions nvim/lua/scratch_config.lua
@@ -0,0 +1,34 @@
local fzf_lua = require("fzf-lua")

local function open_scratch_buffer(filetype)
local date_time = os.date("%Y-%m-%d_%H-%M-%S")
local scratch_dir = vim.fn.expand("~/.vim/scratches/")
local filename = scratch_dir .. date_time .. "." .. filetype

vim.fn.mkdir(scratch_dir, "p")
vim.cmd("vnew " .. vim.fn.fnameescape(filename))
vim.api.nvim_buf_set_option(0, "filetype", filetype)
vim.api.nvim_command("write")
end

function _G.select_filetype_and_create_scratch()
local syntax_dir = vim.fn.globpath(vim.fn.getenv("VIMRUNTIME"), "syntax/*.vim", false, true)
local filetypes = {}

for _, filepath in ipairs(syntax_dir) do
local filetype = filepath:match("syntax[/\\](.+).vim$")
if filetype then
table.insert(filetypes, filetype)
end
end

fzf_lua.fzf_exec(filetypes, {
prompt = "Filetypes> ",
actions = {
["default"] = function(selected)
open_scratch_buffer(selected[1])
end,
},
})
end
vim.api.nvim_set_keymap("n", "<leader>t", ":lua _G.select_filetype_and_create_scratch()<CR>", { noremap = true })

0 comments on commit c09b79c

Please sign in to comment.