vim:选择里面的点 [英] vim: select inside dots

查看:31
本文介绍了vim:选择里面的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到简单的解决方案(在这里和网络上)来简单地选择/插入/删除由点包围的东西(开发中的常见情况):

I can't find a solution (here and on the web) for simply selecting/inserting/deleting stuff surrounded by dots (a common case in development) :

    someobject.some-property-with-hyphens.otherproperty

如何选择中间属性?

我试过了:

    vi.  (dot is for executing last command)
    viw  (don't include hyphens)
    4viw (still nop)
    vis  (select full line)


更常见的例子(在javascript中)


Edit : more common exemple (in javascript)

    app.object['key'].$object_with_a_dollar_sign.function()

推荐答案

我怀疑这里真正的问题是连字符不被视为标识符的一部分

I suspect the real issue here is that hyphens are not considered a part of an identifier

你应该尝试添加

:se iskeyword+=-

适合您的文件类型.这样,viw 会做你想做的事情

for your file type. That way, viw will do exeactly what you want

要使此设置自动用于例如 strange 文件:

To make this setting automatic for, say, strange files:

:autocmd BufReadPost *.strange se isk+=-

将该行添加到您的 vimrc (:e $MYVIMRC) 中,您将永远不必考虑添加 iskeyword 设置.另请参阅 :he modeline 以了解为每个文件设置此设置的替代方法

Adding that line to your vimrc (:e $MYVIMRC) you'll never have to think about adding the iskeyword setting. See also :he modeline for alternative ways to set this setting per file

更新更纯粹的解决方案是创建您自己的运算符映射.

Update an even purer solution would to create your own operator-mapping.

一个快速的草稿,这对我来说似乎很有效:

A quick draft of this, that seemed to work very nicely for me:

xnoremap <silent>.  f.oT.o
xnoremap <silent>a. f.oF.o
xnoremap <silent>i. t.oT.o

onoremap <silent>.  :<C-u>exec 'normal v' . v:count1 . '.'<CR>
onoremap <silent>a. :<C-u>exec 'normal v' . v:count1 . 'a.'<CR>
onoremap <silent>i. :<C-u>exec 'normal v' . v:count1 . 'i.'<CR>

以下缓冲区内容的示例(字母 w 上的光标):

Examples for the following buffer contents (cursor on the letter w):

someobject.some-property-with-hyphens.SUB.otherproperty

  • v. 在可视模式下选择 some-property-with-hyphens.
  • va. 在可视模式下选择 .some-property-with-hyphens.
  • vi. 在可视模式下选择 some-property-with-hyphens
    • v. selects some-property-with-hyphens. in visual mode
    • va. selects .some-property-with-hyphens. in visual mode
    • vi. selects some-property-with-hyphens in visual mode
    • 动作可以链接并接受count:

      • v.. 在可视模式下选择 some-property-with-hyphens.SUB.立>
      • v2. 在可视模式下选择some-property-with-hyphens.SUB.
      • v2a. 选择 .some-property-with-hyphens.SUB. 可视化模式
      • v2i. 选择 some-property-with-hyphens.SUB在可视模式下
      • v.. selects some-property-with-hyphens.SUB. in visual mode
      • v2. also selects some-property-with-hyphens.SUB. in visual mode
      • v2a. selects .some-property-with-hyphens.SUB. in visual mode
      • v2i. selects some-property-with-hyphens.SUB in visual mode

      您可以将运算符用作任何编辑命令的运算符:

      You can use the operators as operators to any editing command:

      • d. 结果为 someobject.SUB.otherproperty
      • ci.shortname 结果为 someobject.shortname.SUB.otherproperty
      • c2.get(" 结果为 someobject.get("otherproperty
      • d. results in someobject.SUB.otherproperty
      • ci.shortname results in someobject.shortname.SUB.otherproperty
      • c2.get(" results in someobject.get("otherproperty

      光标在点分隔标识符"中的哪里开始并不重要.请注意,为方便起见,所有视觉模式映射都将光标定位在选择的末尾(因此您可以继续扩展选择,例如 % 和其他动作).

      It doesn't matter where in a 'dot-delimited-identifier' the cursor is to start with. Note that for convenience, all visual mode mappings position the cursor at the end of the selection (so you can do continue extending the selection by e.g. % and other motions).

      这篇关于vim:选择里面的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆