Skip to content

Commit

Permalink
feat: neovim
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan4yin committed Jul 10, 2023
1 parent b6629a3 commit 21b3d4a
Show file tree
Hide file tree
Showing 37 changed files with 2,499 additions and 18 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,4 @@ Other dotfiles && docs that inspired me:
- [fufexan/dotfiles](https://github.com/fufexan/dotfiles)
- [davidtwco/veritas](https://github.com/davidtwco/veritas)
- [gvolpe/nix-config](https://github.com/gvolpe/nix-config)

```
```
- [Ruixi-rebirth/flakes](https://github.com/Ruixi-rebirth/flakes)
1 change: 1 addition & 0 deletions flakes
Submodule flakes added at 1c6bfb
14 changes: 0 additions & 14 deletions home/base/desktop/development.nix
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,6 @@
];

programs = {
# modern vim
neovim = {
enable = true;
defaultEditor = true;
viAlias = false;
vimAlias = true;

# enable line number, disable mouse visual mode
extraConfig = ''
set number relativenumber mouse-=a
'';

};

direnv = {
enable = true;
nix-direnv.enable = true;
Expand Down
1 change: 1 addition & 0 deletions home/base/server/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{ ... }:
{
imports = [
./neovim
./nushell
./tmux

Expand Down
61 changes: 61 additions & 0 deletions home/base/server/neovim/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{ config, lib, inputs, pkgs, ... }:

# references:
# https://github.com/Ruixi-rebirth/flakes/tree/main/modules/editors/nvim
# https://github.com/Chever-John/dotfiles/tree/master/nvim
{
nixpkgs.config = {
programs.npm.npmrc = ''
prefix = ''${HOME}/.npm-global
'';
};
programs = {
neovim = {
enable = true;
defaultEditor = true;
viAlias = false;
vimAlias = true;
withPython3 = true;
withNodeJs = true;
extraPackages = [
];
#-- Plugins --#
plugins = with pkgs.vimPlugins;[ ];
#-- --#
};
};
home = {
packages = with pkgs; [
#-- LSP --#
nodePackages_latest.typescript
nodePackages_latest.typescript-language-server
nodePackages_latest.vscode-langservers-extracted
nodePackages_latest.bash-language-server
nil
# rnix-lsp
# nixd
lua-language-server
gopls
pyright
zk
rust-analyzer
clang-tools
haskell-language-server
#-- tree-sitter --#
tree-sitter
#-- format --#
stylua
black
nixpkgs-fmt
rustfmt
beautysh
nodePackages.prettier
stylish-haskell
#-- Debug --#
lldb
];
};

home.file.".config/nvim/init.lua".source = ./init.lua;
home.file.".config/nvim/lua".source = ./lua;
}
30 changes: 30 additions & 0 deletions home/base/server/neovim/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require("base")
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
local lazy_theme
if os.getenv("GTK_THEME") == "Nordic" then
lazy_theme = "nord"
elseif os.getenv("GTK_THEME") == "Catppuccin-Frappe-Pink" then
lazy_theme = "catppuccin-frappe"
else
lazy_theme = "catppuccin-latte"
end
local opts = {
install = {
colorscheme = { lazy_theme },
},
ui = {
size = { width = 1.0, height = 1.0 },
},
}
require("lazy").setup("plugins", opts)
16 changes: 16 additions & 0 deletions home/base/server/neovim/lua/base/autocmd.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--Revert to where the cursor was when the file was last closed
vim.cmd([[autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif]])

vim.cmd([[set iskeyword+=-]])

vim.cmd("set whichwrap+=<,>,[,],h,l")
-- about fold
vim.cmd("set foldmethod=expr")
vim.cmd("set foldexpr=nvim_treesitter#foldexpr()")
-- vim.cmd([[autocmd BufReadPost,FileReadPost * normal zR]])

-- set bg transparent
--vim.cmd([[autocmd ColorScheme * highlight Normal guibg=NONE ctermbg=NONE]])
3 changes: 3 additions & 0 deletions home/base/server/neovim/lua/base/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require("base.autocmd")
require("base.mappings")
require("base.options")
86 changes: 86 additions & 0 deletions home/base/server/neovim/lua/base/mappings.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
local opts = { noremap = true, silent = true }
local term_opts = { silent = true }
local keymap = vim.api.nvim_set_keymap

-- Remap space as leader key
keymap("", "<Space>", "<Nop>", opts)
vim.g.mapleader = " "

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

-- Better to save file & exit file --
keymap("n", "Q", ":q<CR>", opts)
keymap("n", "S", ":w<CR>", opts)

-- 'jk' key to exit insert mode --
keymap("i", "jk", "<Esc>", opts)

-- Better window navigation --
keymap("n", "<C-h>", "<C-w>h", opts)
keymap("n", "<C-j>", "<C-w>j", opts)
keymap("n", "<C-k>", "<C-w>k", opts)
keymap("n", "<C-l>", "<C-w>l", opts)

-- Naviagate buffers --
keymap("n", "<TAB>", ":bnext<CR>", opts)
keymap("n", "<S-TAB>", ":bprevious<CR>", opts)

-- Stay in indent mode --
keymap("v", "<", "<gv", opts)
keymap("v", ">", ">gv", opts)

-- Move text up and down --
keymap("x", "J", ":move '>+1<CR>gv-gv", opts)
keymap("x", "K", ":move '<-2<CR>gv-gv", opts)
keymap("v", "J", ":move '>+1<CR>gv-gv", opts)
keymap("v", "K", ":move '<-2<CR>gv-gv", opts)

-- Better split screen --
keymap("", "s", "<Nop>", opts)
keymap("n", "sl", ":set splitright<CR>:vsplit<CR>", opts)
keymap("n", "sh", ":set nosplitright<CR>:vsplit<CR>", opts)
keymap("n", "sk", ":set nosplitbelow<CR>:split<CR>", opts)
keymap("n", "sj", ":set splitbelow<CR>:split<CR>", opts)

-- Average adjustment window --
keymap("n", "<C-=>", "<C-w>=", opts)
-- Swap and move windows --
keymap("n", "<Space>h", "<C-w>H", opts)
keymap("n", "<Space>j", "<C-w>J", opts)
keymap("n", "<Space>k", "<C-w>K", opts)
keymap("n", "<Space>l", "<C-w>L", opts)

-- Adjust the direction of the split screen --
keymap("n", ",", "<C-w>t<C-w>K", opts)
keymap("n", ".", "<C-w>t<C-w>H", opts)

-- Resize the window --
keymap("n", "<C-Down>", ":resize -2<CR>", opts)
keymap("n", "<C-Up>", ":resize +2<CR>", opts)
keymap("n", "<C-Left>", ":vertical resize -2<CR>", opts)
keymap("n", "<C-Right>", ":vertical resize +2<CR>", opts)

-- Better viewing of search results --
keymap("n", "<Space><CR>", ":nohlsearch<CR>", opts)
keymap("n", "n", "nzz", opts)
keymap("n", "N", "Nzz", opts)

-- tabnew
keymap("n", "<C-n>", ":tabnew<CR>", opts)
-- msic --
keymap("n", "<C-u>", "5k", opts)
keymap("n", "<C-d>", "5j", opts)
keymap("n", "<C-.>", "$", opts)
keymap("i", "<C-.>", "<ESC>$", opts)
keymap("x", "<C-.>", "$", opts)
keymap("v", "<C-.>", "$", opts)
keymap("n", "<C-,>", "^", opts)
keymap("i", "<C-,>", "<ESC>^", opts)
keymap("x", "<C-,>", "^", opts)
keymap("v", "<C-,>", "^", opts)
32 changes: 32 additions & 0 deletions home/base/server/neovim/lua/base/options.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
local options = {
clipboard = "unnamedplus",
mouse = "a",
undofile = true,
ignorecase = true,
smartcase = true,
showmode = false,
showtabline = 2,
smartindent = true,
autoindent = true,
swapfile = true,
hidden = true, --default on
expandtab = false,
cmdheight = 1,
shiftwidth = 4, --insert 4 spaces for each indentation
tabstop = 4, --insert 4 spaces for a tab
cursorline = false, --Highlight the line where the cursor is located
cursorcolumn = false,
number = true,
numberwidth = 4,
relativenumber = true,
--[[ wrap = false, ]]
scrolloff = 8,
fileencodings = "utf-8,gbk",
updatetime = 50, -- faster completion (4000ms default)
foldenable = false,
foldlevel = 99,
}

for k, v in pairs(options) do
vim.opt[k] = v
end
38 changes: 38 additions & 0 deletions home/base/server/neovim/lua/plugins/autopairs.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
return {
"windwp/nvim-autopairs",
dependencies = { "hrsh7th/nvim-cmp" },
event = "InsertEnter",
config = function()
local status_ok, npairs = pcall(require, "nvim-autopairs")
if not status_ok then
return
end

npairs.setup({
check_ts = true,
ts_config = {
lua = { "string", "source" },
javascript = { "string", "template_string" },
java = false,
},
disable_filetype = { "TelescopePrompt", "spectre_panel" },
fast_wrap = {
map = "<M-e>",
chars = { "{", "[", "(", '"', "'" },
pattern = string.gsub([[ [%'%"%)%>%]%)%}%,] ]], "%s+", ""),
offset = 0, -- Offset from pattern match
end_key = "$",
keys = "qwertyuiopzxcvbnmasdfghjkl",
check_comma = true,
highlight = "PmenuSel",
highlight_grey = "LineNr",
},
})
local cmp_autopairs = require("nvim-autopairs.completion.cmp")
local cmp_status_ok, cmp = pcall(require, "cmp")
if not cmp_status_ok then
return
end
cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({ map_char = { tex = "" } }))
end,
}
48 changes: 48 additions & 0 deletions home/base/server/neovim/lua/plugins/bufferline.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
return {
"akinsho/bufferline.nvim",
dependencies = { "nvim-tree/nvim-web-devicons", "glepnir/lspsaga.nvim" },
config = function()
local highlights
if os.getenv("GTK_THEME") == "Nordic" then
highlights = require("nord").bufferline.highlights({
italic = true,
bold = true,
})
elseif
os.getenv("GTK_THEME") == "Catppuccin-Frappe-Pink" or os.getenv("GTK_THEME") == "Catppuccin-Latte-Green"
then
highlights = require("catppuccin.groups.integrations.bufferline").get()
end
require("bufferline").setup({
highlights = highlights,
options = {
mode = "buffers", -- set to "tabs" to only show tabpages instead
numbers = "buffer_id",
--number_style = "superscript" | "subscript" | "" | { "none", "subscript" }, -- buffer_id at index 1, ordinal at index 2
close_command = "bdelete! %d", -- can be a string | function, see "Mouse actions"
indicator_style = "",
buffer_close_icon = "x",
modified_icon = "",
close_icon = "",
left_trunc_marker = "",
right_trunc_marker = "",
max_name_length = 30,
max_prefix_length = 30, -- prefix used when a buffer is de-duplicated
tab_size = 21,
diagnostics = false,
diagnostics_update_in_insert = false,
offsets = { { filetype = "NvimTree", text = "", padding = 1 } },
show_buffer_icons = true, -- disable filetype icons for buffers
show_buffer_close_icons = true,
show_close_icon = true,
show_tab_indicators = true,
persist_buffer_sort = true, -- whether or not custom sorted buffers should persist
-- can also be a table containing 2 custom separators
-- [focused and unfocused]. eg: { '|', '|' }
separator_style = { "", "" }, --"slant" | "thick" | "thin" | { 'any', 'any' },
enforce_regular_tabs = true,
always_show_bufferline = true,
},
})
end,
}

0 comments on commit 21b3d4a

Please sign in to comment.