NVIM 配置打造
NVIM 配置
NVIM
安装
NVIM 配置
init.vim
vimrc.vim
# 安装 NVIM
brew install nvim
brew install ranger
# 需要有 python3 ⽀持
brew install python3
brew install node
# 对 nvim 添加 python ⽀持
pip3 install neovim pynvim
# 输⼊ nvim 检测
:
checkhealth
mkdir -p ~/.config/nvim
nvim ~/.config/nvim/init.vim
" 配置⽂件导⼊ "{{{
" ---------------------------------------------------------------------
" 基础使⽤习惯配置
runtime ./vimrc.vim
" 插件管理
"./lua/plugins.lua
lua require('plugins')
" 按键映射
runtime ./maps.vim
nvim ~/.config/nvim/vimrc.vim
"----vim 个⼈使⽤习惯配置start------
set encoding=UTF-8
" leader 设置成空格
let mapleader=" "
" 使⽤⿏标
set mouse=c
" 显⽰⾏号
set nu
" 相对⾏号
set relativenumber
" tab=4个空格
set tabstop=4
set shiftwidth=4
" 改变 vim 中光标的形状
let g:db_ui_use_nerd_fonts=1
let &t_SI.="\e[5 q" "SI = INSERT mode
let &t_SR.="\e[4 q" "SR = REPLACE mode
let &t_EI.="\e[1 q" "EI = NORMAL mode (ELSE)
" ⾼度光标所在⾏
"set cursorline
" 设置不换⾏
"set nowrap
set wrap
" 显⽰按下的按键
set showcmd
" 按tab 显⽰菜单
set wildmenu
" 不需要备份⽂件
set nobackup
"----vim 个⼈使⽤习惯配置end------
"ssh 远程粘贴板
if executable('clipboard-provider')
let g:clipboard = {
\ 'name': 'myClipboard',
\ 'copy': {
\ '+': 'clipboard-provider copy',
\ '*': 'env COPY_PROVIDERS=tmux clipboard-provider copy',
\ },
\ 'paste': {
\ '+': 'clipboard-provider paste',
\ '*': 'env COPY_PROVIDERS=tmux clipboard-provider paste',
\ },
\ }
endif
"随机选⼀个颜⾊风格
function RandomColorScheme()
let mycolors = split(globpath(&rtp,"**/colors/*.vim"),"\n")
exe 'so ' . mycolors[localtime() % len(mycolors)]
unlet mycolors
endfunction
"call RandomColorScheme()
:command NewColor call RandomColorScheme()
" ⽂件类型设置 "{{{
" ---------------------------------------------------------------------
" JSX 语法⾼亮
" set filetypes as typescriptreact
autocmd BufNewFile,BufRead *.tsx,*.jsx,*.js set filetype=typescriptreact
" 添加头部⽂件
function HeaderPython()
call setline(1, "#!/usr/bin/env python")
call append(1, "# -*- coding: utf-8 -*-")
call append(2, "# SR @ " . strftime('%Y-%m-%d %T', localtime()))
normal G
normal o
normal o
endf
autocmd bufnewfile *.py call HeaderPython()
maps.vim
nvim ~/.config/nvim/maps.vim
"-------------------------------------------------------------------------------
" window
"-------------------------------------------------------------------------------
" Split window
nmap ss :split<Return><C-w>w
nmap sv :vsplit<Return><C-w>w
" Move window
"nmap <Space> <C-w>w
"map s<left> <C-w>h
"map s<up> <C-w>k
"map s<down> <C-w>j
"map s<right> <C-w>l
map sh <C-w>h
map sk <C-w>k
map sj <C-w>j
map sl <C-w>l
" Resize window
" 在mac/linux中使⽤Alt键,在webssh
" 中alt没⽤,就使⽤Ctrl,WEBSSH主要的WINDOWS中使⽤
nmap <M-left> <C-w><
nmap <C-left> <C-w><
nmap s<left> <C-w><
nmap <M-right> <C-w>>
nmap <C-right> <C-w>>
nmap s<right> <C-w>>
nmap <M-up> <C-w>+
nmap <C-up> <C-w>+
nmap s<up> <C-w>+
nmap <M-down> <C-w>-
nmap <C-down> <C-w>-
nmap s<down> <C-w>-
" 插⼊模式移动光标
inoremap <C-h> <Left>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-l> <Right>
inoremap <C-d> <Delete>
" hh在我⽤的单词⾥出现的频率极低,其实感觉home⽤的没有end多,统⼀风格都⽤⼤写的吧"inoremap HH <Home>
" 单词中包含ll的太多了,所以⽤⼤写LL
"inoremap LL <End>
" jk <Esc>
inoremap jk <Esc>
" 插⼊模式⿏标滚轮抵消,不然会出现滚动⿏标录⼊了⼀堆5j5k
inoremap 5k <Esc>
inoremap 5j <Esc>
inoremap 9<CR> <Esc>a
" 快速跳转⾏⾸与⾏尾
nnoremap L $
nnoremap H ^
" 向下5⾏
noremap <C-j> 5j
" 向上5⾏
noremap <C-k> 5k
" 保存
noremap <C-s> :w<CR>
noremap s :w<CR>
" Coc智能处理,使⽤IDEA Alt+Enter 同样按键
"noremap <M-Enter> :CocAction<CR>
inoremap <C-s> <ESC> :w<CR>
" 代码格式化
noremap <leader>f :Format<CR>
noremap <leader>r :luafile ~/.wp/lua/run.lua<CR>
" 强制退出
map Q :q<CR>
"map qq :q<CR>
" 重新加载设置
map R :source $MYVIMRC<CR>
"⾃动关闭标签
inoremap <buffer> <C-v> <esc>yiwi<lt><esc>ea></><esc>hpF>i
set iskeyword+=<,>
iab <h1> <lt>h1> <lt>/h1><esc>5ha
" 全选
nmap <C-a> gg<S-v>G
" 加/减数字1
nnoremap + <C-a>
nnoremap - <C-x>
"-------------------------------------------------------------------------------
" Buffers
"-------------------------------------------------------------------------------
" Open current directory
" 插⼊模式移动光标
inoremap <C-h> <Left>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-l> <Right>
inoremap <C-d> <Delete>
" hh在我⽤的单词⾥出现的频率极低,其实感觉home⽤的没有end多,统⼀风格都⽤⼤写的吧
"inoremap HH <Home>
" 单词中包含ll的太多了,所以⽤⼤写LL
"inoremap LL <End>
" jk <Esc>
inoremap jk <Esc>
" 插⼊模式⿏标滚轮抵消,不然会出现滚动⿏标录⼊了⼀堆5j5k
inoremap 5k <Esc>
inoremap 5j <Esc>
inoremap 9<CR> <Esc>a
" 快速跳转⾏⾸与⾏尾
nnoremap L $
nnoremap H ^
" 向下5⾏
noremap <C-j> 5j
" 向上5⾏
noremap <C-k> 5k
" 保存vim命令光标10
noremap <C-s> :w<CR>
" Coc智能处理,使⽤IDEA Alt+Enter 同样按键
noremap <M-Enter> :CocAction<CR>
inoremap <C-s> <ESC> :w<CR>
" 代码格式化
"noremap <leader>f :Format<CR>
" 强制退出
map Q :q<CR>
" 重新加载设置
map R :source $MYVIMRC<CR>
"⾃动关闭标签
inoremap <buffer> <C-v> <esc>yiwi<lt><esc>ea></><esc>hpF>i
set iskeyword+=<,>
iab <h1> <lt>h1> <lt>/h1><esc>5ha
" 全选
nmap <C-a> gg<S-v>G
" 加/减数字1
nnoremap + <C-a>
nnoremap - <C-x>
"-------------------------------------------------------------------------------
" Buffers
"-------------------------------------------------------------------------------
" Open current directory
"nmap te :tabedit
"nmap <S-Tab> :tabprev<Return>
nmap <S-Tab> :bprev<Return>
"nmap <Tab> :tabnext<Return>
nmap <Tab> :bnext<Return>
" 窗⼝管理器
" invoke with '-'
nmap - <Plug>(choosewin)
"nmap sw <Plug>(choosewin)
"nmap <leader>w <Plug>(choosewin)
PS:⼀些插件的快捷键在末尾当所有插件都配置完毕的时候将快捷键加⼊该⽂件中
packer 插件管理器
mkdir -p ~/.config/nvim/lua
nvim ~/.config/nvim/plugins.lua
---@diagnostic disable: undefined-global
--在没有安装packer的电脑上,⾃动安装packer插件
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
pty(fn.glob(install_path)) > 0 then
--fn.system({'git', 'clone', '--depth', '1', 'github/wbthomason/packer.nvim', install_path}) --默认地址
fn.system({'git', 'clone', '--depth', '1', 'codechina.csdn/mirrors/wbthomason/packer.nvim.git', install_path}) --csdn加速镜像 d 'packadd packer.nvim'
end
-- Only required if you have packer configured as `opt`
return require('packer').startup({
function()
use 'wbthomason/packer.nvim'-- Packer can manage itself
end,
config = {
max_jobs = 16,
git = {
default_url_format = "/%s"
},
display = {
open_fn = function()
return require('packer.util').float({ border = 'single' })
end
}
}
})
# 插件安装⽅式
PackerInstall
插件配置
字体配置
# 终端安装该字体并且选择该字体防⽌乱码
brew tap homebrew/cask-fonts
brew install font-hack-nerd-font --cask
lualine标签栏美化
安装
配置
bufferline 状态栏
安装
配置
nvim ~/.config/nvim/lua/plugins.lua
--状态栏插件
use {
"nvim-lualine/lualine.nvim",
requires = {"kyazdani42/nvim-web-devicons", opt = true}
}
nvim ~/.config/nvim/after/plugin/lualine.lua
local status, lualine = pcall(require, "lualine")
if (not status) then
return
end
lualine.setup {
options = {
icons_enabled = true,
theme = "auto",
component_separators = {left = " ", right = " "},
section_separators = {left = " ", right = " "},
disabled_filetypes = {},
always_divide_middle = true
},
sections = {
lualine_a = {"mode"},
lualine_b = {
"branch",
"diff"
-
-{"diagnostics", sources = {"nvim_lsp"}}
},
lualine_c = {"filename"},
lualine_x = {
{"diagnostics", sources = {"nvim_lsp"}, symbols = {error = " ", warn = " ", info = " ", hint = " "}},
"encoding",
"fileformat",
"filetype"
},
lualine_y = {"progress"},
lualine_z = {"location"}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {"filename"},
lualine_x = {"location"},
lualine_y = {},
lualine_z = {}
},
tabline = {},
extensions = {}
}
-- bufferline 显⽰标签页,与lualine 配合使⽤
use "akinsho/bufferline.nvim"
nvim ~/.config/nvim/after/plugin/bufferline.lua
local status, bufferline = pcall(require, "bufferline")
if (not status) then
return
end
uicolors = true
bufferline.setup {
options = {
-
-numbers = "ordinal" | "buffer_id" | "both" | function({ ordinal, id, lower, raise }): string,
--numbers = "both",
--- @deprecated, please specify numbers as a function to customize the styling
--number_style = "superscript" | "subscript" | "" | { "none", "subscript" }, -- buffer_id at index 1, ordinal at index 2 --number_style = "none",
close_command = "bdelete! %d", -- can be a string | function, see "Mouse actions"
right_mouse_command = "bdelete! %d", -- can be a string | function, see "Mouse actions"
left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions"
middle_mouse_command = nil, -- can be a string | function, see "Mouse actions"
-- NOTE: this plugin is designed with this icon in mind,
-- and so changing this is NOT recommended, this is intended
-- as an escape hatch for people who cannot bear it for whatever reason
indicator_icon = "",
buffer_close_icon = " ",
modified_icon = "●",
close_icon = " ",
dashboard 开屏插件
安装
配置
left_trunc_marker = " ",
right_trunc_marker = " ",
--- name_formatter can be used to change the buffer's label in the bufferline.
--- Please note some names can/will break the
--- bufferline so use this at your discretion knowing that it has
--- some limitations that will *NOT* be fixed.
name_formatter = function(buf) -- buf contains a "name", "path" and "bufnr"
-- remove extension from markdown files for example
if buf.name:match("%.md") then
return vim.fn.fnamemodify(buf.name, ":t:r")
end
end,
max_name_length = 15,
max_prefix_length = 12, -- prefix used when a buffer is de-duplicated
tab_size = 15,
--diagnostics = false | "nvim_lsp" | "coc",
diagnostics = "nvim_lsp",
diagnostics_update_in_insert = false,
--[[diagnostics_indicator = function(count, level, diagnostics_dict, context)
return "(" .. count .. ")"
end,]]
-- rest of config ...
-
-- count is an integer representing total count of errors
--- level is a string "error" | "warning"
--- diagnostics_dict is a dictionary from error level ("error", "warning" or "info")to number of errors for each level. --- this should return a string
--- Don't get too fancy as this function will be executed a lot
diagnostics_indicator = function(count, level, diagnostics_dict, context)
local icon = level:match("error") and " " or " "
return " " .. icon .. count
end,
-- NOTE: this will be called a lot so don't do any heavy processing here
custom_filter = function(buf_number)
--如果是defx 则隐藏
local finded, _ = string.find(vim.bo[buf_number].filetype, "defx")
if finded ~= nil then
return false
end
return true
end,
--offsets = {{filetype = "NvimTree", text = "File Explorer" | function , text_align = "left" | "center" | "right"}}, --show_buffer_icons = true | false, -- disable filetype icons for buffers
show_buffer_icons = true, -- disable filetype icons for buffers
--show_buffer_close_icons = true | false,
show_buffer_close_icons = false,
--show_close_icon = true | false,
show_close_icon = false,
--show_tab_indicators = true | false,
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"},
separator_style = "thin",
--enforce_regular_tabs = false | true,
enforce_regular_tabs = false,
--always_show_bufferline = true | false,
always_show_bufferline = true
--[[sort_by = "id" | "extension" | "relative_directory" | "directory" | "tabs" | function(buffer_a, buffer_b)
-- add custom logic
return dified > dified
end]]
}
}
--按键映射
--nnoremap <silent> gb :BufferLinePick<CR>
vim.api.nvim_set_keymap("n", "gb", "<Cmd>BufferLinePick<CR>", {noremap = true, silent = true})
vim.api.nvim_set_keymap("n", "<leader>1", "<Cmd>BufferLineGoToBuffer 1<CR>", {noremap = true, si
lent = true})vim.api.nvim_set_keymap("n", "<leader>2", "<Cmd>BufferLineGoToBuffer 2<CR>", {noremap = true, silent = true})vim.api.nvim_set_keymap("n", "<leader>3", "<Cmd>BufferLineGoToBuffer 3<CR>", {noremap = true, silent = true})vim.api.nvim_set_keymap("n", "<leader>4", "<Cmd>BufferLineGoToBuffer 4<CR>", {noremap = true, silent = true})vim.api.nvim_set_keymap("n", "<leader>5", "<Cmd>BufferLineGoToBuffer 5<CR>", {noremap = true, silent = true})vim.api.nvim_set_keymap("n", "<leader>6", "<Cmd>BufferLineGoToBuffer 6<CR>", {noremap = true, silent = true})vim.api.nvim_set_keymap("n", "<leader>7", "<Cmd>BufferLineGoToBuffer 7<CR>", {noremap = true, silent = true})vim.api.nvim_set_keymap("n", "<leader>8", "<Cmd>BufferLineGoToBuffer 8<CR>", {noremap = true, silent = true})vim.api.nvim_set_keymap("n", "<leader>9", "<Cmd>BufferLineGoToBuffer 9<CR>", {noremap = true, silent = true}) use {"glepnir/dashboard-nvim"}
nvim ~/.config/nvim/after/plugin/dashboard.lua
local vim = vim
"",
" ⠀⠀⠀⠀⠀⠀⠀⠀⠀⡴⠞⠉⢉⣭⣿⣿⠿⣳⣤⠴⠖⠛⣛⣿⣿⡷⠖⣶⣤⡀⠀⠀⠀ ",
" ⠀⠀⠀⠀⠀⠀⠀⣼⠁⢀⣶⢻⡟⠿⠋⣴⠿⢻⣧⡴⠟⠋⠿⠛⠠⠾⢛⣵⣿⠀⠀⠀⠀ ",
" ⣼⣿⡿⢶⣄⠀⢀⡇⢀⡿⠁⠈⠀⠀⣀⣉⣀⠘⣿⠀⠀⣀⣀⠀⠀⠀⠛⡹⠋⠀⠀⠀⠀ ",
" ⣭⣤⡈⢑⣼⣻⣿⣧⡌⠁⠀⢀⣴⠟⠋⠉⠉⠛⣿⣴⠟⠋⠙⠻⣦⡰⣞⠁⢀⣤⣦⣤⠀ ",
" ⠀⠀⣰⢫⣾⠋⣽⠟⠑⠛⢠⡟⠁⠀⠀⠀⠀⠀⠈⢻⡄⠀⠀⠀⠘⣷⡈⠻⣍⠤⢤⣌⣀ ",
" ⢀⡞⣡⡌⠁⠀⠀⠀⠀⢀⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⢿⡀⠀⠀⠀⠸⣇⠀⢾⣷⢤⣬⣉ ",
" ⡞⣼⣿⣤⣄⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⣿⠀⠸⣿⣇⠈⠻ ",
" ⢰⣿⡿⢹⠃⠀⣠⠤⠶⣼⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⣿⠀⠀⣿⠛⡄⠀ ",
" ⠈⠉⠁⠀⠀⠀⡟⡀⠀⠈⡗⠲⠶⠦⢤⣤⣤⣄⣀⣀⣸⣧⣤⣤⠤⠤⣿⣀⡀⠉⣼⡇⠀ ",
" ⣿⣴⣴⡆⠀⠀⠻⣄⠀⠀⠡⠀⠀⠀⠈⠛⠋⠀⠀⠀⡈⠀⠻⠟⠀⢀⠋⠉⠙⢷⡿⡇⠀ ",
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论