windows下在vim中搭建C/C++语言开发环境

1 代码格式化

C语言代码的格式化需要使用clang-format,而clang-format被集成在了llvm中,所以需要先安装llvm点击此处下载

注:若vim为32位,则下载32位的llvm

在这里插入图片描述
下载之后运行安装文件,将其中的bin目录添加到环境变量path中(需重启电脑使新添加的环境变量生效)。例如我安装后的目录为C:\wsr (x86)\LLVM\bin,图中的clang-format就是格式化c代码需要的组件

在这里插入图片描述

在这里插入图片描述

1.1 clang-format初体验

C:\Users\fy\Desktop\test1.c为例,在powershell或cmd中执行如下命令:

PS C:\Users\fy> cd 'C:\wsr (x86)\LLVM\bin\'
PS C:\wsr (x86)\LLVM\bin> .\clang-format.exe -style=google -i C:\Users\fy\Desktop\test1.c
// 格式化前
#include <stdio.h>

int main(int argc, char *argv[])
{
    int a[2][2] = {{1,2}
    ,
        {3,4}};
    printf("Hello World!\n");
            printf("Hello World!\n");
        printf("Hello World!\n");
printf("Hello World!\n");

    return 0;
}

// 格式化后
#include <stdio.h>

int main(int argc, char *argv[]) {
  int a[2][2] = {{1, 2}, {3, 4}};
  printf("Hello World!\n");
  printf("Hello World!\n");
  printf("Hello World!\n");
  printf("Hello World!\n");

  return 0;
}
clang-foramt用法clang-format -style=xxx -i ***.c
-style表示风格,可选项为 LLVM、Google、Chromium、Mozilla、
WebKit 和 file,其中 file 指定参数文件
-i表示将格式化后的内容写入原文件

如:

clang-format -style=Chromium -i C:\Users\fy\Desktop\test1.c
clang-format -style=LLVM -i C:\Users\fy\Desktop\test1.c
clang-format -style=google -i C:\Users\fy\Desktop\test1.c
clang-format -style=WebKit -i C:\Users\fy\Desktop\test1.c

也可以通过-style='{key1: value1, key2: value2, ...}'来添加更个性化的格式化选项:

clang-format.exe -i -style='{BasedOnStyle: llvm, AlignConsecutiveMacros: true, ColumnLimit: 80}' xxx.cpp

更多格式化选项请参考CLANG-FORMAT STYLE OPTIONS

1.2 在vim中格式化c代码

1.2.1 使用外部命令

既然已经有了clang-foramt.exe,则可以在vim中通过执行外部命令来格式化代码。在.vimrc中添加如下配置:

nnoremap <leader>cf :call FormatSrc()<CR>
func! FormatSrc()
    exec "w"
    " Use clang-format to format C/C++ source file. Make sure llvm is installed
    " and /path/to/llvm/bin is added to the environment variable path.
    " Otherwise, use !/path/to/llvm/bin/clang-format.exe instead of !clang-format
    if ( &filetype == 'cpp' || &filetype == 'c' )
        exec 'silent !clang-format -i -style="{'
                \ .'BasedOnStyle: llvm,'
                \ .'AlignConsecutiveMacros : true,'
                \ .'AlignEscapedNewlines: Left,'
                \ .'BreakBeforeBraces: Stroustrup,'
                \ .'ColumnLimit: 80,'
                \ .'IndentWidth: 4'
                \ .'}" %'
    " Use black to format python source file. Make sure black is installed.
    " If not, execute command 'pip install black' to install
    elseif &filetype == 'python'
        exec "silent !c:/wsr/python/python39/Scripts/black %"
    " pip install jsbeautifier
    elseif &filetype == 'javascript'
        exec "silent !c:/wsr/python/python39/Scripts/js-beautify.exe -r %"
    " visit url 'https://github.com/mvdan/sh/releases/' to download shfmt
    elseif &filetype == 'sh'
        exec "silent !e:/toolbox/shfmt/shfmt.exe -l -w %"
    " execute command 'Install-Module -Name PowerShell-Beautifier' in powershell
    " to install PowerShell-Beautifier
    elseif &filetype == 'ps1'
        exec "silent !powershell Edit-DTWBeautifyScript % -IndentType FourSpaces"
    " execute command 'cpanm Perl::Tidy' to install perl-tidy
    elseif &filetype == 'perl'
        " exec 'silent !perltidy -b %'
        exec "silent % !perltidy"
    endif
endfunc

那么在normal mode下按下<leader>cf就能格式化当前编辑的源程序了。

1.2.2 使用插件

1.2.2.1 为vim配置python

由于配置环境过程中用到的插件与vim使用的python版本有关,所以下面先为vim配置python。首先,打开vim,在命令行模式下输入:version,查看所使用的vim是否支持python,以及支持的python版本

在这里插入图片描述

在这里插入图片描述

从输出可以看出,我用的vim是32位的vim8.2,此版本支持python,且所用的python版本为python2.7及python3.6

打开python官网,下载32位的python2.7及python3.6,我下载的为2.7.18和3.6.8
https://www.python.org/ftp/python/3.6.8/python-3.6.8.exe
https://www.python.org/ftp/python/2.7.18/python-2.7.18.msi
下载好之后将两个版本的python分别安装(若已安装过其他版本python不用卸载)。这里安装时自定义安装目录,不要为其设置环境变量

我的自定义安装目录如下所示:

C:\wsr (x86)\python\python27
C:\wsr (x86)\python\python36

编辑vim的配置文件.gvimrc,在其中添加如下设置项(目录路径中有空格的话,在空格前添加一个\):

set pythondll=C:\wsr\ (x86)\python\python27\python27.dll
set pythonhome=C:\wsr\ (x86)\python\python27
set pythonthreedll=C:\wsr\ (x86)\python\python36\python36.dll
set pythonthreehome=C:\wsr\ (x86)\python\python36

然后在vim命令行模式执行:source $MYGVIMRC,使改动生效。

1.2.2.2 安装代码格式化插件

安装代码格式化插件vim-clang-format,打开powershell,执行命令(这里没有使用插件管理器安装插件):

PS C:\Users\fy\vimfiles\pack\my_plugins\start> git clone https://github.com/rhysd/vim-clang-format.git vim-clang-format

打开vim,在命令行模式下,执行:ClangFormat,则源文件就被格式化了:
在这里插入图片描述

也可以在.gvimrc中为vim-clang-format设置快捷键:

" 代码风格的自定义设置
let g:clang_format#style_options = {
            \ "AlignConsecutiveMacros" : "true",
            \ "AlignEscapedNewlines": "Left",
            \ "BreakBeforeBraces": "Stroustrup",
            \ "BreakBeforeTernaryOperators": "true",
            \ "IndentPPDirectives": "AfterHash" }

" 使用 <Leader>cf 格式化代码
autocmd FileType c,cpp,objc nnoremap <buffer><Leader>cf :<C-u>ClangFormat
autocmd FileType c,cpp,objc vnoremap <buffer><Leader>cf :ClangFormat
" Toggle auto formatting:
nmap <Leader>C :ClangFormatAutoToggle

2 代码片段(snippet)

代码自动补全需要安装插件vim-snippetsultisnips

PS C:\Users\fy\vimfiles\pack\my_plugins\start> git clone https://github.com/honza/vim-snippets.git vim-snippets
PS C:\Users\fy\vimfiles\pack\my_plugins\start> git clone https://github.com/SirVer/ultisnips.git ultisnips

安装完成之后,就可以在vim中使用代码自动补全了。使用vim编辑test2.c

输入 inc、按Tab键
输入 main、按Tab键
输入 printf、按Tab键
……

如果想自定义代码片段的话,可以在c:\users\username\vimfiles文件夹中新建文件夹ultisnips,并在其中新建文件c.snippets、cpp.snippets……。c.snippets对应C语言、cpp.snippets对应C++……

在这里插入图片描述
其中文件夹的名字自定义,若有多个文件夹,可在.gvimrc添加let g:UltiSnipsSnippetDirectories=["ultisnips","ultisnips-1"]

在这里插入图片描述

其中自定义代码片段的格式为:

snippet trigger_word [ "description" [ options ] ]

snippet 缩写 [ “描述” [选项] ]
code
endsnippet

C:\Users\fy\vimfiles\ultisnips\c.snippets

snippet if0
if ($1 == 0) {
	${2}
}
endsnippet

定义上述代码片段之后,在C源文件中编辑代码时输入if0,再按下Tab就能添加代码了。

3 语法检查

两个插件二选一

3.1 syntastic

syntastic通过外部语法检查器运行文件,并显示所有由此产生的错误。这可以按需完成,也可以在保存文件时自动完成。安装:

PS C:\Users\fy\vimfiles\pack\my_plugins\start> git clone --depth=1 https://github.com/vim-syntastic/syntastic.git syntastic

.gvimrc中添加如下配置:

let g:syntastic_cpp_checkers = ['gcc']
let g:syntastic_cpp_compiler = 'gcc'

set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0" let g:ale_sign_column_always = 1
" 使用 ctrl+k/ctrl+j 转到上一个/下一个错误处
nnoremap <C-K> :lprevious
nnoremap <C-j> :lnext

设置完成后,编写代码并通过:w保存后,若代码中有错误,则会在错误行显示标记。

在这里插入图片描述

3.2 ale

ale是一个异步语法检查插件,相比于syntastic更快。安装:

PS C:\Users\fy\vimfiles\pack\my_plugins\start> git clone --depth 1 https://github.com/dense-analysis/ale.git ale

.gvimrc中添加如下配置:

let g:ale_sign_column_always = 1
let g:ale_sign_error = '>>'
let g:ale_sign_warning = '--'
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
" 文件内容发生变化、离开插入模式、打开文件时不进行语法检查
let g:ale_lint_on_text_changed = 'never'
let g:ale_lint_on_insert_leave = 0
let g:ale_lint_on_enter = 0
" 在文件包含警告或错误时显示loclist或quickfix项的Vim窗口
" let g:ale_open_list = 1
" 使用 ctrl+k/ctrl+j 转到上一个/下一个错误处
nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap)
let g:ale_linters = {
\   'c++': ['gcc'],
\   'c': ['gcc'],
\}

若要在状态栏显示错误信息,则需在.gvimrc中添加如下设置(此步非必须):

function! LinterStatus() abort
    let l:counts = ale#statusline#Count(bufnr(''))

    let l:all_errors = l:counts.error + l:counts.style_error
    let l:all_non_errors = l:counts.total - l:all_errors

    return l:counts.total == 0 ? 'OK' : printf(
    \   '%dW %dE',
    \   all_non_errors,
    \   all_errors
    \)
endfunction

set statusline=%{LinterStatus()}
" set statusline=\ %F%m%r%h%w%=\ %y\ \|\ %{&ff}\ \|\ %{(&fenc!=''?&fenc:&enc).(&bomb?',BOM':'')}\ \|\ %v,%l/%L\ %p%%\ \|\ ASCII=%03.3b,HEX=%B\ \|\ %{LinterStatus()}\ 

设置完成后,编写代码并通过:w保存后,若代码中有错误,则会在错误行显示标记。

在这里插入图片描述

4 代码自动补全

建议直接观看4.2 coc.nvim+clangd+coc-snippets

4.1 autocomplpop+c.vim+clang_complete

比较有名的补全插件有YouCompleteMe、OmniCppComplete,但是这两个插件使用起来较为麻烦。所以下面使用AutoComplPop+clang_complete+c.vim实现自动补全。

1、autocomplpop:下载之后直接解压到插件目录就能使用(此插件也可单独使用)
2、c.vim:下载后直接解压到插件目录即可
3、clang_complete:下载之后进入到插件所在目录,命令行执行vim clang_complete.vmb -c 'so %' -c 'q'安装

然后在.gvimrc中添加如下设置:

" 这里使用的是32位的llvm
let g:clang_library_path='c:/wsr (x86)/llvm/bin'
" 自动选择第一个匹配项但不插入到代码中
let g:clang_auto_select = 1
let g:clang_hl_errors = 0
let g:clang_close_preview=1
let g:clang_user_options='-stdlib=libc++ -std=c++11 -IIncludePath'

在编写代码时如果输入相同的词语或.::->等等则会自动补全
在这里插入图片描述

注:要想卸载clang_complete的话,在vim的命令行模式下执行命令:RmVimball clang_complete即可。

4.2 coc.nvim+clangd+coc-snippets

方式4.1只能用于单文件的自动补全,如编写的为多文件的C/C++程序,补全效果就不那么好了。而coc.nvim适用于多种情况下的自动补全。

coc.nvim安装要求

  • neovim >= 0.3.2 or vim >= 8.0.1453 (run :version or vim --version to checkout your vim version)
  • node >= 10.12

我用的是vim 8.2,且已经安装过node.js

PS C:\Users\fy> gvim --version
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Dec 12 2019 13:30:17)
MS-Windows 32 位图形界面版本 带 OLE 支持
编译者 mool@tororo
……

PS C:\Users\fy> node.exe --version
v14.16.0

满足上述两个条件就可以安装coc.nvim了:

# for vim8
mkdir -p $home/vimfiles/pack/coc/start
cd $home/vimfiles/pack/coc/start
git clone https://github.com/neoclide/coc.nvim.git

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

安装coc.nvim之后还要配置C/C++语言的Language Server,我用的是clangd

在这里插入图片描述
打开vim,执行命令:CocInstall coc-clangd,安装之后就可以使用coc.nvim的自动补全了。

还可以执行:CocInstall coc-snippets安装coc-snippets来添加代码片段,使用coc-snippets就可以丢弃ultisnips和vim-snippets了,因为coc.nvim也是用<tab>自动补全,这和ultisnips冲突,所以建议使用coc.nvim+coc-snippets。更多coc.nvim的扩展可以在这里查看

而且coc.nvim也支持语法检查,所以syntastic、ale什么的也都不需要了。

按照上述步骤配置后,在.gvimrc中添加如下配置就完成了:

" 2.5 coc.nvim
" ----------coc1----------
set encoding=UTF-8 " coc.nvim using some unicode characters in the file autoload/float.vim "
set hidden         " TextEdit might fail if hidden is not set.
set nowritebackup  " Some servers have issues with backup files, see #649.
set cmdheight=2    " Give more space for displaying messages.
set updatetime=300 " Having longer updatetime (default is 4000 ms = 4 s)
                   " leads to noticeable delays and poor user experience.
                   " Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("nvim-0.5.0") || has("patch-8.1.1564")
    " Recently vim can merge signcolumn and number column into one
    set signcolumn=number
else
    set signcolumn=yes
endif

" ----------coc2----------
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
nmap <silent> gy <Plug>(coc-type-definition)
" 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)
" Symbol renaming.
nmap <space>rn <Plug>(coc-rename)

nnoremap <space>cf :call CocAction('format')<CR>
nnoremap <space>cc :CocConfig<CR>
nnoremap <space>cu :CocUpdate<CR>
" Formatting selected code.
xmap <space>f  <Plug>(coc-format-selected)
nmap <space>f  <Plug>(coc-format-selected)

" ----------coc3----------
" Mappings for CoCList
" Show all diagnostics.
nnoremap <silent><nowait> <space>la  :<C-u>CocList diagnostics<cr>
" Manage extensions.
nnoremap <silent><nowait> <space>le  :<C-u>CocList extensions<cr>
" Show commands.
nnoremap <silent><nowait> <space>lc  :<C-u>CocList commands<cr>
nnoremap <silent><nowait> <space>lm  :<C-u>CocList marketplace<cr>
" Find symbol of current document.
nnoremap <silent><nowait> <space>lo  :<C-u>CocList outline<cr>
" Search workspace symbols.
nnoremap <silent><nowait> <space>ls  :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent><nowait> <space>lj  :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent><nowait> <space>lk  :<C-u>CocPrev<CR>
" Resume latest coc list.
nnoremap <silent><nowait> <space>lp  :<C-u>CocListResume<CR>

" ----------coc4----------
" 2.5.1 coc-snippet
let g:coc_snippet_next = '<tab>'
inoremap <silent><expr> <TAB>
            \ pumvisible() ? coc#_select_confirm() :
            \ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
            \ <SID>check_back_space() ? "\<TAB>" :
            \ coc#refresh()
function! s:check_back_space() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1]  =~# '\s'
endfunction
let g:coc_snippet_prev = '<c-j>'
let g:coc_snippet_next = '<c-k>'

" 2.5.2 coc-explorer
" :nnoremap <space>e :CocCommand explorer<CR>
" nnoremap <A-m>e :CocCommand explorer<CR>

在这里插入图片描述
ctrl+nctrl+p<tab>或ctrl+j、ctrl+k…,就可以选择弹出列表的项了。

5 编译运行源程序

5.1 使用 c.vim

如果在4.1 autocomplpop+c.vim+clang_complete安装过c.vim后,可以在vim的普通模式下执行\rc编译源程序,\rr运行程序

5.2 自定义命令

.gvimrc中添加如下设置:

" 4.1 use <leader>rm to run multiple source file program. Make sure all the
" head files and source files in the same directory
nnoremap <leader>rm :call RunMulSrcFileProgram()<CR>
func! RunMulSrcFileProgram()
    exec "wall"
    if &filetype == 'c'
        exec "!clang   *.c   -o main.exe" | exec "!main.exe" | exec "silent !del main.exe"
    elseif &filetype == 'cpp'
        exec "!clang++ *.cpp -o main.exe" | exec "!main.exe" | exec "silent !del main.exe"
    endif
endfunc
" 4.2 use <leader>rr to run single source file program
nnoremap <leader>rr :call RunSingleSrcFileProgram()<CR>
" %     current file name
" %<    current file name without extension
func! RunSingleSrcFileProgram()
    exec "w"
    if &filetype == 'c'
        " exec '!clang   % -o %<.exe' | exec '!%<' | exec 'silent !del %<.exe'
        exec '!gcc % -o %<' | exec '!%<' | exec 'silent !del %<.exe'
    elseif &filetype == 'cpp'
        " exec '!clang++ % -o %<.exe' | exec '!%<' | exec 'silent !del %<.exe'
        exec '!g++ % -o %<' | exec '!%<' | exec 'silent !del %<.exe'
    elseif &filetype == 'perl'
        exec "!perl %"
    elseif &filetype == 'python'
        exec "!python %"
    elseif &filetype == 'sh'
        exec "!c:/wsr/Git/bin/bash.exe %"
    endif
endfunc

6 调试

首先确保电脑上已经安装了GDB

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;

struct node {
    int data;
    node *lchild = nullptr;
    node *rchild = nullptr;
};
const int maxn = 50;
int pre[maxn], in[maxn], post[maxn];
int n, num = 0;

node *create(int postL, int postR, int inL, int inR);
void BFS(node *root);

int main(void)
{
    int ttt[] = {1, 2, 34, 5, 6};
    cin >> n;
    int i;
    for (i = 0; i < n; i++) {
        cin >> post[i];
    }
    for (i = 0; i < n; i++) {
        cin >> in[i];
    }

    node *root = create(0, n - 1, 0, n - 1);
    BFS(root);

    return 0;
}
node *create(int postL, int postR, int inL, int inR)
{
    // directly return if the length of post order sequence less than or equal
    // to zero
    if (postL > postR) {
        return nullptr;
    }

    node *root = new node;
    root->data = post[postR];
    int k;
    for (k = inL; k <= inR; k++) {
        if (in[k] == post[postR]) {
            break;
        }
    }
    int numLeft = k - inL; // number of left subtree nodes
    root->lchild = create(postL, postL + numLeft - 1, inL, k - 1);
    root->rchild = create(postL + numLeft, postR - 1, k + 1, inR);
    return root;
}
void BFS(node *root)
{
    // what the queue stores is the address of the node
    queue<node *> q;
    q.push(root);
    while (!q.empty()) {
        // remove the first element of the queue
        node *now = q.front();
        q.pop();
        cout << now->data;
        num++;
        if (num < n)
            cout << ' ';
        // if the left subtree is not empty
        if (now->lchild != nullptr)
            q.push(now->lchild);
        // if the right subtree is not empty
        if (now->rchild != nullptr)
            q.push(now->rchild);
    }
    cout << endl;
}

6.1 直接使用gdb调试

PS C:\Users\fy\Desktop> g++ -g .\post_in_to_level.cpp -o .\post_in_to_level
PS C:\Users\fy\Desktop> gdb -q .\post_in_to_level.exe
Reading symbols from .\post_in_to_level.exe...done.
(gdb)

6.2 使用termdebug

termdebug 是从 Vim 8.1 开始内置的调试插件,仅支持 GDB。

打开vim,在命令模式下依次执行命令:

:packadd termdebug
:!g++ -g % -o %<
:Termdebug %<

或者在.gvirmc中添加如下配置:

" 4.5 debug C/C++ program
nnoremap <C-F5> :call DebugCorCppProgram()<CR>
function! DebugCorCppProgram()
    exec 'packadd termdebug'
    exec 'wall'
    if &filetype == 'c'
        exec '!gcc -g % -o %<'
        " exec 'wall' | exec '!gcc -g % -o %<' | exec '!gdb -q %<'
    elseif &filetype == 'cpp'
        exec '!g++ -g % -o %<'
        " exec 'wall' | exec '!g++ -g % -o %<' | exec '!gdb -q %<'
    endif
    exec 'Termdebug %<'
endfunction

6.3 使用vimspector

1、安装插件vimspector,以vim-plug为例:

Plug 'puremourning/vimspector'

2、安装调试适配器

在vim的command mode下执行命令:VimspectorInstall vscode-cpptools以安装调试适配器。

Vimspector is a generic client for Debug Adapters. Debug Adapters (referred to as 'gadgets' or 'adapters') 
are what actually do the work of talking to the real debuggers.

In order for Vimspector to be useful, you need to have some adapters installed.

Vimspector 是调试适配器的通用客户端。调试适配器(称为"小工具"或"适配器")是实际与真正的调试者交谈的工作。

为了让 Vimspector 有用,您需要安装一些适配器。

3、添加配置文件

首先编译源程序:!g++ -g % -o %<

其次在工程目录下新建文件.vimspector.json,假如有程序C:\Users\fy\Desktop\post_in_to_level.cpp,则在C:\Users\fy\Desktop目录下新建文件.vimspector.json

{
  "configurations": {
    "Launch": {
      "adapter": "vscode-cpptools",
      "configuration": {
        "request": "launch",
        "program": "./post_in_to_level.exe",
        "stopAtEntry": true
      }
    }
  }
}

只要将program的值改成目标可执行文件的路径即可。

4、调试。调试时可以使用两套快捷键:

Visual Studio / VSCode

To use Visual Studio-like mappings, add the following to your before loading vimspector:vimrc

let g:vimspector_enable_mappings = 'VISUAL_STUDIO'
KeyMappingFunction
F5<Plug>VimspectorContinueWhen debugging, continue. Otherwise start debugging.
Shift F5<Plug>VimspectorStopStop debugging.
Ctrl Shift F5<Plug>VimspectorRestartRestart debugging with the same configuration.
F6<Plug>VimspectorPausePause debuggee.
F9<Plug>VimspectorToggleBreakpointToggle line breakpoint on the current line.
Shift F9<Plug>VimspectorAddFunctionBreakpointAdd a function breakpoint for the expression under cursor
F10<Plug>VimspectorStepOverStep Over
F11<Plug>VimspectorStepIntoStep Into
Shift F11<Plug>VimspectorStepOutStep out of current function scope

Human Mode

If, like me, you only have 2 hands and 10 fingers, you probably don’t like Ctrl-Shift-F keys. Also, if you’re running in a terminal, there’s a real possibility of terminfo being wrong for shifted-F-keys, particularly if your is . If these issues (number of hands, variables) are unfixable, try the following mappings, by adding the following before loading vimspector:TERM``screen-256color``TERM

let g:vimspector_enable_mappings = 'HUMAN'
KeyMappingFunction
F5<Plug>VimspectorContinueWhen debugging, continue. Otherwise start debugging.
F3<Plug>VimspectorStopStop debugging.
F4<Plug>VimspectorRestartRestart debugging with the same configuration.
F6<Plug>VimspectorPausePause debuggee.
F9<Plug>VimspectorToggleBreakpointToggle line breakpoint on the current line.
<leader>F9<Plug>VimspectorToggleConditionalBreakpointToggle conditional line breakpoint on the current line.
F8<Plug>VimspectorAddFunctionBreakpointAdd a function breakpoint for the expression under cursor
<leader>F8<Plug>VimspectorRunToCursorRun to Cursor
F10<Plug>VimspectorStepOverStep Over
F11<Plug>VimspectorStepIntoStep Into
F12<Plug>VimspectorStepOutStep out of current function scope

比如我在.virmc中添加了设置let g:vimspector_enable_mappings = 'VISUAL_STUDIO',那么就可以按下F5启动调试,按下F9添加或删除行断点……

在这里插入图片描述

评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值