Git Product home page Git Product logo

Comments (7)

fannheyward avatar fannheyward commented on August 17, 2024

have to use 'zz' to manually center it

Can't reproduce, after jumping, the cursor will be centered. What's your :CocInfo and try minimal vimrc.

from coc.nvim.

chenxuan520 avatar chenxuan520 commented on August 17, 2024

minimal vimrc

let mapleader = ","      " use ',' as leader
set nocompatible         " set not compatible with vi
" filetype on              " set file type detection
" filetype plugin on       " set load plugin by file type
set noeb                 " turn off error syntax prompts
syntax enable            " highlight enable
syntax on                " highlight auto
set background=dark      " set background color

call plug#begin('~/.vim/plugged')
" auto complete
Plug 'neoclide/coc.nvim', {'branch': 'release'}
call plug#end()

" load vim default plugin
runtime macros/matchit.vim
" coc.nvim
let g:coc_disable_startup_warning = 1
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>"
inoremap <silent><expr><right> coc#pum#visible() ? coc#pum#confirm() : "\<right>"
inoremap <silent><expr><c-p> coc#pum#visible() ? coc#pum#prev(1) : "\<c-[>"

function! CheckBackspace() abort
	let col = col('.') - 1
	return !col || getline('.')[col - 1]  =~# '\s'
endfunction
" coc find define
nmap <leader>u <Plug>(coc-definition)
nmap <leader>U <Plug>(coc-type-definition)
nmap <silent>gd <Plug>(coc-definition)
nmap <silent>gD <Plug>(coc-type-definition)
nmap <silent>gr <Plug>(coc-references)
nmap <silent>gi <Plug>(coc-implementation)
" coc refactor code
nmap <space>r <Plug>(coc-refactor)
nmap <leader>r <Plug>(coc-rename)
" coc find wrong
nmap <silent><F3> <Plug>(coc-diagnostic-prev)
nmap <silent><F4> <Plug>(coc-diagnostic-next)
nmap <silent>[w <Plug>(coc-diagnostic-prev)
nmap <silent>]w <Plug>(coc-diagnostic-next)
nmap <silent>-w <Plug>(coc-fix-current)
nnoremap <silent><nowait>=w :<C-u>CocList --normal diagnostics<cr>
nnoremap <silent><nowait><space>w :<C-u>CocList --normal diagnostics<cr>
" coc text obj
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)
" coc code action
nmap <leader>a  <Plug>(coc-codeaction)
xmap <leader>a  <Plug>(coc-codeaction-selected)
nmap <leader>l  <Plug>(coc-codelens-action)
" coc select range
nmap <silent><leader>s <Plug>(coc-range-select)
xmap <silent><leader>s <Plug>(coc-range-select)
" coc format
command! -nargs=0 Format :call CocActionAsync('format')
command! -nargs=0 Import :call CocActionAsync('runCommand', 'editor.action.organizeImport')
nmap <leader><leader>f :Format<cr>
" coc config
nmap <silent><nowait><space><space>c :CocConfig<cr>
nmap <silent><nowait><space><space>l :CocList --normal extensions<cr>
nmap <silent><nowait><space><space>j :CocList outline<cr>
" coc currnt tag
nnoremap <silent><nowait><space><space>k :echo CocAction('getCurrentFunctionSymbol')<cr>
" coc help
nnoremap <silent> K  :call ShowDocumentation()<cr>
nnoremap <silent> gh :call ShowDocumentation()<cr>

code demo

  • The following is the example code of go
package demo

import "fmt"







































func Example() {
	fmt.Println("hello")
}



































func main() {
	fmt.Println("hello world")
	Example()
}













CocInfo

## versions

vim version: NVIM v0.10.0
node version: v22.4.0
coc.nvim version: 0.0.82-c3ae5c3b 2024-05-23 20:39:40 +0800
coc.nvim directory: /Users/chenxuan/.vim/plugged/coc.nvim
term: iTerm.app
platform: darwin

## Log of coc.nvim

2024-07-30T19:30:45.888 INFO (pid:72509) [plugin] - coc.nvim initialized with node: v22.4.0 after 114
2024-07-30T19:30:45.967 INFO (pid:72509) [services] - LanguageClient gopls state change: stopped => starting
2024-07-30T19:30:46.057 INFO (pid:72509) [services] - LanguageClient gopls state change: starting => running
2024-07-30T19:30:46.060 INFO (pid:72509) [services] - service go started
2024-07-30T19:30:52.256 INFO (pid:72509) [attach] - receive notification: showInfo []

coc plug list

image

Steps to reproduce

  1. Install a specific version of the plugin
  2. Edit this go file
  3. Move the cursor to the example function in the underlying main function
  4. Move to this function and find that it is not automatically centered

video

Jietu20240730-194148-HD.mp4

from coc.nvim.

fannheyward avatar fannheyward commented on August 17, 2024

Sorry I still can't reproduce this, here's my tests.

set nocompatible
set runtimepath^=~/.local/share/nvim/plugged/coc.nvim
set hidden
set noexpandtab
filetype plugin indent on
syntax on

nmap <silent> gd <Plug>(coc-definition)

Tested with same coc.nvim release with coc-go, gd on Example in main function, will jump to Example function and centered.

from coc.nvim.

chenxuan520 avatar chenxuan520 commented on August 17, 2024

Jietu20240731-131919-HD.mp4

I used the script you provided and retested it and found that it still cannot be centered correctly. Why is this? Do you need me to provide more information? I am using a Mac laptop with an M1 chip and using nvim

from coc.nvim.

fannheyward avatar fannheyward commented on August 17, 2024

Tested with M1 as well, still debugging this issue.

from coc.nvim.

fannheyward avatar fannheyward commented on August 17, 2024

coc.nvim didn't call zz after jumping, the cursor sometimes was centered but not always.

No plan to center the cursor after jumping, use zz manually.

from coc.nvim.

chenxuan520 avatar chenxuan520 commented on August 17, 2024

Well, is there a way to automatically jump to the middle through configuration? I tried nmap <silent>gd <Plug>(coc-definition)zz, but because it seems to be asynchronous, the cursor often jumps to the middle.

from coc.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.