当前位置: 首页 > news >正文

打造基于终端命令行的IDE,Termux配置Vim C++开发环境

Termux配置Vim C++开发环境,打造基于终端命令行的IDE

主要利用Vim+Coc插件,配置C++的代码提示等功能。

Termux换源

打开termux,输入termux-change-repo

找到mirrors.tuna.tsinghua.edu.cn,清华源,空格选中,回车确认

在这里插入图片描述

Termux配置ssh

有了ssh后,就可以方便的在PC或者其它平台上,使用ssh工具远程termux终端了

# 安装
apt install open-ssh
# 启动sshd,默认端口为8022
sshd
# 关闭sshd
pkill sshd
# 查看sshd是否运行
ps aux | grep sshd

默认没有密码,使用passwd命令配置密码

ssh user@192.168.0.11 -p 8022

user用户名可以用whoami命令查看,一般termux用户名为u0_xxxx

软件包管理简介

termux使用pkg管理软件包,并且可以使用apt别名

例如更新仓库和软件:

pkg update
apt update
pkg upgrade
apt upgrade

两个命令都可以,apt命令对使用过Debian的人非常友好。以下全部使用apt

安装命令就是

apt install xxx

安装基础软件

  • vim:编辑器
  • clang:C++编译器,并且提供了g++别名
  • cmake:管理C++项目配置
  • git:源码仓库工具
  • nodejs:C++开发很少用到nodejs,主要是为vim插件提供运行环境
  • python3:提供环境
apt install vim clang cmake git nodejs python3

Vim基础配置

主要配置缩进、tab空格、文件编码、行号等,可以根据自己的需求配置

配置项非常少,很基础

vim .vimrc

编辑.vimrc文件,将以下内容输入

" vim base config
set nocompatible
syntax on
set showmode
set showcmd
set encoding=utf-8
set t_Co=256
filetype indent on
set softtabstop=4
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set number
set cursorline

安装Vim插件

  • VimPlug:用来管理Vim插件,之后的插件都需要用它来安装
  • vim-code-dark:VsCode主题

VimPlug插件管理

VimPlug主页提供了安装方法

复制下面的命令到终端并执行

curl -fLo ~/.vim/autoload/plug.vim --create-dirs \https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

安装完成后编辑.vimrc文件,添加如下代码段

" plugin
call plug#begin()Plug 'xxx'call plug#end()

中间的Plug 'xxx',就是代表安装xxx插件,每个插件一行

每当想安装新的插件时,先编辑vimrc,再重新进入vim命令模式,输入:PlugInstall就会安装插件

卸载插件时,编辑vimrc,删除插件那一行,然后进入vim命令模式,输入:PlugClean,不在列表里的插件就会被清理

:PlugUpdate更新插件

:PlugUpgrade更新VimPlug本身

VsCode颜色主题

Vim自己的高亮不好看,我选择了VsCode主题

Plug 'tomasiser/vim-code-dark'

添加上述代码,重新打开vim并运行PlugInstall,出现Finishing … Done!且插件名称后面显示100%时,说明安装成功

在这里插入图片描述

再次编辑vimrc,添加如下代码

colorscheme codedark

再次打开vim时,已经变为VsCode主题

在这里插入图片描述

Coc代码提示

参考Coc主页,安装方式如下:

Plug 'neoclide/coc.nvim', {'branch': 'release'}

同样,运行:PlugInstall就可以安装,Coc依赖于NodeJs

Coc是类似VimPlug的管理工具,具体的语言支持还需要安装语言包

其插件列表可以在CocWiki看到

注意,这里的插件指的是Coc插件,他们往往都按照coc-xxx命名,例如coc-clangd、coc-json等

安装插件需要使用:CocInstall命令,例如:

CocInstall coc-json coc-tsserver

Coc也需要配置,配置很多,我也没看明白,官网给了一个示例,主要是配置快捷键补全等功能。

对于C++开发环境,需要的Coc插件有

  • coc-clangd:提供C++语言服务支持
  • coc-cmake:提供cmake支持

coc-clangd

安装coc-clangd,依赖于clangd,在termux中使用apt install clang来安装

:ConInstall coc-clangd

安装完成后,可以编辑一个cpp文件尝试效果,Tab用来选择候选项,Enter用来确认

对于多文件项目或者CMake项目,插件需要读取compile_commands.json文件,这个文件需要在编译时生成。

CMake在构建项目时生成该文件,指令为:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=TRUE
  • -S指定源代码文件夹
  • -B指定输出目录
  • -DCMAKE_BUILD_TYPE设置构建类型
  • -DCMAKE_EXPORT_COMPILE_COMMANDS指定生成compile_commands.json文件

在这里插入图片描述

coc-cmake

依赖cmake lsp

pip install cmake-language-server
:CocInstall coc-cmake

然后就可以使用了

括号补全

使用auto-pairs插件

Plug 'jiangmiao/auto-pairs'

无需任何配置

代码格式化

使用vim-clang-format插件,参考其主页安装

依赖于clang-format,在Termux下,安装clang就行

Plug 'rhysd/vim-clang-format'

安装完成后,可以参考如下代码或者ClangFormat主页配置格式化风格:

let g:clang_format#code_style='WebKit'

格式化命令为:ClangFormat

为了方便,把Ctrl+Shift+i映射为该命令,在常规模式下有效:

nnoremap <C-S-i> :ClangFormat<CR>

缩进参考线

indentLine插件

Plug 'Yggdroot/indentLine'

无需配置

在这里插入图片描述

最终vimrc源码

" vim base config
set nocompatible
syntax on
set showmode
set showcmd
set encoding=utf-8
set t_Co=256
filetype indent on
set softtabstop=4
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set number
set cursorline" vim plug
call plug#begin()Plug 'tomasiser/vim-code-dark'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'jiangmiao/auto-pairs'
Plug 'rhysd/vim-clang-format'
Plug 'Yggdroot/indentLine'call plug#end()" vscode theme
colorscheme codedark
" Clang Format
let g:clang_format#code_style='WebKit'
nnoremap <C-S-i> :ClangFormat<CR>" =================================== Coc Config ==================
" Use tab for trigger completion with characters ahead and navigate
" NOTE: There's always complete item selected by default, you may want to enable
" no select by `"suggest.noselect": true` in your configuration file
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config
inoremap <silent><expr> <TAB>\ coc#pum#visible() ? coc#pum#next(1) :\ CheckBackspace() ? "\<Tab>" :\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"function! CheckBackspace() abortlet col = col('.') - 1return !col || getline('.')[col - 1]  =~# '\s'
endfunction" Use <c-space> to trigger completion
if has('nvim')inoremap <silent><expr> <c-space> coc#refresh()
elseinoremap <silent><expr> <c-@> coc#refresh()
endif" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)" GoTo code navigation
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)" Use K to show documentation in preview window
nnoremap <silent> K :call ShowDocumentation()<CR>function! ShowDocumentation()if CocAction('hasProvider', 'hover')call CocActionAsync('doHover')elsecall feedkeys('K', 'in')endif
endfunction" Highlight the symbol and its references when holding the cursor
autocmd CursorHold * silent call CocActionAsync('highlight')" Symbol renaming
nmap <leader>rn <Plug>(coc-rename)" Formatting selected code
xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)augroup mygroupautocmd!" Setup formatexpr specified filetype(s)autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')" Update signature help on jump placeholderautocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end" Applying code actions to the selected code block
" Example: `<leader>aap` for current paragraph
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>a  <Plug>(coc-codeaction-selected)" Remap keys for applying code actions at the cursor position
nmap <leader>ac  <Plug>(coc-codeaction-cursor)
" Remap keys for apply code actions affect whole buffer
nmap <leader>as  <Plug>(coc-codeaction-source)
" Apply the most preferred quickfix action to fix diagnostic on the current line
nmap <leader>qf  <Plug>(coc-fix-current)" Remap keys for applying refactor code actions
nmap <silent> <leader>re <Plug>(coc-codeaction-refactor)
xmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)
nmap <silent> <leader>r  <Plug>(coc-codeaction-refactor-selected)" Run the Code Lens action on the current line
nmap <leader>cl  <Plug>(coc-codelens-action)" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server
xmap if <Plug>(coc-funcobj-i)
omap if <Plug>(coc-funcobj-i)
xmap af <Plug>(coc-funcobj-a)
omap af <Plug>(coc-funcobj-a)
xmap ic <Plug>(coc-classobj-i)
omap ic <Plug>(coc-classobj-i)
xmap ac <Plug>(coc-classobj-a)
omap ac <Plug>(coc-classobj-a)" Remap <C-f> and <C-b> to scroll float windows/popups
if has('nvim-0.4.0') || has('patch-8.2.0750')nnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"nnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"inoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(1)\<cr>" : "\<Right>"inoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? "\<c-r>=coc#float#scroll(0)\<cr>" : "\<Left>"vnoremap <silent><nowait><expr> <C-f> coc#float#has_scroll() ? coc#float#scroll(1) : "\<C-f>"vnoremap <silent><nowait><expr> <C-b> coc#float#has_scroll() ? coc#float#scroll(0) : "\<C-b>"
endif" Use CTRL-S for selections ranges
" Requires 'textDocument/selectionRange' support of language server
nmap <silent> <C-s> <Plug>(coc-range-select)
xmap <silent> <C-s> <Plug>(coc-range-select)" Add `:Format` command to format current buffer
command! -nargs=0 Format :call CocActionAsync('format')" Add `:Fold` command to fold current buffer
command! -nargs=? Fold :call     CocAction('fold', <f-args>)" Add `:OR` command for organize imports of the current buffer
command! -nargs=0 OR   :call     CocActionAsync('runCommand', 'editor.action.organizeImport')" Add (Neo)Vim's native statusline support
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}" Mappings for CoCList
" Show all diagnostics
nnoremap <silent><nowait> <space>a  :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent><nowait> <space>e  :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent><nowait> <space>c  :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent><nowait> <space>o  :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent><nowait> <space>s  :<C-u>CocList -I symbols<cr>
" Do default action for next item
nnoremap <silent><nowait> <space>j  :<C-u>CocNext<CR>
" Do default action for previous item
nnoremap <silent><nowait> <space>k  :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent><nowait> <space>p  :<C-u>CocListResume<CR>

相关文章:

打造基于终端命令行的IDE,Termux配置Vim C++开发环境

Termux配置Vim C开发环境&#xff0c;打造基于终端命令行的IDE 主要利用VimCoc插件&#xff0c;配置C的代码提示等功能。 Termux换源 打开termux&#xff0c;输入termux-change-repo 找到mirrors.tuna.tsinghua.edu.cn&#xff0c;清华源&#xff0c;空格选中&#xff0c;回…...

【初阶C语言】操作符2---表达式求值

前言&#xff1a;本节重点介绍操作符的使用&#xff0c;如&#xff0c;优先级高低、类型转换等 一、逻辑操作符 前言&#xff1a;逻辑操作符包括逻辑与&#xff08;&&&#xff09;和逻辑或&#xff08;||&#xff09;&#xff0c;操作对象&#xff1a;两个 1.逻辑与&…...

代码随想录day50|123. 买卖股票的最佳时机 III188. 买卖股票的最佳时机 IV

123. 买卖股票的最佳时机 III class Solution:def maxProfit(self, prices: List[int]) -> int:dp[[0]*5 for _ in range(len(prices))]dp[0][0]0dp[0][1]-prices[0]dp[0][2]0dp[0][3]-prices[0]dp[0][4]0for i in range(1,len(prices)):dp[i][0] dp[i-1][0]dp[i][1] max…...

Word 表格单元格无法垂直居中

Word使用 由于平时也需要用到word编写一些文档&#xff0c;但是咱们就是用的少&#xff0c;很多操作或者技巧不太清楚&#xff0c;很多小问题处理起来反而需要消耗很多时间&#xff0c;所以在这里记录平时遇到的一些问题。 表格无法垂直居中 类似于上图的情况&#xff0c;总之…...

python实现Flask POST Demo

数据处理逻辑 from flask import Flask, requestapp Flask(__name__)app.route(/, methods[POST]) def index():username request.form[username]password request.form[password]if username "Jhon" and password "1":return f"<html>&l…...

3-Pytorch张量的运算、形状改变、自动微分

3-Pytorch张量的运算、形状改变、自动微分 1 导入必备库2 张量的运算3 张量的算数运算4 一个元素的张量可以使用tensor.item()方法转成标量5 torch.from_numpy()和tensor.numpy()6 张量的变形7 张量的自动微分8 使用with torch.no_grad():包含上下文中使其不再跟踪计算9 使用te…...

用户权限数据转换为用户组列表(3/3) - Excel PY公式

最近Excel圈里的大事情就是微软把PY塞进了Excel单元格&#xff0c;可以作为公式使用&#xff0c;轻松用PY做数据分析。系好安全带&#xff0c;老司机带你玩一把。 实例需求&#xff1a;如下是AD用户的列表,每个用户拥有该应用程序的只读或读写权限&#xff0c;现在需要创建新的…...

VS2022+CMAKE+OPENCV+QT+PCL安装及环境搭建

VS2022安装&#xff1a; Visual Studio 2022安装教程&#xff08;千字图文详解&#xff09;&#xff0c;手把手带你安装运行VS2022以及背景图设置_vs安装教程_我不是大叔丶的博客-CSDN博客 CMAKE配置&#xff1a; win11下配置vscodecmake_心儿痒痒的博客-CSDN博客 OPENCV配…...

JavaScript的内置类

一、认识包装类型 1.原始类型的包装类 JavaScript的原始类型并非对象类型&#xff0c;所以从理论上来说&#xff0c;它们是没有办法获取属性或者调用方法的。 但是&#xff0c;在开发中会看到&#xff0c;我们会经常这样操作&#xff1a; var message "hello world&q…...

6.英语的十六种时态(三面旗):主动、被动、肯定、否定、一般疑问句、特殊疑问句。

目录 一、do句型&#xff08;以动词allow举例&#xff09;。 &#xff08;1&#xff09;主动语态表格。 &#xff08;2&#xff09;被动语态表格。 &#xff08;3&#xff09;否定。 二、be句型&#xff08;表格里的时态可以参考&#xff0c;查不到对应的资料&#xff09;…...

SpringBoot连接Redis与Redisson【代码】

系列文章目录 一、SpringBoot连接MySQL数据库实例【tk.mybatis连接mysql数据库】 二、SpringBoot连接Redis与Redisson【代码】 三、SpringBoot整合WebSocket【代码】 四、SpringBoot整合ElasticEearch【代码示例】 文章目录 系列文章目录代码下载地地址一、引入依赖二、修改配…...

ardupilot开发 --- MAVSDK 篇

概述 MAVSDK是各种编程语言的库集合&#xff0c;用于与MAVLink系统&#xff08;如无人机、相机或地面系统&#xff09;接口。这些库提供了一个简单的API&#xff0c;用于管理一个或多个车辆&#xff0c;提供对车辆信息和遥测的程序访问&#xff0c;以及对任务、移动和其他操作…...

腾讯云AI超级底座新升级:训练效率提升幅度达到3倍

大模型推动AI进入新纪元&#xff0c;对计算、存储、网络、数据检索及调度容错等方面提出了更高要求。在9月7日举行的2023腾讯全球数字生态大会“AI超级底座专场”上&#xff0c;腾讯云介绍异构计算全新产品矩阵“AI超级底座”及其新能力。 腾讯云副总裁王亚晨在开场致辞中表示&…...

AB测试结果分析

一、假设检验 根据样本&#xff08;小流量&#xff09;的观测结果&#xff0c;拒绝或接受关于总体&#xff08;全部流量&#xff09;的某个假设&#xff0c;称为假设检验。 假设检验的基本依据是小概率事件原理&#xff08;小概率事件几乎不发生&#xff09;&#xff0c;如果…...

Python模块和包:sys模块、os模块和变量函数的使用

文章目录 模块&#xff08;module&#xff09;引入外部模块引入部分内容包 (package)示例代码开箱即用sys模块sys.argvsys.modulessys.pathsys.platformsys.exit() os模块os.environos.system()os模块中的变量、函数和类 测试代码模块中的变量和函数的使用 总结&#xff1a;pyt…...

计算机软件工程毕业设计题目推荐

文章目录 0 简介1 如何选题2 最新软件工程毕设选题3 最后 0 简介 学长搜集分享最新的软件工程业专业毕设选题&#xff0c;难度适中&#xff0c;适合作为毕业设计&#xff0c;大家参考。 学长整理的题目标准&#xff1a; 相对容易工作量达标题目新颖 1 如何选题 最近非常多的…...

嵌入式学习笔记(25)串口通信的基本原理

三根通信线&#xff1a;Tx Rx GND &#xff08;1&#xff09;任何通信都要有信息作为传输载体&#xff0c;或者有线的或则无线的。 &#xff08;2&#xff09;串口通信时有线通信&#xff0c;是通过串口线来通信的。 &#xff08;3&#xff09;串口通信最少需要2根&#xff…...

c++学习第十三

1)循环引用的案例及解决办法: #include <iostream> #include <memory> using namespace std; class A;class B { public:B(){cout<<"B constructor---"<<endl;}~B(){cout<<"B deconstructor----"<<endl;}std::weak_…...

java复习-线程的同步和死锁

线程的同步和死锁 同步问题引出 当多个线程访问同一资源时&#xff0c;会出现不同步问题。比如当票贩子A&#xff08;线程A&#xff09;已经通过了“判断”&#xff0c;但由于网络延迟&#xff0c;暂未修改票数的间隔时间内&#xff0c;票贩子B&#xff08;线程B&#xff09;…...

Qt指示器设置

目录 1. 样式设置 2. 行为设置 3. 交互设置 创建一个进度指示器控件 在Qt中设置指示器&#xff08;Indicator&#xff09;的外观和行为通常需要操作相关部件的属性和样式表。以下是如何在Qt中设置指示器的一些常见方式&#xff1a; 1. 样式设置 你可以使用样式表&#xf…...

调用支付宝接口响应40004 SYSTEM_ERROR问题排查

在对接支付宝API的时候&#xff0c;遇到了一些问题&#xff0c;记录一下排查过程。 Body:{"datadigital_fincloud_generalsaas_face_certify_initialize_response":{"msg":"Business Failed","code":"40004","sub_msg…...

RocketMQ延迟消息机制

两种延迟消息 RocketMQ中提供了两种延迟消息机制 指定固定的延迟级别 通过在Message中设定一个MessageDelayLevel参数&#xff0c;对应18个预设的延迟级别指定时间点的延迟级别 通过在Message中设定一个DeliverTimeMS指定一个Long类型表示的具体时间点。到了时间点后&#xf…...

系统设计 --- MongoDB亿级数据查询优化策略

系统设计 --- MongoDB亿级数据查询分表策略 背景Solution --- 分表 背景 使用audit log实现Audi Trail功能 Audit Trail范围: 六个月数据量: 每秒5-7条audi log&#xff0c;共计7千万 – 1亿条数据需要实现全文检索按照时间倒序因为license问题&#xff0c;不能使用ELK只能使用…...

srs linux

下载编译运行 git clone https:///ossrs/srs.git ./configure --h265on make 编译完成后即可启动SRS # 启动 ./objs/srs -c conf/srs.conf # 查看日志 tail -n 30 -f ./objs/srs.log 开放端口 默认RTMP接收推流端口是1935&#xff0c;SRS管理页面端口是8080&#xff0c;可…...

Axios请求超时重发机制

Axios 超时重新请求实现方案 在 Axios 中实现超时重新请求可以通过以下几种方式&#xff1a; 1. 使用拦截器实现自动重试 import axios from axios;// 创建axios实例 const instance axios.create();// 设置超时时间 instance.defaults.timeout 5000;// 最大重试次数 cons…...

以光量子为例,详解量子获取方式

光量子技术获取量子比特可在室温下进行。该方式有望通过与名为硅光子学&#xff08;silicon photonics&#xff09;的光波导&#xff08;optical waveguide&#xff09;芯片制造技术和光纤等光通信技术相结合来实现量子计算机。量子力学中&#xff0c;光既是波又是粒子。光子本…...

网站指纹识别

网站指纹识别 网站的最基本组成&#xff1a;服务器&#xff08;操作系统&#xff09;、中间件&#xff08;web容器&#xff09;、脚本语言、数据厍 为什么要了解这些&#xff1f;举个例子&#xff1a;发现了一个文件读取漏洞&#xff0c;我们需要读/etc/passwd&#xff0c;如…...

安卓基础(Java 和 Gradle 版本)

1. 设置项目的 JDK 版本 方法1&#xff1a;通过 Project Structure File → Project Structure... (或按 CtrlAltShiftS) 左侧选择 SDK Location 在 Gradle Settings 部分&#xff0c;设置 Gradle JDK 方法2&#xff1a;通过 Settings File → Settings... (或 CtrlAltS)…...

【Elasticsearch】Elasticsearch 在大数据生态圈的地位 实践经验

Elasticsearch 在大数据生态圈的地位 & 实践经验 1.Elasticsearch 的优势1.1 Elasticsearch 解决的核心问题1.1.1 传统方案的短板1.1.2 Elasticsearch 的解决方案 1.2 与大数据组件的对比优势1.3 关键优势技术支撑1.4 Elasticsearch 的竞品1.4.1 全文搜索领域1.4.2 日志分析…...

API网关Kong的鉴权与限流:高并发场景下的核心实践

&#x1f525;「炎码工坊」技术弹药已装填&#xff01; 点击关注 → 解锁工业级干货【工具实测|项目避坑|源码燃烧指南】 引言 在微服务架构中&#xff0c;API网关承担着流量调度、安全防护和协议转换的核心职责。作为云原生时代的代表性网关&#xff0c;Kong凭借其插件化架构…...