【vimsolo】让vim看起来像VSCode:颜色主题和状态栏的配置

news/2024/10/18 2:42:00/

文章目录

    • 1. 目的
    • 2. 理念: vimsolo
    • 3. vimrc: 配置颜色
    • 4. vimrc: 配置状态栏
    • 5. 拷贝颜色主题和.vimrc: python安装脚本

在这里插入图片描述

1. 目的

习惯了 VSCode 默认的配色:黑色主题,蓝色状态栏。偶尔使用 Vim 时想让 vim 伪装的像 VSCode,不考虑花里花哨的插件和动态效果,静态效果上让 vim 看起来像 VSCode,怎样实现呢?

2. 理念: vimsolo

vimsolo = vim + solo,除了颜色主题可以用第三方插件, 其他配置都用 .vimrc 手工完成,不依赖库插件。

vimsolo 的理念是: vim 插件如果装多了,配置繁杂,受网络影响较大,还需要适配不同 vim/nvim 版本和 nerdfont 字体, 而是极致的简洁。

3. vimrc: 配置颜色

VSCode 颜色主题的 vim 插件有好几个, 我用的是 codedark https://github.com/tomasiser/vim-code-dark

vimrc 中的配置代码:
在这里插入图片描述

"--- color theme
set background=dark
tryset t_Co=256set t_ut=colorscheme codedark""colorscheme molokai
catchtrycolorscheme desertcatchcolorscheme peakseaendtry
endtry

用 vim 打开 Python 文件看看效果:
在这里插入图片描述

4. vimrc: 配置状态栏

状态栏的插件有很多,很容易陷入选择的困境,因为都太漂亮了;而一一尝试和配置会花费不少时间,但容易漂浮在插件开发者配置的表层。其实基于 vimL 徒手可以写一个 statuline:

  • 本质是给变量 statusline 赋值
  • 把 statueline 拆分为n部分,每部分是一个字符串变量,变量之间用 . 连接起来
  • 每部分大都可以从 vim 自带的变量或函数获取到,例如文件编码是 let l:encoding = ' %{&fenc} '

在这里插入图片描述
具体配置 vimL 脚本如下:

"======================================================================
" statusline
"======================================================================
"--- https://bruhtus.github.io/posts/vim-statusline/
"--- https://jdhao.github.io/2019/11/03/vim_custom_statusline/
" component for active window
function! StatuslineActive()" if we want to add `f` items in our statuslinelet g:currentmode={\ 'n'  : 'NORMAL',\ 'v'  : 'VISUAL',\ 'V'  : 'V·Line',\ "\<C-V>" : 'V·Block',\ 'i'  : 'INSERT',\ 'R'  : 'R',\ 'Rv' : 'V·Replace',\ 'c'  : 'Command',\}"let l:current_mode = mode()let l:current_mode = ' ['.'%{toupper(g:currentmode[mode()])}'.'] '" if we want to add 'm' items in our statuslinelet l:cursor_position = ' Ln %l, Col %c'let l:indentation = ' %{(&expandtab=="1") ? "Spaces: ".&tabstop : "Tabs: ".&tabstop} 'let l:encoding = ' %{&fenc} 'let l:end_of_line_sequence = ' %{(&fileformat=="dos")? "CRLF" : "LF"} 'let l:percent = ' %p%% 'let l:language_mode = '%{&filetype}'" the `.` is basically to ignore whitespace before and put it right after the previous componentlet l:statusline_left = l:current_modelet l:statusline_middle = ''let l:statusline_right = l:cursor_position.l:indentation.l:encoding.l:end_of_line_sequence.l:percent.l:language_modereturn l:statusline_left.'%='.l:statusline_middle.'%='.l:statusline_right
endfunction" component for inactive window
function! StatuslineInactive()" the component goes here
endfunction" load statusline using `autocmd` event with this function
function! StatuslineLoad(mode)if a:mode ==# 'active'" to make it simple, %! is to evaluate the current changes in the window" it can be useful for evaluate current mode in statusline. For more info:" :help statusline.setlocal statusline=%!StatuslineActive()elsesetlocal statusline=%!StatuslineInactive()endif
endfunction" so that autocmd didn't stack up and slow down vim
augroup statusline_startupautocmd!" for more info :help WinEnter and :help BufWinEnterautocmd WinEnter,BufWinEnter * call StatuslineLoad('active')autocmd WinLeave * call StatuslineLoad('inactive')
augroup ENDhi StatusLine ctermbg=32 ctermfg=254 guibg=#007acc guifg=#dfe9ed
"hi StatusLineNC ctermbg=240 ctermfg=240 guibg=#d0d0d0 guifg=#444444hi StatusLineTerm ctermbg=32 ctermfg=254 guibg=#007acc guifg=#dfe9ed
"hi StatusLineTermNC ctermbg=252 ctermfg=240 guibg=#d0d0d0 guifg=#444444
"-- #007acc
"-- #dfe9ed

配置效果:
在这里插入图片描述

5. 拷贝颜色主题和.vimrc: python安装脚本

使用 Python 编写了安装脚本,相比于 shell 脚本,开发效率相当高, 平台兼容性更强。

import os
import shutil
import subprocess
import platformdef is_wsl():return 'microsoft-standard' in platform.uname().releasedef is_windows():return platform.system().lower() == "windows"def is_linux():return platform.system().lower() == "linux"def is_macosx():return platform.system().lower() == "darwin"class CommandRunner(object):@staticmethoddef run(cmd, verbose = True):if (verbose):print('Executing cmd:', cmd)process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)if is_windows():# encoding = 'ISO-8859-1'encoding = 'gbk'else:encoding = 'utf-8'#print('encoding:', encoding)out_bytes = process.communicate()[0]err_bytes = process.communicate()[1]out_msg = out_bytes.decode(encoding)err_msg = out_bytes.decode(encoding)if (verbose):print('Command executing stdout: {:s}'.format(out_msg))print('Command executing stderr: {:s}'.format(err_msg))return out_msg, err_msgdef is_windows_git_bash():d = 'C:\\Users'return os.path.exists(d) and os.path.isdir(d)def path_to_proper_abs_path(p):p_abs = os.path.abspath(p)if (is_windows_git_bash()):disk, remain = p_abs.split(':')res = "/{:s}/{:s}".format(disk, remain[1:])res = res.replace("\\", "/")else:res = p_absreturn resdef copy_or_link_file(src, dst):# if is_windows_git_bash():#     shutil.copyfile(src, dst)# else:if (os.path.exists(dst)):os.remove(dst)elif (os.path.islink(dst)):os.remove(dst)src_abs = path_to_proper_abs_path(src) #os.path.abspath(src)dst_abs = path_to_proper_abs_path(dst) # os.path.abspath(dst)cmd = "ln -sf {:s} {:s}".format(src_abs, dst_abs)CommandRunner.run(cmd, True)def copy_colors_dir(src_color_dir, dst_color_dir):os.makedirs(dst_color_dir, exist_ok=True)for item in os.listdir('colors'):src = 'colors/' + itemdst = dst_color_dir + '/' + itemcopy_or_link_file(src, dst)def get_vim_first_default_runtimepath():if (is_windows()):# return os.path.expanduser('~/vimfiles') # not working on windows 11return os.path.expanduser('~/.vim')elif is_macosx():return os.path.expanduser('~/vimfiles')elif is_linux():return os.path.expanduser('~/.vim')def copy_vim_config():# copy .vimrcsrc = '.vimrc'dst = os.path.expanduser('~/.vimrc')copy_or_link_file(src, dst)vim_cfg_dir = os.path.expanduser('~/.vim')# copy colors dirrtp = get_vim_first_default_runtimepath()copy_colors_dir('colors', rtp + "/colors")# create undodirundodir = '{:s}/temp_dirs/undodir'.format(vim_cfg_dir)os.makedirs(undodir, exist_ok=True)if __name__ == '__main__':copy_vim_config()

http://www.ppmy.cn/news/69808.html

相关文章

Verilog语法概述二:何为仿真?仿真可以在几个层面上进行?

Verilog 是一种用于数字逻辑电路设计的硬件描述语言&#xff0c;可以用来进行数字电路的仿真验证、时序分析、逻辑综合。 既是一种行为级&#xff08;可用于电路的功能描述&#xff09;描述语言又是一种结构性&#xff08;可用于元器件及其之间的连接&#xff09;描述语言。 …

方差分析 python中运行stata

方差分析 文章目录 方差分析[toc]1 单因素方差分析2 多因素方差分析 # 配置stata17在jupyter 配置 import stata_setup stata_setup.config(r"D:\Stata17\setup",se)1 单因素方差分析 from pystata import stata # 查看单因素方差分析命令介绍 stata.run("help…

springcloud基于web的智慧养老平台

系统分析 可行性分析 在开发系统之前要进行系统可行性分析&#xff0c;目的是在用最简单的方法去解决最大的问题&#xff0c;程序一旦开发出来满足了用户的需要&#xff0c;所带来的利益也很多。下面我们将从技术、操作、经济等方面来选择这个系统最终是否开发。 1、技术可行…

如何用R语言分析COVID-19相关数据

一、概述 COVID-19是当前全球面临的一项重大挑战。 本文将介绍如何使用R语言分析COVID-19相关数据&#xff0c;探索其感染率、死亡率和人口特征的相关性&#xff0c;以及使用统计建模方法预测COVID-19的死亡率。 二、数据导入与筛选 COVID-19 Data Repository by the Center…

hive实操大全,目前最全最详细的了

本篇博客是hive操作的详细记录及案例实操,原稿是来自尚硅谷的老师 目录 第一章.hive的基本概念1.1hive是什么1.2 hive的优缺点1.3 hive的架构1.4 Hive和数据库区别第二章.安装2.1hive的常用交互命令2.2hive的参数配置方式第三章.hive的数据类型3.1 基本数据类型3.2 集合数据类…

银豆信息张雪灿:钻石级合作伙伴的增长秘诀

编者按&#xff1a; 杭州银豆信息技术有限公司&#xff08;简称“银豆”&#xff09;&#xff0c;是一家专注于云计算服务的高科技企业&#xff0c;目前已为2000家企业级客户提供了专业的行业解决方案, 与人民网、光大银行、长安汽车金融、vivo金融、浙江省农科院、淄博市大数…

ViLT论文精读笔记

ViLT论文精读笔记 0.摘要1.引言2.背景知识&#xff08;小综述&#xff09;2.1对VLP模型分类2.2模态的融合2.3融合前特征的抽取 3.模型方法3.1预训练目标函数&#xff1a;3.1.1 Image Text Matching&#xff1a;3.1.2 Masked Language Modeling3.1.3 Masked Image Modeling 3.2W…

Linux速通 常用基本命令

大部分摘自《Linux 命令行与shell脚本编程大全》该书&#xff0c;少部分参考自csdn博客 目录 一、基本的bash shell 命令 1、文件和目录列表 基本列表功能 修改输出信息 过滤输出列表 2、处理文件 3、处理目录 4、查看文件内容 查看整个文件 查看部分文件 二、更多的…