Skip to content

Commit

Permalink
first commit: Packer
Browse files Browse the repository at this point in the history
  • Loading branch information
talentestors committed Nov 30, 2024
0 parents commit 8f1ebc5
Show file tree
Hide file tree
Showing 18 changed files with 762 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## install packer

> Unix, Linux Installation
```shell
git clone --depth 1 https://github.com/wbthomason/packer.nvim\
~/.local/share/nvim/site/pack/packer/start/packer.nvim
```

> Windows Powershell Installation
```shell
git clone --depth 1 https://github.com/wbthomason/packer.nvim "$env:LOCALAPPDATA\nvim-data\site\pack\packer\start\packer.nvim"
```
3 changes: 3 additions & 0 deletions ginit.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if exists(':GuiFont')
GuiFont! JetBrainsMono\ Nerd\ Font:h11
endif
47 changes: 47 additions & 0 deletions init.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
" Packer 插件管理
lua require('plugins')
lua require('conf/nvim-treesitter-context')
lua require('conf/nvim-treesitter')
lua require('conf/nvim-tree')
lua require('conf/bufferline')
lua require('conf/toggleterm')

" lua neovim 配置
lua require('options')
lua require('keymaps')
lua require('colorscheme')

" lsp
lua require('lsp/setup')
lua require('lsp/nvim-cmp')

" 语法高亮
" syntax on

" 显示行号
" set rnu
" set number
set number relativenumber

set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,chinese,cp936
set mouse=a " 启用鼠标

" 退出vim重置光标
:autocmd VimLeave * set guicursor= | call chansend(v:stderr, "\x1b[ q")

set guifont=JetBrainsMono\ Nerd\ Font:h12

" 回车自动换行
" nnoremap <CR> i<CR><Esc>

" add tab space
set ts=4 " tabstop
set softtabstop=4 " 在编辑模式的时候按退格键的时候退回缩进的长度
set shiftwidth=4 " 每一级缩进的长度
" expandtab 缩进用空格来表示,noexpandtab 则是用制表符表示一个缩进。
set expandtab
set autoindent " 自动缩进

50 changes: 50 additions & 0 deletions lua/colorscheme.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- colorscheme.lua for theme

-- Default options
require('nightfox').setup({
options = {
-- Compiled file's destination location
compile_path = vim.fn.stdpath("cache") .. "/nightfox",
compile_file_suffix = "_compiled", -- Compiled file suffix
transparent = true, -- Disable setting background
terminal_colors = true, -- Set terminal colors (vim.g.terminal_color_*) used in `:terminal`
dim_inactive = false, -- Non focused panes set to alternative background
module_default = true, -- Default enable value for modules
colorblind = {
enable = false, -- Enable colorblind support
simulate_only = false, -- Only show simulated colorblind colors and not diff shifted
severity = {
protan = 0, -- Severity [0,1] for protan (red)
deutan = 0, -- Severity [0,1] for deutan (green)
tritan = 0, -- Severity [0,1] for tritan (blue)
},
},
styles = { -- Style to be applied to different syntax groups
comments = "NONE", -- Value is any valid attr-list value `:help attr-list`
conditionals = "NONE",
constants = "NONE",
functions = "NONE",
keywords = "NONE",
numbers = "NONE",
operators = "NONE",
strings = "NONE",
types = "NONE",
variables = "NONE",
},
inverse = { -- Inverse highlight for different types
match_paren = false,
visual = false,
search = false,
},
modules = { -- List of various plugins and additional options
-- ...
},
},
palettes = {},
specs = {},
groups = {},
})

-- setup must be called before loading
vim.cmd("colorscheme nightfox")

14 changes: 14 additions & 0 deletions lua/conf/bufferline.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
vim.opt.termguicolors = true
require("bufferline").setup {
options = {
-- 使用 nvim 内置lsp
diagnostics = "nvim_lsp",
-- 左侧让出 nvim-tree 的位置
offsets = {{
filetype = "NvimTree",
text = "File Explorer",
highlight = "Directory",
text_align = "left"
}}
}
}
18 changes: 18 additions & 0 deletions lua/conf/nvim-tree.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require'nvim-tree'.setup {
sort = {
sorter = "case_sensitive",
},
view = {
width = 27,
},
renderer = {
group_empty = true,
},
filters = {
dotfiles = true,
},
-- 不显示 git 状态图标
git = {
enable = false
}
}
14 changes: 14 additions & 0 deletions lua/conf/nvim-treesitter-context.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require'treesitter-context'.setup{
enable = true, -- Enable this plugin (Can be enabled/disabled later via commands)
max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit.
min_window_height = 0, -- Minimum editor window height to enable context. Values <= 0 mean no limit.
line_numbers = true,
multiline_threshold = 20, -- Maximum number of lines to show for a single context
trim_scope = 'outer', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
mode = 'cursor', -- Line used to calculate context. Choices: 'cursor', 'topline'
-- Separator between context and content. Should be a single character string, like '-'.
-- When separator is set, the context will only show up when there are at least 2 lines above cursorline.
separator = nil,
zindex = 20, -- The Z-index of the context window
on_attach = nil, -- (fun(buf: integer): boolean) return false to disable attaching
}
62 changes: 62 additions & 0 deletions lua/conf/nvim-treesitter.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require'nvim-treesitter.configs'.setup {
-- A list of parser names, or "all" (the five listed parsers should always be installed)
ensure_installed = { "c", "lua", "vim", "vimdoc", "query","cpp", "python", "rust"},

-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,

-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,

-- List of parsers to ignore installing (or "all")
ignore_install = { "javascript" },

---- If you need to change the installation directory of the parsers (see -> Advanced Setup)
-- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")!

highlight = {
enable = true,

-- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
-- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
-- the name of the parser)
-- list of language that will be disabled
disable = { },
-- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files
disable = function(lang, buf)
local max_filesize = 100 * 1024 -- 100 KB
local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
if ok and stats and stats.size > max_filesize then
return true
end
end,

-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false,
},
-- 启用增量选择
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<CR>',
node_incremental = '<CR>',
node_decremental = '<BS>',
scope_incremental = '<TAB>',
}
},
-- 启用基于Treesitter的代码格式化(=) . NOTE: This is an experimental feature.
indent = {
enable = true
}
}
-- 开启 Folding
vim.wo.foldmethod = 'expr'
vim.wo.foldexpr = 'nvim_treesitter#foldexpr()'
-- 默认不要折叠
-- https://stackoverflow.com/questions/8316139/how-to-set-the-default-to-unfolded-when-you-open-a-file
vim.wo.foldlevel = 99

8 changes: 8 additions & 0 deletions lua/conf/toggleterm.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-- termainl
local opt = require("toggleterm").setup({
open_mapping = [[<c-`>]],
-- 打开新终端后自动进入插入模式
start_in_insert = true,
-- 在当前buffer的下方打开新终端
direction = 'horizontal'
})
86 changes: 86 additions & 0 deletions lua/keymaps.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
-- keymaps.lua for keymap

-- Modes
-- normal_mode = "n",
-- insert_mode = "i",
-- visual_mode = "v",
-- visual_block_mode = "x",
-- term_mode = "t",
-- command_mode = "c",

-- leader key 为空
vim.g.mapleader = " "
vim.g.maplocalleader = " "

local opt = {
noremap = true,
silent = true,
}

-- 本地变量
local map = vim.api.nvim_set_keymap
-- nvimTree
map('n', '<A-m>', ':NvimTreeToggle<CR>', opt)
map('n', '<A-h>', ':NvimTreeFocus<CR>', opt)
map('n', '<A-r>', ':NvimTreeRefresh<CR>', opt)
-- bufferline 左右Tab切换
map("n", "<C-h>", ":BufferLineCyclePrev<CR>", opt)
map("n", "<C-l>", ":BufferLineCycleNext<CR>", opt)

--
local pluginKeys = {}
-- nvim-cmp 自动补全
pluginKeys.cmp = function(cmp)
return {
-- 上一个
['<C-k>'] = cmp.mapping.select_prev_item(),
-- 下一个
['<Tab>'] = cmp.mapping.select_next_item(),
['<C-j>'] = cmp.mapping.select_next_item(),
-- 出现补全
['<A-.>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
-- 取消
['<A-,>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
-- 确认
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({
select = true ,
behavior = cmp.ConfirmBehavior.Replace
}),
-- ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-u>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-d>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
}
end

-- lsp 回调函数快捷键设置
pluginKeys.maplsp = function(mapbuf)
-- rename
mapbuf('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opt)
-- code action
mapbuf('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opt)
-- go xx
mapbuf('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opt)
mapbuf('n', 'gh', '<cmd>lua vim.lsp.buf.hover()<CR>', opt)
mapbuf('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', opt)
mapbuf('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opt)
mapbuf('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opt)
-- diagnostic
mapbuf('n', 'go', '<cmd>lua vim.diagnostic.open_float()<CR>', opt)
mapbuf('n', 'gp', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opt)
mapbuf('n', 'gn', '<cmd>lua vim.diagnostic.goto_next()<CR>', opt)
-- mapbuf('n', '<leader>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opt)
-- leader + =
mapbuf('n', '<leader>=', '<cmd>lua vim.lsp.buf.formatting()<CR>', opt)
-- mapbuf('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opt)
-- mapbuf('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opt)
-- mapbuf('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opt)
-- mapbuf('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opt)
-- mapbuf('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opt)
end

return pluginKeys
52 changes: 52 additions & 0 deletions lua/lsp/config/lua.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
require'lspconfig'.lua_ls.setup {
settings = {
Lua = {
runtime = {
-- Tell the language server which version of lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT',
},
diagnostics = {
-- Get the language server to recognize the `vim` global
global = {
'vim',
'require'
},
},
workspace = {
-- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true),
},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {
enable = false,
},
}
},
on_init = function(client)
local path = client.workspace_folders[1].name
if vim.loop.fs_stat(path..'/.luarc.json') or vim.loop.fs_stat(path..'/.luarc.jsonc') then
return
end

client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT'
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME
-- Depending on the usage, you might want to add additional paths here.
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
}
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
-- library = vim.api.nvim_get_runtime_file("", true)
}
})
end
}
16 changes: 16 additions & 0 deletions lua/lsp/config/markdown.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
local opts = {
flags = {
debounce_text_changes = 150,
},
on_attach = function(client, bufnr)
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
require("keybindings").mapLSP(buf_set_keymap)
end,
}
return {
on_setup = function(server)
server.setup(opts)
end,
}
Loading

0 comments on commit 8f1ebc5

Please sign in to comment.