Neovim 算法竞赛配置(windows版本)

Table of Contents

  1. Neovim 算法竞赛配置(windows版本)
    1. 安装neovim
    2. 配置neovim
    3. neovim的使用:
    4. 详细的代码配置如下:

Neovim 算法竞赛配置(windows版本)

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

安装neovim

配置neovim

  • 在C:\Users\用户名\AppData\Local\nvim\ 下创建autoload文件夹和init.vim文件,init.vim即为vim的配置文件
  • plug.vim下载,将这个文件放到autoload文件夹中。(vim-plug是个插件管理器,十分好用)
  • 需要git环境,请自行配置
  • 在neovim中运行:PlugInstall,即可安装
  • 在neovim中:checkhealth 这时依据显示去解决所需问题
  • 详细配置会在文末给出

neovim的使用:

  • 1、基本操作的快捷键:

    说明快捷键
    离开Q
    保存S
    打开配置文件<space>rc
    粘贴P
    复制Y
    取消搜索高亮<space>CR
    跳到行尾9
    跳到行首0
    向上移动5行K
    向下移动5行J
    查找(下一个)=
    查找(上一个)-
    向右分屏sl
    向左分屏sh
    向上分屏sk
    向下分屏sj
    窗口大小变化(5个单位)方向箭头键
    离开单个窗口qf
    多个屏幕窗口间移动<space>方向箭头键
    新建标签页窗口tu
    下一个标签页窗口tn
    上一个标签页窗口tp
    全选<C-a>
  • 2、功能操作快捷键:

    说明快捷键
    回到初始启动页面<F12>
    翻译单词显示在命令行<space>t
    翻译单词显示在小方框<space>w
    格式化代码<space>f
    运行代码r
    打开目录tt
    打开当前文件目录ff
    触发自定义代码补全<C-e>
    自定义代码补全跳转上一个序号处<C-k>
    自定义代码补全跳转下一个序号处<C-j>
  • 3、coc是一个十分好用的vim插件,其具体用法在我的另一篇博客上。

详细的代码配置如下:

  • init.vim
        " __  ____   __  _   ___     _____ __  __ ____   ____
        "|  \/  \ \ / / | \ | \ \   / /_ _|  \/  |  _ \ / ___|
        "| |\/| |\ V /  |  \| |\ \ / / | || |\/| | |_) | |
        "| |  | | | |   | |\  | \ V /  | || |  | |  _ <| |___
        "|_|  |_| |_|   |_| \_|  \_/  |___|_|  |_|_| \_\\____|
        
        " Author: theRunCom
        
        " ===
        " === Basic
        " ===
        set number " 显示行号
        " 使用:set number?可以显示当前值
        set ruler " 显示光标位置
        set showcmd " 右下角显示命令
        set nocompatible  " 去掉有关vi一致性模式,避免操作习惯上的局限.
        set scrolloff=5
        set backspace=indent,eol,start " Backspace键用不了,或者时灵时不灵.所以主动配置
        set laststatus=2   " 1=启动显示状态行, 2=总是显示状态行
        set wildmenu  " 使用Tab键补全时,在状态栏显示匹配的列表
        set showmatch  " 高亮显示匹配的括号
        set hlsearch                        " 高亮匹配结果
        set ignorecase                      " 搜索时默认忽略大小写
        set smartcase                       " 搜索时智能匹配大小写
        syntax enable  " 开启语法高亮
        filetype plugin indent on  " 检测文件类型,并载入文件类型插件,为特定文件类型载入相关缩进文件
        set shiftwidth=4 " 自动缩进时,缩进长度为4 
        set encoding=utf-8  
        set cursorline   " 突出显示当前行
        set mouse=a 
        set tabstop=4  " 设置 Tab 键宽度为 4 个空格
        " 禁用交换文件
        set noswapfile
        " 禁用undo文件
        set noundofile
        "Vim自动探测fileencodings的顺序列表
        "启动时会按照它所列出的字符编码方式逐一探测即将打开的文件的字符编码方式
        "并且将fileencoding设置为最终探测到的字符编码方式
        set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
        set termencoding=utf-8              " Vim所工作的终端的字符编码方式
        set autoindent                      " 自动缩进
        set autoread                        " 文件变化之后自动重读
        " 打开文件时光标返回上次离开的位置
        autocmd BufReadPost * execute "normal g'\""
        
        " ===
        " === Basic Mappings
        " ===
        let mapleader=" "
        noremap Q :q<CR>
        noremap S :w<CR>
        " Open the vimrc file anytime
        noremap <LEADER>rc :e C:/Users/17724/AppData/Local/nvim/init.vim<CR>
        " paste
        nnoremap P "+p
        " make Y to copy till the end of the line
        nnoremap Y y$
        " Copy to system clipboard
        vnoremap Y "+y
        " Search
        noremap <LEADER><CR> :nohlsearch<CR>
        " 9 key: go to the end of the line
        noremap <silent> 9 $
        " K/J keys for 5 times k/j (faster navigation)
        noremap <silent> K 5k
        noremap <silent> J 5j
        map <C-a> ggVG
        "Searching
        noremap - N
        noremap = n
        " Use <space> + arrow keys for moving the cursor around windows
        noremap <LEADER><up> <C-w>k
        noremap <LEADER><down> <C-w>j
        noremap <LEADER><left> <C-w>h
        noremap <LEADER><right> <C-w>l
        noremap qf <C-w>o
        " Disable the default s key
        noremap s <nop>
        map sl :set splitright<CR>:vsplit<CR>
        map sh :set nosplitright<CR>:vsplit<CR>
        map sj :set splitbelow<CR>:split<CR>
        map sk :set nosplitbelow<CR>:split<CR>
        " Resize splits with arrow keys
        noremap <up> :res +5<CR>
        noremap <down> :res -5<CR>
        noremap <left> :vertical resize-5<CR>
        noremap <right> :vertical resize+5<CR>
        " make new tanline
        map tu :tabe<CR>
        map tn :+tabnext<CR>
        map tp :-tabnext<CR>
        
        " ===
        " === Plug
        " ===
        
        call plug#begin('G:\Neovim\share\nvim\plugged')
        Plug 'mhinz/vim-startify'
        Plug 'arzg/vim-colors-xcode'
        Plug 'voldikss/vim-translator'
        Plug 'vim-airline/vim-airline'
        Plug 'vim-airline/vim-airline-themes'
        Plug 'neoclide/coc.nvim', {'branch': 'release'}
        Plug 'preservim/nerdtree'
        Plug 'SirVer/ultisnips'
        Plug 'jiangmiao/auto-pairs'
        call plug#end()
        
        " === vim-startify ===
        let g:startify_custom_header          = [
        \'',
        \'',
        \' VVVVVVVV           VVVVVVVV iiii                             ',
        \' V::::::V           V::::::Vi::::i                            ',
        \' V::::::V           V::::::V iiii                             ',
        \' V::::::V           V::::::V                                  ',
        \'  V:::::V           V:::::Viiiiiii    mmmmmmm    mmmmmmm      ',
        \'   V:::::V         V:::::V i:::::i  mm:::::::m  m:::::::mm    ',
        \'    V:::::V       V:::::V   i::::i m::::::::::mm::::::::::m   ',
        \'     V:::::V     V:::::V    i::::i m::::::::::::::::::::::m   ',
        \'      V:::::V   V:::::V     i::::i m:::::mmm::::::mmm:::::m   ',
        \'       V:::::V V:::::V      i::::i m::::m   m::::m   m::::m   ',
        \'        V:::::V:::::V       i::::i m::::m   m::::m   m::::m   ',
        \'         V:::::::::V        i::::i m::::m   m::::m   m::::m   ',
        \'          V:::::::V        i::::::im::::m   m::::m   m::::m   ',
        \'           V:::::V         i::::::im::::m   m::::m   m::::m   ',
        \'            V:::V          i::::::im::::m   m::::m   m::::m   ',
        \'             VVV           iiiiiiiimmmmmm   mmmmmm   mmmmmm   ',
        \]
        let g:startify_session_persistence    = 1
        let g:startify_session_delete_buffers = 1
        let g:startify_change_to_dir          = 0
        let g:startify_change_to_vcs_root     = 1
        let g:startify_fortune_use_unicode    = 1
        let g:startify_padding_left           = 3
        let g:startify_enable_special         = 0
        let g:startify_session_number         = 10
        nmap <silent><F12>  :Startify<cr>
        nmap <C-p><C-o> :SLoad<cr>
        nmap <C-p><C-s> :SSave<cr>
        nmap <C-p><C-d> :SDelete<cr>
        nmap <C-p><C-c> :SClose<cr>
        
        " === vim-colors-xcode ==
        let g:signify_sign_add    = ''
        let g:signify_sign_change = ''
        let g:signify_sign_delete = ''
        let g:signify_sign_show_count = 0 " Don’t show the number of deleted lines.
        " Update Git signs every time the text is changed
        autocmd User SignifySetup
                    \ execute 'autocmd! signify' |
                    \ autocmd signify TextChanged,TextChangedI * call sy#start()
        
        colorscheme xcodedark
        
        " === vim-translator ===
        " Echo translation in the cmdline
        nmap <silent> <Leader>t <Plug>Translate
        vmap <silent> <Leader>t <Plug>TranslateV
        " Display translation in a window
        nmap <silent> <Leader>w <Plug>TranslateW
        vmap <silent> <Leader>w <Plug>TranslateWV
        " Replace the text with translation
        nmap <silent> <Leader>r <Plug>TranslateR
        vmap <silent> <Leader>r <Plug>TranslateRV
        " Translate the text in clipboard
        nmap <silent> <Leader>x <Plug>TranslateX
        " only work in neovim
        nnoremap <silent><expr> <M-f> translator#window#float#has_scroll() ?
                                    \ translator#window#float#scroll(1) : "\<M-f>"
        nnoremap <silent><expr> <M-b> translator#window#float#has_scroll() ?
                                    \ translator#window#float#scroll(0) : "\<M-f>"
        
        " === vim-airline ===
        let g:airline#extensions#tabline#enabled = 1
        let g:airline_theme='murmur'
        let g:airline#extensions#tabline#formatter = 'unique_tail'
        " 10% ☰ 10/100 ln : 20 介绍
        " 10%     - 10 percent down the top of the file
        " ☰ 10    - current line 10
        " /100 ln - of 100 lines
        " : 20    - current column 20
        
        " === coc.nvim ===
        " coc_extensions
        let g:coc_global_extensions = [
        	\'coc-json',
        	\'coc-marketplace',
        	\'coc-vimlsp',
        	\'coc-clangd',
        	\'coc-powershell']
        "----------------------------------------------------------------------
        " 基本配置
        "----------------------------------------------------------------------
        " Coc约束 -- 没设置可能导致文本编辑失败
        set hidden
        " 刷新时间
        set updatetime=100
        " Coc约束
        set shortmess+=c
        " coc的tab补全
        inoremap <silent><expr> <TAB>
              \ pumvisible() ? "\<C-n>" :
              \ <SID>check_back_space() ? "\<TAB>" :
              \ coc#refresh()
        inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
        
        function! s:check_back_space() abort
          let col = col('.') - 1
          return !col || getline('.')[col - 1]  =~# '\s'
        endfunction
        
        "----------------------------------------------------------------------
        " 补全配置
        "----------------------------------------------------------------------
        " 使用CR 确认补全
        inoremap <silent><expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u<CR>"
        " 对 log 文件禁用补全
        autocmd FileType log let b:coc_suggest_disable = 1
        "----------------------------------------------------------------------
        " 功能配置
        "----------------------------------------------------------------------
        let g:coc_enable_locationlist = 0
        " 下一个占位符
        let g:coc_snippet_next = '<C-l>'
        " 上一个占位符
        let g:coc_snippet_prev = '<C-h>'
        " 格式化代码
        xmap <Leader>F  <Plug>(coc-format-selected)
        nmap <Leader>F  <Plug>(coc-format-selected)
        " 支持json注释
        autocmd FileType json syntax match Comment +\/\/.\+$+
        " 显示当前buffer下的错误信息
        nmap <silent> <Leader>el :CocList diagnostics<CR>
        " 下一个错误
        nmap <silent> <Leader>en <Plug>(coc-diagnostic-next)
        " 上一个错误
        nmap <silent> <Leader>em <Plug>(coc-diagnostic-prev)
        " 转到定义
        nmap <silent> <Leader>td <Plug>(coc-definition)
        " 转到类型定义
        nmap <silent> <Leader>ty <Plug>(coc-type-definition)
        " 转到实现
        nmap <silent> <Leader>ti <Plug>(coc-implementation)
        " 转到声明
        nmap <silent> <Leader>tc <Plug>(coc-declaration)
        " 转到引用
        nmap <silent> <Leader>tr <Plug>(coc-references)
        " show documentation in preview window.
        nnoremap <silent> <LEADER>h :call <SID>show_documentation()<CR>
        function! s:show_documentation()
          if (index(['vim','help'], &filetype) >= 0)
            execute 'h '.expand('<cword>')
          elseif (coc#rpc#ready())
            call CocActionAsync('doHover')
          else
            execute '!' . &keywordprg . " " . expand('<cword>')
          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)
        "----------------------------------------------------------------------
        " 多光标配置
        "----------------------------------------------------------------------
        " 在当前位置放下光标
        nmap <silent> <C-i> <Plug>(coc-cursors-position)
        " 在选中位置放下光标
        xmap <silent> <C-i> <Plug>(coc-cursors-range)
        " 选中相同的单词
        nmap <expr> <silent> <C-;> <SID>select_current_word()
        function! s:select_current_word()
          if !get(g:, 'coc_cursors_activated', 0)
            return "\<Plug>(coc-cursors-word)"
          endif
          return "*\<Plug>(coc-cursors-word):nohlsearch\<CR>"
        endfunc
        " Remap for do codeAction of selected region
        function! s:cocActionsOpenFromSelected(type) abort
          execute 'CocCommand actions.open ' . a:type
        endfunction
        xmap <leader>a  <Plug>(coc-codeaction-selected)
        nmap <leader>aw  <Plug>(coc-codeaction-selected)w
        
        " === NERDTree ===
        let g:NERDTreeDirArrowExpandable = '▸'
        let g:NERDTreeDirArrowCollapsible = '▾'
        nnoremap tt :NERDTreeToggle<CR>
        nnoremap ff :NERDTreeFind<CR>
        " NerdCommenter
        " Create default mappings
        let g:NERDCreateDefaultMappings = 1
        " Add spaces after comment delimiters by default
        let g:NERDSpaceDelims = 1
        " Use compact syntax for prettified multi-line comments
        let g:NERDCompactSexyComs = 1
        " Align line-wise comment delimiters flush left instead of following code indentation
        let g:NERDDefaultAlign = 'left'
        " Set a language to use its alternate delimiters by default
        let g:NERDAltDelims_java = 1
        " Add your own custom formats or override the defaults
        let g:NERDCustomDelimiters = { 'c': { 'left': '/**','right': '*/' } }
        " Allow commenting and inverting empty lines (useful when commenting a region)
        let g:NERDCommentEmptyLines = 1
        " Enable trimming of trailing whitespace when uncommenting
        let g:NERDTrimTrailingWhitespace = 1
        " Enable NERDCommenterToggle to check all selected lines is commented or not 
        let g:NERDToggleCheckAllLines = 1
        
        " === UltiSnips ===
        let g:UltiSnipsExpandTrigger="<c-e>"
        let g:UltiSnipsJumpForwardTrigger="<c-k>"
        let g:UltiSnipsJumpBackwardTrigger="<c-j>"
        let g:UltiSnipsSnippetDirectories = ['~/AppData/Local/nvim/ultisnips']
        
        noremap r :call CompileRunGcc()<CR>
        func! CompileRunGcc()
        	exec "w"
        	if &filetype == 'c'
        		exec "!gcc % -o %< & %<"	
        	elseif &filetype == 'cpp'
        		set splitbelow
        		exec "!g++ -Wall % -o %<"
        		"exec "! %<"
        		:sp
        		:res -5
        		:term %< 
        	endif  
        endfunc
    
  • cpp.snippets
        snippet head "An entire header" 
        #include <iostream>
        #include <algorithm>
        #include <cstring>
        ${0}
        endsnippet
        
        snippet using "using namespace std"
        using namespace std;
        ${0}
        endsnippet
        
        snippet cout "cout"
        cout << ${1} << endl;
        ${0}
        endsnippet
        
        snippet scanf "scanf"
        scanf("%${1}",&${2});
        ${0}
        endsnippet
        
        snippet for "loop"
        for(int ${1};${2} < ${3:length};${4}++) {
        	${0}
        }
        endsnippet
        
        snippet main "int main"
        int main()
        {
        	${0}
        	return 0;
        }
        endsnippet
    
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不能say的秘密

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值