Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vim:关闭特定行上的折叠_Vim - Fatal编程技术网

Vim:关闭特定行上的折叠

Vim:关闭特定行上的折叠,vim,Vim,我想根据vim是否匹配正则表达式,以编程方式关闭它的折叠。我在vimrc中定义了一个函数来执行此操作: " Support python 2 and 3 if has('python') command! -nargs=1 Python2or3 python <args> elseif has('python3') command! -nargs=1 Python2or3 python3 <args> else echo "Error: Requ

我想根据vim是否匹配正则表达式,以编程方式关闭它的折叠。我在vimrc中定义了一个函数来执行此操作:

" Support python 2 and 3 
if has('python')
    command! -nargs=1 Python2or3 python <args>
elseif has('python3')
    command! -nargs=1 Python2or3 python3 <args>
else
    echo "Error: Requires Vim compiled with +python or +python3"
    finish
endif

" Define function
func! FoldCopyrightHeader()
Python2or3 << EOF
import re
import vim
# Look at the first 30 lines
header = '\n'.join(vim.current.buffer[0:30])
pattern = 'Copyright .* by .* THE POSSIBILITY OF SUCH DAMAGE'
match = re.search(pattern, header, flags=re.MULTILINE | re.DOTALL)
if match:
    # Find the line number of the block to fold 
    lineno = header[:match.start()].count('\n') 
    # Remember the current position
    row, col = vim.current.window.cursor
    # move cursor to the fold block
    vim.command('cal cursor({},{})'.format(lineno, 0))
    # close the fold
    vim.command('call feedkeys("zc")')  
    # move back to the original position
    vim.command('cal cursor({},{})'.format(row, col))
EOF
endfunc
“支持python 2和python 3
如果有('python')
命令!-nargs=1 Python2or3 python
elseif有('python3')
命令!-nargs=1蟒蛇2或3蟒蛇3
其他的
echo“错误:需要使用+python或+python3编译Vim”
完成
恩迪夫
“定义功能
func!FoldCoyRightHeader()文件

Python2or3我在打字时解决了它

使用
vim.command(':foldclose')
而不是
vim.command('callfeedkeys('zc'))
似乎可以做到这一点