如何使Neovim' s' e'地图额外的位置?

发布于 2025-01-24 12:43:02 字数 1172 浏览 2 评论 0原文

我试图用:nnoremap e mynewcommand重新映射“ e”键,但是我对如何使当前的“结尾”完成一个额外的位置有些丢失。

例如,如果我有Word1 X Word2 Word3(x是当前位置),它将在此处结束:Word1 WordX Word3

有没有办法重新映射它,以便它以Word + 1位置的结尾结束?像这样:Word1 Word2x Word3

谢谢!

Edit1:出于某些奇怪的原因,进行重新映射时::nnoremap< sl> e,工作就像魅力 - 但是,:nnoremap< sj> b不起作用。有人有任何想法吗?

EDIT2:按照要求,这是我的vim.init:

:nnoremap t r
:nnoremap <SPACE> <INSERT>
:vnoremap i <UP>
:vnoremap <SPACE> <INSERT>
:nnoremap i <UP>
:nnoremap k <DOWN>
:nnoremap j h
:nnoremap <S-l> e 
:nnoremap <S-j> b 
:nnoremap a <S-A>
:nnoremap vv <S-V>
:vnoremap k <DOWN>
:vnoremap j <LEFT>
:nnoremap dw daw
:inoremap jh <Esc>

" Settings.

set nocompatible
set showmatch
set ignorecase
set tabstop=4
set softtabstop=4
set expandtab
set shiftwidth=4
set autoindent
set number 
set clipboard=unnamedplus
set ttyfast

" Vim-plug (Plugin Manager)

call plug#begin()
Plug 'itchyny/lightline.vim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
call plug#end()

I am trying to remap 'e' keybind with :nnoremap e mynewcommand, but I am a bit lost about how to make the current "end of word" finish one extra position.

For example, right now if I have word1 Xword2 word3 (X being the current position), it ends here: word1 wordX word3.

Is there a way to remap it so that it ends on end of word + 1 position? Like this: word1 word2X word3

Thanks!

Edit1: For some weird reason, when doing the remap: :nnoremap <S-l> e, works like a charm - but, the :nnoremap <S-j> b doesn't work at. Does anyone have any idea?

Edit2: As requested, here is my vim.init:

:nnoremap t r
:nnoremap <SPACE> <INSERT>
:vnoremap i <UP>
:vnoremap <SPACE> <INSERT>
:nnoremap i <UP>
:nnoremap k <DOWN>
:nnoremap j h
:nnoremap <S-l> e 
:nnoremap <S-j> b 
:nnoremap a <S-A>
:nnoremap vv <S-V>
:vnoremap k <DOWN>
:vnoremap j <LEFT>
:nnoremap dw daw
:inoremap jh <Esc>

" Settings.

set nocompatible
set showmatch
set ignorecase
set tabstop=4
set softtabstop=4
set expandtab
set shiftwidth=4
set autoindent
set number 
set clipboard=unnamedplus
set ttyfast

" Vim-plug (Plugin Manager)

call plug#begin()
Plug 'itchyny/lightline.vim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
call plug#end()

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

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

发布评论

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

评论(1

街角迷惘 2025-01-31 12:43:02

首先:vim(和neovim)没有“地图”,因此您所做的不是“重新映射”,它们是“映射”(或“地图”,如果您真的想要)。

第二:正如某人已经指出的那样,f&lt; space&gt;已经满足了您的需求,因此您可能不应该为此花费太多精力。

第三&lt; sl&gt;&lt; sj&gt;是响应的,并且是不必要的方法来表达l and j。保持您的配置简单。

第四:帮助j:帮助l是两个非常有用的命令,因此您应该认真考虑覆盖的相对好处他们。特别是因为这样的事情。

第五 in nnoremap&lt; key&gt; E不是很可读,并且在匆忙格式化后可能会消失。您应该考虑这些替代符号:

nnoremap <key> e<Space>
nnoremap <key> el
nnoremap <key> e<Right>

甚至可能是:

nnoremap <key> f<Space>

第六:您解释情况的方式不是很清楚:

word1 Xword2 word3
word1 wordX word3

2 2在哪里?确切的光标是哪个角色?您能以更明确的方式重写它吗?类似:

当前行为:

word1 word2 word3
     ^               " position of the cursor before e
          ^          " position of the cursor after e

期望的行为:

word1 word2 word3
     ^               " position of the cursor before <key>
           ^         " position of the cursor after <key>

第七:我可以,有点了解nnoremap l e&lt; space&gt;的渴望,因为希望光标在之后立即降落当前的单词似乎是一件合理的事情。您可能想放在那里,或插入括号或其他任何东西。但是我无法想象一个常见的场景足以证明nnoremap j b&lt; space&gt;。什么,您到底想处理该映射?您要解决什么问题?而且,更重要的是,“不起作用”是什么意思?

您是否试图通过在单词之前降落光标来映射l映射?由于&lt; space&gt;将光标移至右侧,因此b&lt; space&gt;显然无法使用,但是以下可能是:甚至可能:

nnoremap <key> b<Left>
nnoremap <key> bh
nnoremap <key> b<BS>

甚至可能:甚至可能:

nnoremap <key> F<Space>

First: Vim (and Neovim) doesn't have "maps" so what you are doing are not "remaps", they are "mappings" (or "maps", if you really want).

Second: as someone already pointed out, f<Space> already covers your need so you probably shouldn't spend so much energy on this.

Third: <S-l> and <S-j> are convoluted and unnecessary ways to say L and J. Keep your config simple.

Fourth: :help J and :help L are two very useful commands in their own right so you should think hard about the relative benefits of overriding them. Especially for something as trivial as this.

Fifth: The in nnoremap <key> e is not very readable and is likely to disappear after some hasty formatting. You should consider these alternatives notations:

nnoremap <key> e<Space>
nnoremap <key> el
nnoremap <key> e<Right>

or maybe even:

nnoremap <key> f<Space>

Sixth: The way you explained your situation is not very clear:

word1 Xword2 word3
word1 wordX word3

Where did the 2 go? Which character was the cursor on, exactly? Could you rewrite it in a more explicit way? Something like:

Current behaviour:

word1 word2 word3
     ^               " position of the cursor before e
          ^          " position of the cursor after e

Desired behaviour:

word1 word2 word3
     ^               " position of the cursor before <key>
           ^         " position of the cursor after <key>

Seventh: I can, sort of, understand the desire for nnoremap L e<Space> because wanting the cursor to land right after the current word seems like a reasonable thing to want. You may want to put something, there, or insert a bracket, or whatever. But I fail to imagine a scenario common enough to justify nnoremap J b<Space>. What, exactly are you trying to do with that mapping? What problem are you trying to solve? And, more importantly, what does "doesn't work" mean?

Are you trying to mirror your L mapping by landing the cursor before the word? Since <Space> moves the cursor to the right, then b<Space> is obviously not going to work but the following might:

nnoremap <key> b<Left>
nnoremap <key> bh
nnoremap <key> b<BS>

or maybe even:

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