Martins3 / My-Linux-Config

:clap: Modern neovim configuration based on native lsp
https://martins3.github.io/My-Linux-Config/
GNU General Public License v3.0
336 stars 62 forks source link

how to jump back after call coc-definition? #28

Closed marryton007 closed 3 years ago

marryton007 commented 3 years ago

大佬,你好。

操作环境: ubuntu18.04 ~/.SpaceVim.d$ nvim -v NVIM v0.5.0 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3 Compilation: /usr/bin/gcc-11 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/runner/work/neovim/neovim/build/config -I/home/runner/work/neovim/neovim/src -I/home/runner/work/neovim/neovim/.deps/usr/include -I/usr/include -I/home/runner/work/neovim/neovim/build/src/nvim/auto -I/home/runner/work/neovim/neovim/build/include Compiled by runner@fv-az139-878

Features: +acl +iconv +tui See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/share/nvim"

Run :checkhealth for more info

直接使用你的配置已经可以浏览代码了,只是有一个问题:

在使用,gd跳到一个函数定义之后,使用ctro+o可以跳转回原来的位置。但如果使用jkhl移动了光标,就不能使用ctrl+o到跳回原地址了。这导致在浏览内核代码时,非常不方便。

请问应该如何操作才可以快速跳回原来的位置,就像以前用ctags的ctrl+[和ctrl+]一样

image

Martins3 commented 3 years ago

因为我的配置是来来自于 coc.nvim 的,所以 可以参考下面两个 issue

具体做法就是

  1. 增加配置 set tagfunc=CocTagFunc
  2. 删除我之前对于 cltr [ 的映射

https://github.com/Martins3/My-Linux-config/blob/65f4d778b8f44b4614d3d9ea5b8e41c6d18fbd9f/autoload/myspacevim.vim#L42

  1. 使用 ctrl [ 来跳转而不是 gd
marryton007 commented 3 years ago

非常感谢,按你所说修改之后。

使用ctrl+] 跳到定义处,ctrl+t 跳回, 但不能与,gd混用。

我觉得这样就可以了

marryton007 commented 2 years ago

大佬,你好。

今天重新拉取大佬的配置,并合并到我自己的分支上,对比差异如下

diff --git a/autoload/myspacevim.vim b/autoload/myspacevim.vim
index e5af4b8..7c9aced 100755
--- a/autoload/myspacevim.vim
+++ b/autoload/myspacevim.vim
@@ -6,8 +6,6 @@ func! myspacevim#before() abort
   " 当失去焦点或者离开当前的 buffer 的时候保存
   set autowrite
   autocmd FocusLost,BufLeave * silent! update
-  set mouse=
-  set tagfunc=CocTagFunc

   " 重新映射 leader 键
   let g:mapleader = ','
@@ -40,7 +38,7 @@ func! myspacevim#before() abort

   " ctrl + ] 查询 cppman
   " 如果想让该快捷键自动查询 man,将Cppman 替换为 Cppman!
-  " autocmd FileType c,cpp noremap <C-]> <Esc>:execute "Cppman " . expand("<cword>")<CR>
+  autocmd FileType c,cpp noremap <C-]> <Esc>:execute "Cppman " . expand("<cword>")<CR>

   " Tell Neosnippet about the other snippets
   " ref : https://github.com/Shougo/neosnippet.vim
diff --git a/init.toml b/init.toml
index 7527b92..b8678c3 100755
--- a/init.toml
+++ b/init.toml
@@ -33,7 +33,6 @@
     # 3: 1 ➛ ¹
     # 4: 1 ➛ 
     buffer_index_type = 4
-    relativenumber = false
     # 显示/隐藏顶部标签栏上文件类型图标,这一图标需要安装 nerd fonts,
     # 如果未能成功安装这一字体,可以隐藏图标
     enable_tabline_filetype_icon = true
diff --git a/plugin/coc.vim b/plugin/coc.vim
index 5e4b298..7e1a7a6 100644
--- a/plugin/coc.vim
+++ b/plugin/coc.vim
@@ -69,9 +69,8 @@ call coc#config("languageserver", {
       \},
       \})

-"显示git blame 
-"call coc#config("git.addGBlameToVirtualText", v:true)
-"call coc#config("git.virtualTextPrefix", "👋 ")
+call coc#config("git.addGBlameToVirtualText", v:true)
+call coc#config("git.virtualTextPrefix", "👋 ")

 " 使用 shellcheck 可以让 shell 自动补全,格式化和静态检查
 call coc#config("diagnostic-languageserver.filetypes", {

spacevim.txt

最新的nvim, 从源码编译 ~/.SpaceVim.d » nvim --version jiaxi@ehome-hwrd-1 NVIM v0.6.0-dev+434-g7f93b2ab0 Build type: RelWithDebInfo LuaJIT 2.1.0-beta3 Compilation: /usr/bin/cc -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/jiaxi/git/neovim/build/config -I/home/jiaxi/git/neovim/src -I/home/jiaxi/git/neovim/.deps/usr/include -I/usr/include -I/home/jiaxi/git/neovim/build/src/nvim/auto -I/home/jiaxi/git/neovim/build/include Compiled by jiaxi@ehome-hwrd-1

Features: +acl +iconv +tui See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/usr/local/share/nvim"

Run :checkhealth for more info

~/.SpaceVim.d » which vim

vim: aliased to nvim

现在问题是ctrl+]不能定位到函数定义了, 按文档操作,已经在linux kernel 项目下生成了compile_commands.json文件

image

Martins3 commented 2 years ago

你测试一下 https://github.com/Martins3/My-Linux-Config/tree/issue-28 这个分支能不能使用 ctrl ] 来进行跳转

Martins3 commented 2 years ago

这个配置在我的机器上是没有问题的。

marryton007 commented 2 years ago

感谢大佬的回复,闹了个乌龙。

服务器被人挖矿攻击了,导致ccls运行缓慢,不能及时响应。

Martins3 commented 2 years ago

感谢大佬的回复,闹了个乌龙。

服务器被人挖矿攻击了,导致ccls运行缓慢,不能及时响应。

好吧,这也可以,可笑死我了。