安装deepin虚拟机
官网下载地址
vmware中记得版本选择是debian 10.x 64位
然后就是一些确认操作,然后就可以了
安装git
apt install gedit
apt install git
git config --global user.name "hello"
git config --global user.email hello@126.com
git config --list
ssh-keygen -t rsa
cd /root/.ssh
gedit id_rsa.pub
# 下面这个可以解决Failed to connect to github.com port 443: 拒绝连接
git config --global url."https://ghproxy.com/https://github.com".insteadOf "https://github.com"
再上传这个id_rsa.pub里的文本(即公钥)
输入这行命令以验证是否成功
ssh -T git@github.com
安装golang
- 下载
下载地址
也可wget https://studygolang.com/dl/golang/go1.20.4.linux-amd64.tar.gz
- 解压
- 配环境变量
配置GOROOT(go核心内容的文件夹,即从官网下的那个)和GOPATH(go mod时存储第三方库的文件夹)
完全使用命令就是vim /etc/profile # 即刚刚解压的压缩包的文件夹 export GOROOT=/usr/local/env/go # 你自己指定一个存第三方库的文件夹 export GOPATH=/usr/local/env/gopath export PATH=$PATH:$GOROOT/bin:$GOPATH/bin #保存退出 :wq #配置生效 source /etc/profile
echo 'export GOROOT=/usr/local/env/go' >> /etc/profile echo 'export GOPATH=/usr/local/env/gopath' >> /etc/profile echo 'export PATH=$PATH:$GOROOT/bin:$GOPATH/bin' >> /etc/profile source /etc/profile
- 改下go的配置,即开启module模式和下载的镜像源
测试go env -w GO111MODULE=on go env -w GOPROXY=https://mirrors.aliyun.com/goproxy/
go version go env
- 其他
我发现每次开个新shell,都要重新source /etc/profile
才能正常使用go version
看博客知道要再配一下
注意每个用户都要配一下这个
这样子每次开新shell就会触发这个命令echo 'source /etc/profile' >> ~/.bashrc
安装neovim
参考[经验分享] Deepin
v20下编译安装vim9和neovim9,默认的vim和neovim版本太低
一、编译vim9
-
先卸载默认的vim8
sudo apt purge vim vim-* sudo apt autoremove
-
安装编译依赖
sudo apt install lua5.3 liblua5.3-dev ruby2.5-dev python3-pip cmake gettext
-
下载源码
git clone -b v9.0.1504 https://github.com/vim/vim.git ~/Downloads/vim9
-
编译与安装
cd ~/Downloads/vim9 ./configure --prefix=/opt/vim \ --with-features=huge \ --enable-multibyte \ --enable-rubyinterp=yes \ --enable-python3interp=yes \ --enable-luainterp=yes \ --enable-gui=gtk2 \ --enable-cscope \ --enable-fail-if-missing make -j6 sudo make install sudo ln -s /opt/vim/bin/vim /usr/local/bin/vim
二、编译neovim
- 下载源码
git clone -b v0.9.0 https://github.com/neovim/neovim.git ~/Downloads/neovim9
- 编译与安装
注意第二行的下载操作,可能会总是拉取不到github的项目,实在不行就进浏览器手动下,然后放在对应的位置,下载网址和放置路径在dos里都有展示cd ~/Downloads/neovim9 make CMAKE_EXTRA_FLAGS="-DCMAKE_INSTALL_PREFIX=/opt/neovim" sudo make install sudo ln -s /opt/neovim/bin/nvim /usr/local/bin/nvim
- 测试
输入nvim test.txt
- 起别名,使
vim
命令会打开nvim
echo "alias vim='nvim'" >> /etc/profile source /etc/profile
treesitter报错可以不用管
-
安装NvChad
Turning Neovim into an advanced IDE
参考视频针对Golang的NeoVim完美配置git clone https://github.com/NvChad/NvChad.git ~/.config/nvim
然后输入nvim
然后输入N
然后等他把相关的插件下完(好像挂着梯子下快一点?)
到这个界面就是下好了
然后输入空格 th
来选主题
-
两个的卸载方法:
删除~/.local/state/nvim
和~/.local/share/nvim
和~/.config/nvim
安装go的lsp
cd /root/.config/nvim/lua/custom
touch plugins.lua
在plugins.lua
中写入如下内容
local plugins = {
{
"williamboman/mason.nvim",
opts = {
ensure_installed = {
"gopls",
},
},
},
}
return plugins
再在/root/.config/nvim/lua/custom/chadrc.lua
中做如下添加
M.plugins = "custom.plugins
然后退出vim,再输入vim,输入命令:MasonInstallAll
此时等一小会会出现
再添加如下
{
"neovim/nvim-lspconfig",
config = function()
require "plugins.configs.lspconfig"
require "custom.configs.lspconfig"
end,
},
如果使用可视化的编辑器,可能会出现
E37: No write since last change
E162: No write since last change for buffer “xxxxx”
Press ENTER or type command to continue
这时用
:set fileencoding=utf-8
然后
mkdir /root/.config/nvim/lua/custom/configs
touch configs/lspconfig.lua
在lspconfig.lua中写入
local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities
local lspconfig = require("lspconfig")
local util = require "lspconfig/util"
lspconfig.gopls.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = {"gopls"},
filetypes = {"go","gomod","gowork","gotmpl"},
root_dir = util.root_pattern("go.work","go.mod",".git"),
}
再加一点设置,使得nvim里面可以自动导go的包、未使用警告等
settings = {
gopls = {
completeUnimported = true,
usePlaceholders = true,
analyses = {
unusedparams = true,
},
},
},
…不想写了,跟着视频配吧
安装Nerd字体
ubuntu系统添加新的字体——JetBrains Mono 字体添加实例
字体下载网站
用jetbrains mono即可
nvim-tree
自带,在normal模式下用ctrl n
唤出
ctrl h
和ctrl l
切换左右
其他
输入:Lazy
进入包管理界面
总结
/root/.config/nvim/lua/custom/chadrc.lua
---@type ChadrcConfig
local M = {}
M.ui = {theme = 'catppuccin'}
M.plugins = "custom.plugins"
M.mappings = require "custom.mappings"
return M
/root/.config/nvim/lua/custom/mappings.lua
local M ={}
M.dap = {
plugin = true,
n = {
["<leader>db"] = {
"<cmd> DapToggleBreakpoint <CR>",
"Add breakpoint at line"
},
["<leader>dus"] = {
function ()
local widgets = require("dap.ui.widgets");
local siderbar = widgets.sidebar(widgets.scopes);
end,
"Open debugging sidebar"
}
}
}
M.dap_go = {
plugin = true,
n = {
["<leader>dgt"] = {
function()
require("dap-go").debug_test()
end,
"Debug go test"
},
["<leader>dgl"] = {
function()
require("dap-go").debug_test()
end,
"Debug last go test"
}
}
}
return M
/root/.config/nvim/lua/custom/plugins.lua
local plugins = {
{
"williamboman/mason.nvim",
opts = {
ensure_installed = {
"gopls",
},
},
},
{
"mfussenegger/nvim-dap",
init = function()
require("core.utils").load_mappings("dap")
end
},
{
"leoluz/nvim-dap-go",
ft = "go",
dependencies = "mfussenegger/nvim-dap",
config = function(_,opts)
require("dap-go").setup(opts)
require("core.utils").load_mappings("dap_go")
end
},
{
"neovim/nvim-lspconfig",
config = function()
require "plugins.configs.lspconfig"
require "custom.configs.lspconfig"
end,
},
{
"jose-elias-alvarez/null-ls.nvim",
ft = "go",
opts = function()
return require "custom.configs.null-ls"
end,
},
{
"olexsmir/gopher.nvim",
ft="go",
config = function(_,opts)
require("gopher").setup(opts)
end,
build = function()
vim.cmd [[silent! GoInstallDeps]]
end,
},
}
return plugins
/root/.config/nvim/lua/custom/configs/lspconfig.lua
local on_attach = require("plugins.configs.lspconfig").on_attach
local capabilities = require("plugins.configs.lspconfig").capabilities
local lspconfig = require("lspconfig")
local util = require "lspconfig/util"
lspconfig.gopls.setup {
on_attach = on_attach,
capabilities = capabilities,
cmd = {"gopls"},
filetypes = {"go","gomod","gowork","gotmpl"},
root_dir = util.root_pattern("go.work","go.mod",".git"),
settings = {
gopls = {
completeUnimported = true,
usePlaceholders = true,
analyses = {
unusedparams = true,
},
},
},
}
/root/.config/nvim/lua/custom/configs/null-ls.lua
local null_ls = require("null-ls")
local augroup = vim.api.nvim_create_augroup("LspFormatting",{})
local opts = {
sources = {
null_ls.builtins.formatting.gofmt,
null_ls.builtins.formatting.goimports_reviser,
null_ls.builtins.formatting.golines,
},
on_attach = function(client,bufnr)
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({
group = augroup,
buffer = bufnr,
})
vim.api.nvim_create_autocmd("BufWritePre",{
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({bufnr = bufnr})
end,
})
end
end,
}
设置在vim中可以复制到系统剪贴板
apt install xclip
创建init.vim
vim ~/.config/nvim/init.lua
然后加入一行
vim.o.clipboard = "unnamedplus"
然后发现之后用y复制时,在浏览器里面也可以粘贴这个内容了
同时在别的地方ctrl+c复制,在vim里也可以用p粘贴