Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update fzf configuration and keymaps, add token counting function, an…
…d update completion configuration for lsp servers
- Loading branch information
Showing
8 changed files
with
90 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }) |