Skip to content

zhzhzhy/coc-vimrc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

coc-vimrc

Configuration of my coc-nvim & Vimrc

Vim Installation

Neovim Installation(Optional)

Neovim

Neovim is a project that seeks to aggressively refactor Vim in order to:

  • Simplify maintenance and encourage contributions
  • Split the work between multiple developers
  • Enable [advanced UIs] without modifications to the core
  • Maximize extensibility

See the Introduction wiki page and [Roadmap] for more information.

Neovim Installation guide

coc-nvim Installation

  • First Install coc-nvim Don't forget to install nodejs and npm
sudo apt-get install nodejs npm

OR

sudo pacman -S nodejs npm

Note: If you are in China,change the npm source(Taobao registry) by following command

npm config set registry https://registry.npm.taobao.org

Plug.vim Install

A minimalist Vim plugin manager.

Installation

Download plug.vim and put it in the "autoload" directory.

Vim

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

You can automate the process by putting the command in your Vim configuration file as suggested here.

Windows (PowerShell)
iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |`
    ni $HOME/vimfiles/autoload/plug.vim -Force

Neovim

Unix, Linux
sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
       https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
Linux (Flatpak)
curl -fLo ~/.var/app/io.neovim.nvim/data/nvim/site/autoload/plug.vim \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Windows (PowerShell)
iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |`
    ni "$(@($env:XDG_DATA_HOME, $env:LOCALAPPDATA)[$null -eq $env:XDG_DATA_HOME])/nvim-data/site/autoload/plug.vim" -Force

Vim & Neovim configuration: How to use these scripts

Notice: These config files suit my own needs,Please DO NOT just copy this configuration folder without really understanding about it! Please, at least, read this README file!

For Vim

  1. After you install Plug.vim,copy .vimrc and coc-settings.json Scripts to $HOME/ & $HOME/.vim/

  2. Reopen Vim

  3. Wait Coc Extension installing finished

  4. Execute :PlugInstall to Finish VIM Plugin install

  5. Configure the rest components

For Neovim

  1. After you install Plug.vim,copy init.vim to $HOME/.config/nvim/
  2. Reopen Neovim

Neovim: Transitioning from Vim (nvim-from-vim)

nvim-from-vim

  1. To start the transition, create your init.vim (user config) file:
:call mkdir(stdpath('config'), 'p')
:exe 'edit '.stdpath('config').'/init.vim'
  1. Add these contents to the file:
    set runtimepath^=~/.vim runtimepath+=~/.vim/after
    let &packpath = &runtimepath
    source ~/.vimrc
  1. Restart Nvim, your existing Vim config will be loaded.

See |provider-python| and |provider-clipboard| for additional software you might need to use some features.

Your Vim configuration might not be entirely Nvim-compatible. See |vim-differences| for the full list of changes.

The |'ttymouse'| option, for example, was removed from Nvim (mouse support should work without it). If you use the same |vimrc| for Vim and Nvim, consider guarding |'ttymouse'| in your configuration like so:

    if !has('nvim')
        set ttymouse=xterm2
    endif

Conversely, if you have Nvim specific configuration items, you could do this:

    if has('nvim')
        tnoremap <Esc> <C-\><C-n>
    endif

For a more granular approach use YXXYexists()|:

    if exists(':tnoremap')
        tnoremap <Esc> <C-\><C-n>
    endif

Now you should be able to explore Nvim more comfortably. Check |nvim-features| for more information.

Plugin explanation & key mapping

vim plugins

Follow Installation

Shortcut Action
Ctrl+n Select next key (multiple cursors)
q Deselect the current keys (multiple cursors)
N Select the previous key
n Select the next key
Esc Quit mutiple cursors

To minimize chances for conflicts, a leader that is specific to VM is defined. The default is \\ (two backslashes), but you can change it by setting:

let g:VM_leader = {your VM leader}
Basic usage:
  • select words with Ctrl-N (like Ctrl-d in Sublime Text/VS Code)
  • create cursors vertically with Ctrl-Down/Ctrl-Up
  • select one character at a time with Shift-Arrows
  • press n/N to get next/previous occurrence
  • press [/] to select next/previous cursor
  • press q to skip current and get next occurrence
  • press Q to remove current cursor/selection
  • start insert mode with i,a,I,A

Two main modes:

  • in cursor mode commands work as they would in normal mode
  • in extend mode commands work as they would in visual mode
  • press Tab to switch between «cursor» and «extend» mode

Most vim commands work as expected (motions, r to replace characters, ~ to change case, etc). Additionally you can:

  • run macros/ex/normal commands at cursors
  • align cursors
  • transpose selections
  • add patterns with regex, or from visual mode

And more... of course, you can enter insert mode and autocomplete will work.

Documentation
:help visual-multi

For some specific topic it's often:

:help vm-some-topic

The wiki was the first documentation for the plugin, but many pictures are outdated and contain wrong mappings. Still, you can take a look.

You could read at least the Quick Start.

Quick refer the Key mapping

Insert mode with autocomplete, alignment (mappings in pic have changed, don't trust them)

Imgur


Undo/Redo edits and selections

Imgur


Alternate cursor/extend mode, motions (even %), reverse direction (as in visual mode) and extend from the back. At any time you can switch from extend to cursor mode and viceversa.

Imgur


Select inside/around brackets/quotes/etc:

Imgur


Select operator, here shown with 'wellle/targets.vim' plugin: sib, sia, saa + selection shift

Imgur


Synched column transposition

Imgur


Unsynched transposition (cycle all regions, also in different lines)

Imgur


Shift regions left and right (M-S-<>)

Imgur


Find words under cursor, add new words (patterns stack), navigate regions, skip them, add regions with regex.

Imgur

Usage
Shortcut Action
:UndotreeToggle OR F5 toggle the undo-tree panel.
:redo OR <ctrl-r> restore
[ number ] marks the most recent change
  1. Use :UndotreeToggle to toggle the undo-tree panel. You may want to map this command to whatever hotkey by adding the following line to your vimrc, take F5 for example.
nnoremap <F5> :UndotreeToggle<CR>
  1. Markers
    • Every change has a sequence number and it is displayed before timestamps.
    • The current state is marked as > number <.
    • The next state which will be restored by :redo`:redo` or <ctrl-r> is marked as { number }.
    • The [ number ] marks the most recent change.
    • The undo history is sorted by timestamps.
    • Saved changes are marked as s and the big S indicates the most recent saved change.
  2. Press ? in undotree window for quick help.
  3. Persistent undo
    • Usually I would like to store the undo files in a seperate place like below.
if has("persistent_undo")
   let target_path = expand('~/.undodir')

    " create the directory and any parent directories
    " if the location does not exist.
    if !isdirectory(target_path)
        call mkdir(target_path, "p", 0700)
    endif

    let &undodir=target_path
    set undofile
endif

A simple, easy-to-use Vim alignment plugin.

ga + symbol in normal or visual mode to align text based on symbol

  • with the following lines of text,
apple   =red
grass+=green
sky-=   blue

try these commands:

  • vipga=
    • visual-select inner paragraph
    • Start EasyAlign command (ga)
    • Align around =
  • gaip=
    • Start EasyAlign command (ga) for inner paragraph
    • Align around =
Demo
Using predefined alignment rules

An alignment rule is a predefined set of options for common alignment tasks, which is identified by a single character, such as <Space>, =, :, ., |, &, #, and ,.

=

  • = Around the 1st occurrences
  • 2= Around the 2nd occurrences
  • *= Around all occurrences
  • **= Left/Right alternating alignment around all occurrences
  • <Enter> Switching between left/right/center alignment modes
<Space>

  • <Space> Around the 1st occurrences of whitespaces
  • 2<Space> Around the 2nd occurrences
  • -<Space> Around the last occurrences
  • <Enter><Enter>2<Space> Center-alignment around the 2nd occurrences
,

  • The predefined comma-rule places a comma right next to the preceding token without margin ({'stick_to_left': 1, 'left_margin': 0})
  • You can change it with <Right> arrow
Using regular expression

You can use an arbitrary regular expression by

  • pressing <Ctrl-X> in interactive mode
  • or using :EasyAlign /REGEX/ command in visual mode or in normal mode with a range (e.g. :%)

Different ways to start

This demo shows how you can start interactive mode with visual selection or use non-interactive :EasyAlign command.

Aligning table cells

Check out various alignment options and "live interactive mode".

Syntax-aware alignment

Delimiters in strings and comments are ignored by default.

Using blockwise-visual mode

A simple, easy-to-use Vim alignment plugin.

ga + symbol in normal or visual mode to align text based on symbol

  • with the following lines of text,
apple   =red
grass+=green
sky-=   blue

try these commands:

  • vipga=
    • visual-select inner paragraph
    • Start EasyAlign command (ga)
    • Align around =
  • gaip=
    • Start EasyAlign command (ga) for inner paragraph
    • Align around =
Demo
Using predefined alignment rules

An alignment rule is a predefined set of options for common alignment tasks, which is identified by a single character, such as <Space>, =, :, ., |, &, #, and ,.

=

  • = Around the 1st occurrences
  • 2= Around the 2nd occurrences
  • *= Around all occurrences
  • **= Left/Right alternating alignment around all occurrences
  • <Enter> Switching between left/right/center alignment modes
<Space>

  • <Space> Around the 1st occurrences of whitespaces
  • 2<Space> Around the 2nd occurrences
  • -<Space> Around the last occurrences
  • <Enter><Enter>2<Space> Center-alignment around the 2nd occurrences
,

  • The predefined comma-rule places a comma right next to the preceding token without margin ({'stick_to_left': 1, 'left_margin': 0})
  • You can change it with <Right> arrow
Using regular expression

You can use an arbitrary regular expression by

  • pressing <Ctrl-X> in interactive mode
  • or using :EasyAlign /REGEX/ command in visual mode or in normal mode with a range (e.g. :%)

Different ways to start

This demo shows how you can start interactive mode with visual selection or use non-interactive :EasyAlign command.

Aligning table cells

Check out various alignment options and "live interactive mode".

Syntax-aware alignment

Delimiters in strings and comments are ignored by default.

Using blockwise-visual mode

You can limit the scope with blockwise-visual mode.

calendar.vim

Press E key to view the event list, and T key to view the task list. Also, press ? key to view a quick help.

calendar.vim

Basic Usage
:Calendar

calendar.vim

:Calendar 2000 1 1

calendar.vim

:Calendar -view=year

calendar.vim

:Calendar -view=year -split=vertical -width=27

calendar.vim

:Calendar -view=year -split=horizontal -position=below -height=12

calendar.vim

:Calendar -first_day=monday

calendar.vim

:Calendar -view=clock

calendar.vim

You can switch between views with < and > keys.

For convenience it is recommended that you assign a key for this, like so:

noremap <F3> :Autoformat<CR>

Basic usage: :Autoformat OR F3

A Vim plugin which shows a git diff in the sign column. It shows which lines have been added, modified, or removed. You can also preview, stage, and undo individual hunks; and stage partial hunks. The plugin also provides a hunk text object.

In the screenshot above you can see:

  • Lines 183-184 are new.
  • Lines 186-187 have been modified.
  • The preview for the modified lines highlights changed regions within the line.

Example

Press cs"' inside

"Hello world!"

to change it to

'Hello world!'

Now press cs'<q> to change it to

<q>Hello world!</q>

To go full circle, press cst" to get

"Hello world!"

To remove the delimiters entirely, press ds".

Hello world!

Now with the cursor on "Hello", press ysiw] (iw is a text object).

[Hello] world!

Let's make that braces and add some space (use } instead of { for no space): cs]{

{ Hello } world!

Now wrap the entire line in parentheses with yssb or yss).

({ Hello } world!)

Revert to the original text: ds{ds)

Hello world!

Emphasize hello: ysiw<em>

<em>Hello</em> world!

Finally, let's try out visual mode. Press a capital V (for linewise visual mode) followed by S<p class="important">.

<p class="important">
  <em>Hello</em> world!
</p>

gif

  • Generate table of contents for Markdown files.

    Supported Markdown parsers:

    • GFM (GitHub Flavored Markdown)
    • GitLab
    • Redcarpet
  • Update existing table of contents.

  • Auto update existing table of contents on save.

  1. :GenTocGFM

    Generate table of contents in GFM link style.

    This command is suitable for Markdown files in GitHub repositories, like README.md, and Markdown files for GitBook.

  2. :GenTocRedcarpet

    Generate table of contents in Redcarpet link style.

    This command is suitable for Jekyll or anywhere else use Redcarpet as its Markdown parser.

  3. :GenTocGitLab

    Generate table of contents in GitLab link style.

    This command is suitable for GitLab repository and wiki.

  4. :GenTocMarked

    Generate table of contents for iamcco/markdown-preview.vim which use Marked markdown parser.

You can view here to know differences between GFM and Redcarpet style toc links.

Update existing table of contents

Generally you don't need to do this manually, existing table of contents will auto update on save by default.

The :UpdateToc command, which is designed to update toc manually, can only work when g:vmt_auto_update_on_save turned off, and keep insert fence.

Remove table of contents

:RemoveToc command will do this for you, just remember keep insert fence option by default.

Lean & mean status/tabline for vim that's light as air.

img

When the plugin is correctly loaded, there will be a nice statusline at the bottom of each vim window.

Smarter tab line

Automatically displays all buffers when there's only one tab open.

tabline

This is disabled by default; add the following to your vimrc to enable the extension:

let g:airline#extensions#tabline#enabled = 1

Indent Guides is a plugin for visually displaying indent levels in Vim.

Usage

The default mapping to toggle the plugin is <Leader>ig.

You can also use the following commands inside Vim:

:IndentGuidesEnable
:IndentGuidesDisable
:IndentGuidesToggle

If you would like to have indent guides enabled by default, you can add the following to your ~/.vimrc:

let g:indent_guides_enable_on_vim_startup = 1

Preview markdown on your modern browser with synchronised scrolling and flexible configuration

" Start the preview
:MarkdownPreview

" Stop the preview"
:MarkdownPreviewStop

coc-nvim extensions

Language servers

Other coc extensions

coc.nvim extensions marketplace.

  • search keywords:coc.nvim from npmjs.com, display extensions in coc-lists
  • extension name starts with means installed already, with an uninstall action
  • extension name starts with x means uninstalled, with an install action
  • extension name ends with * is published by @chemzqm, IMO, is official
Usage
  • :CocList marketplace list all available extensions
  • :CocList marketplace python to search extension that name contains python

coc-marketplace

you can use :Prettier to format current buffer. your can <leader>f for range format.

Prettier range format only support languageId including: javascript,javascriptreact, typescript, typescriptreact, json and graphql.

Update your coc-settings.json for format on save

Open settings file with:

:CocConfig

Add:

  "coc.preferences.formatOnSaveFiletypes": ["css", "markdown"],

to setup the languages which you want to format on save.

Shortcut Action
Insert Mode Ctrl l coc-snippets-expand
(trigger snippet expand)
Visual Mode Ctrl j coc-snippets-select
(select text for visual placeholder of snippet)
Ctrl j coc_snippet_next
(jump to next placeholder, it's default of coc.nvim)
Ctrl k coc_snippet_prev
(jump to previous placeholder, it's default of coc.nvim)
xmap <leader> x coc-convert-snippet
(Use x for convert visual selected code to snippet)
imap <C-j> <Plug> coc-snippets-expand-jump
(Use for both expand and jump (make expand higher priority.)

Make <tab> used for trigger completion, completion confirm, snippet expand and jump like VSCode.

vim-snipmate default snippets (Previously snipmate-snippets)

This repository contains snippets files for various programming languages.

  • snippets/*: snippets using snipMate format
  • UltiSnips/*: snippets using UltiSnips format

Explorer extension for coc.nvim

image

  • Open explorer
    <space>e
    

Translation extension for coc.nvim.

Shortcut Action
<Leader> t popup
<Leader> t echo
<Leader> t replace

About

Configuration of my coc-nvim & vimrc

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published