我具有由在约一百段落的文件时,每一个被根据第三示例折叠下:帮助折叠EXPR部,这使得折叠用空行分开的段落中:
set foldmethod=expr
set foldexpr=getline(v:lnum)=~'^\\s*$'&&getline(v:lnum+1)=~'\\S'?'<1':1
Run Code Online (Sandbox Code Playgroud)
假设我启动搜索模式,例如
/Item 014
Run Code Online (Sandbox Code Playgroud)
这种模式可以在7个不同的折叠中找到.
我知道我可以按"n"6次连续打开搜索所涉及的所有折叠.
但我希望一次性打开7个折叠,以便快速浏览.
我试过一个宏
qu n q
Run Code Online (Sandbox Code Playgroud)
然后
/Item 014
100@u
Run Code Online (Sandbox Code Playgroud)
但失败了.
我该怎么办?
我有一个相当简单的列表(一个数字后跟一个句子),这里按正确的顺序:
-347 a negative number
-100 another negative number
-25 and again, a negative number
17 some text
25 foo bar
100 two same texts
100 two same texts (almost)
350 a positive number
Run Code Online (Sandbox Code Playgroud)
每次添加新项目时,我都需要对该列表进行排序.
我搜索了SO,发现答案:
在python中排序 - 如何对包含字母数字值的列表进行排序?
我使用的代码是奇特的,它是:
import re
def convert(str):
return int("".join(re.findall("\d*", str)))
list1.sort(key=convert)
Run Code Online (Sandbox Code Playgroud)
为了更好地解释我的问题,我洗了清单并运行了代码.
结果是:
17 some text
-25 and again, a negative number
25 foo bar
100 two same texts (almost)
100 two same texts
-100 another negative number
-347 a negative number
350 …Run Code Online (Sandbox Code Playgroud) 我希望运行一个带有 case 语句的脚本,导致在脚本之间的其他选项列表(某种子菜单)之间进行选择:
#!/bin/bash
echo "Your choice ?"
echo "1) Foo"
echo "2) Bar"
echo "3) Stuff"
read case;
case $case in
#and this is where I would like to allow
#(here a simplified example I do not manage to code)
1) What script ? # may I use another case statement ?
a) Foo1;;
b) Foo2;;
2) What script ? # d°
a) Bar1;;
b) Bar2;;
c) Bar3;;
esac
Run Code Online (Sandbox Code Playgroud)
Foo1、Foo2、Bar1、Bar2 和 Bar3 实际上是 bash 脚本,我想从脚本中调用例如 sh Foo1。
我必须如何进行:我可以在 case …
我有文本行,都具有相同的结构,并希望在所有行上排列2个元素:
1257654 some text (which may be long) #Foo
1543098 some other text #Barbar
1238769 whatever #Baz
2456874 something else #Quux
Run Code Online (Sandbox Code Playgroud)
我想获得:
#Foo some text (which may be long) 1257654
#Barbar some other text 1543098
#Baz whatever 1238769
#Quux something else 2456874
Run Code Online (Sandbox Code Playgroud)
这是我被困的地方:
:%s/\(\d\{7\}\)\(#.\{-}\)/\2\1/
Run Code Online (Sandbox Code Playgroud)
我哪里做错了 ?
我有一个非常简单的待办事项列表,其中包含日期和标签:
141218 Call school &phone @me
141219 Buy groceries &buy @me
141220 Have W order books &buy @W
141220 Think about vacation &vac @me
141221 Have W try Santa Claus outfit &fam @W
141222 Ask a question to S.O. &vim @me
Run Code Online (Sandbox Code Playgroud)
这个列表不长(我记的文件要长得多),但是假设我要打印它,只打印,例如@W部分?
首先,我将搜索:
/&W
Run Code Online (Sandbox Code Playgroud)
折叠(Vim Wikia Simple Folding:Tip 282)
:set foldexpr=getline(v:lnum)!~@/
:nnoremap <F8> :set foldmethod=expr<CR><Bar>zM
Run Code Online (Sandbox Code Playgroud)
我现在有:
+—- 2 lines
141220 Have W order books &buy @W
+—- 1 line
141221 Have W try Santa Claus outfit &fam @W
+—- 1 …Run Code Online (Sandbox Code Playgroud) 1)我使用全局命令在文件中搜索foo:g:
:g/foo/p
Run Code Online (Sandbox Code Playgroud)
我想将结果粘贴到文件的末尾.我该怎么办?
2)同样的问题(或者是?)和echo语句的结果:
:echo IndexByWord(['word1', 'word2', 'word3', etc])
Run Code Online (Sandbox Code Playgroud)
(关于这个函数,请参阅:Vim:如何索引纯文本文件?)
提前致谢
我有文本文件,只是没有段落的列表.当我想专注于一个项目时,我能够将除了匹配之外的所有内容折叠到我的搜索中,这要归功于Vim Wikia(提示282:"简单折叠"):
:set foldexpr=getline(v:lnum)!~@/
:nnoremap <F8> :set foldmethod=expr<CR><Bar>zM
Run Code Online (Sandbox Code Playgroud)
这被证明是有用的:因此我可以非常清楚地看到我正在寻找的物品:它们在黑色背景上呈现白色,而褶皱是灰色(ctermbg)上的暗灰色(ctermfg).
但是有一个 - 次要 - 故障.可能发生(并且实际上经常发生)不包含图案的单条线保留在包含图案的两条线之间,例如:
1 pattern
2 not pattern
3 not pattern
4 pattern
5 not pattern
6 pattern
Run Code Online (Sandbox Code Playgroud)
简单的折叠将折叠第2和第3行,而不是第5行.
我应该如何隐藏这条单线呢?
有没有办法折叠零线(这让我想起了一只手鼓掌的公案......)?我想这是不可能的.
那么,有没有办法简单地用一个函数隐藏线条(例如与折叠相同的突出显示)?