为什么可以在VIM 8.1中更改COC/Neoclide键绑定?

发布于 2025-02-09 18:10:47 字数 867 浏览 0 评论 0原文

我喜欢拥有热键来格式化我使用的所有代码。我更喜欢在较低的“ F”按钮上放它。我尝试模仿默认配置中给出的代码(创建新的“格式”命令的代码将其绑定到“ F”,但它不起作用。 这是我.vimrc的相关内容:

" Formatting selected code.
"original code commented out
"xmap <leader>f  <Plug>(coc-format-selected)
"nmap <leader>f  <Plug>(coc-format-selected)

"these bindings do not work
xmap <leader>f  :call CocActionAsync('format')
nmap <leader>f  :call CocActionAsync('format')
nnoremap <leader>f  :call CocActionAsync('format') 

"This does however work.... strangely:
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocActionAsync('format')

作为旁注,什么是新网络的“选择”?我尝试使用视觉选择,但这似乎不起作用。 这是指向原始配置的链接: https://github.com/neoclide/coc.nvim#example-vim-配置

非常感谢!

I love having a hotkey to format all of the code I'm using. I'd prefer having it on the lower case "f" button. I tried imitating the code given in the default config (the one which creates a new "Format" command) to bind it to "f", but it doesn't work.
Here's the relevant except from my .vimrc:

" Formatting selected code.
"original code commented out
"xmap <leader>f  <Plug>(coc-format-selected)
"nmap <leader>f  <Plug>(coc-format-selected)

"these bindings do not work
xmap <leader>f  :call CocActionAsync('format')
nmap <leader>f  :call CocActionAsync('format')
nnoremap <leader>f  :call CocActionAsync('format') 

"This does however work.... strangely:
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocActionAsync('format')

As a side note, what counts as "selected" for neoclide? I tried using visual selection, but that doesn't seem to work.
Here's the link to the original config:
https://github.com/neoclide/coc.nvim#example-vim-configuration

Many thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千鲤 2025-02-16 18:10:47

因此,答案实际上很简单。产生了两个问题:
第一个来自仿真,基本上,它基本上禁用了VIM的大多数有用函数键,包括CTRL,启动密钥和其他功能……这使调试不必要地很难。第二个是我混淆了钥匙扣语法。
似乎唯一起作用的是使用现有的:格式命令并应用于Shift-f:

nmap F :Format<CR>

仅此而已。我无法想象该解决方案的任何人的脑力都将超过.01%的脑力。由于上述仿真问题,我最初的解决问题的尝试失败了 - 我发布了原始代码,以免使事情变得过于混乱。
即使现在解决了问题,仍然存在一定的苦味。假设人们不仅仅是因为他们正在学习或没有您的熟练程度而使用软件似乎是非常不足的事情。我敢打赌,大多数程序员首先要从小示例中学习,而不是首先阅读2000页的文档。如果您不想提供帮助,请保持沉默。我总是尽力帮助我所拥有的很少的知识,例如C#或TS或拉丁语,西班牙语或捷克语。祝你晚安。

So the answer is actually quite simple. Two problems were being generated:
The first one comes from emulation, which basically disabled most of the useful function keys for vim, including CTRL, the START key and others... that made debugging unnecessarily hard. The second one was me confusing the keybinding syntax.
The only thing that seemed to work was to use the existing :Format command and apply it so shift-f:

nmap F :Format<CR>

That's all. I can't imagine that this solution would've taken more than .01% brainpower of anyone experienced with the software. My initial attempts at fixing the problem failed due to the aforementioned emulation problems - I had posted the original not working code in order not to make things too confusing.
Even though the problem is solved now, there is a certain bitterness remaining. Assuming people aren't using software "properly" just because they are learning or do not have your proficiency level seems a very inadequate thing to do. I'd bet that most programmers started by learning from small examples instead of reading a 2000-page documentation first. If you don't want to help, remain silent. I always try to help with what little knowledge I have in, say, C# or TS, or Latin, Spanish or Czech for that matter. Have a good night.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文