打造基于终端命令行的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>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/100300.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

手写Spring:第5章-注入属性和依赖对象

文章目录 一、目标&#xff1a;注入属性和依赖对象二、设计&#xff1a;注入属性和依赖对象三、实现&#xff1a;注入属性和依赖对象3.0 引入依赖3.1 工程结构3.2 注入属性和依赖对象类图3.3 定义属性值和属性集合3.3.1 定义属性值3.3.2 定义属性集合 3.4 Bean定义补全3.5 Bean…

《向量数据库指南》——AI原生向量数据库Milvus Cloud 2.3架构升级

架构升级 GPU 支持 早在 Milvus 1.x 版本,我们就曾经支持过 GPU,但在 2.x 版本中由于切换成了分布式架构,同时出于对于成本方面的考虑,暂时未加入 GPU 支持。在 Milvus 2.0 发布后的一年多时间里,Milvus 社区对 GPU 的呼声越来越高,再加上 NVIDIA 工程师的大力配合——为…

深度优先搜索(dfs)--矩阵部分-leetcode以及常见题

介绍 深度优先搜索&#xff08;Depth-First Search&#xff0c;DFS&#xff09;是一种常用的图搜索算法&#xff0c;它用于查找图或树数据结构中的路径或解决问题。下面是深度优先搜索的常见步骤以及一个示例问题&#xff1a; 深度优先搜索的常见步骤&#xff1a; 选择起始节…

Layui快速入门之第一节Layui的基本使用

目录 一&#xff1a;Layui的基本概念 二&#xff1a;Layui使用的基本步骤 1.在官网下载layui的基本文件&#xff0c;引入css和js文件 ①&#xff1a;普通方式引入 ②&#xff1a;第三方 CDN 方式引入 2.在script标签体中编写代码 3.测试 一&#xff1a;Layui的基本概念 …

flink学习之广播流与合流操作demo

广播流是什么&#xff1f; 将一条数据广播到所有的节点。使用 dataStream.broadCast() 广播流使用场景&#xff1f; 一般用于动态加载配置项。比如lol&#xff0c;每天不断有人再投诉举报&#xff0c;客服根本忙不过来&#xff0c;腾讯内部做了一个判断&#xff0c;只有vip3…

Hadoop的第二个核心组件:MapReduce框架第四节

Hadoop的第二个核心组件&#xff1a;MapReduce框架 十、MapReduce的特殊应用场景1、使用MapReduce进行join操作2、使用MapReduce的计数器3、MapReduce做数据清洗 十一、MapReduce的工作流程&#xff1a;详细的工作流程第一步&#xff1a;提交MR作业资源第二步&#xff1a;运行M…

升哲科技城市级“算力+数字底座”服务亮相2023服贸会

9月2日至6日&#xff0c;以“开放引领发展&#xff0c;合作共赢未来”为主题的2023年中国国际服务贸易交易会在北京隆重举办。作为城市级数据服务商&#xff0c;升哲科技&#xff08;SENSORO&#xff09;连续第四年参加服贸会&#xff0c;携城市级“算力数字底座”服务及在城市…

【Apollo】自动驾驶技术的介绍

阿波罗是百度发布的名为“Apollo&#xff08;阿波罗&#xff09;”的向汽车行业及自动驾驶领域的合作伙伴提供的软件平台。 帮助汽车行业及自动驾驶领域的合作伙伴结合车辆和硬件系统&#xff0c;快速搭建一套属于自己的自动驾驶系统。 百度开放此项计划旨在建立一个以合作为中…

halcon双目标定双相机标定

halcon双目标定 *取消更新 dev_update_off () *获取窗体句柄 dev_get_window (WindowHandle) *设置窗体字体样式 set_display_font (WindowHandle, 16, mono, true, false) *设置线条粗细 dev_set_line_width (3) *创建空对象 gen_empty_obj (ImageL) *读取指定文件内子集 li…

实现CenterNet图像分割算法模型的转换和量化(SDK0301-转ONNX编译)

一、实现CenterNet图像分割算法模型的转换和量化&#xff08;SDK0301-转ONNX编译&#xff09; 1、模型转换 &#xff08;1&#xff09;下载CenterNet算法移植代码&#xff1a; $ git clone https://github.com/sophon-ai-algo/examples.git # CenterNet示例项目代码位置 /ex…

Yolov5的tensorRT加速(python)

地址&#xff1a;https://github.com/wang-xinyu/tensorrtx/tree/master/yolov5 下载yolov5代码 方法一&#xff1a;使用torch2trt 安装torch2trt与tensorRT 参考博客&#xff1a;https://blog.csdn.net/dou3516/article/details/124538557 先从github拉取torch2trt源码 ht…

Power BI的发布到web按钮怎么没有?有人知道怎么办吗??????

Power BI的发布到web按钮怎么没有&#xff1f;有人知道怎么办吗&#xff1f;&#xff1f;&#xff1f;&#xff1f;&#xff1f; .