Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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
(g) Vim-在运行时禁用历史记录/viminfo_Vim - Fatal编程技术网

(g) Vim-在运行时禁用历史记录/viminfo

(g) Vim-在运行时禁用历史记录/viminfo,vim,Vim,我使用一些命令在保存时压缩文件,并在保存后仅在开始时对缩进进行解压缩。有一件事我很难接受,那就是我不希望这些命令被添加到历史记录中。无论是命令还是光标位置等 我想我要做的是在写前关闭viminfo,然后在写后再打开它。但我似乎不明白。以下是我正在使用的函数: function! s:CompressIndent() augroup CompressIndent autocmd! " Befor writing, change 4 spaces (and

我使用一些命令在保存时压缩文件,并在保存后仅在开始时对缩进进行解压缩。有一件事我很难接受,那就是我不希望这些命令被添加到历史记录中。无论是命令还是光标位置等

我想我要做的是在写前关闭viminfo,然后在写后再打开它。但我似乎不明白。以下是我正在使用的函数:

function! s:CompressIndent()
    augroup CompressIndent
        autocmd!

        " Befor writing, change 4 spaces (and single tabs) into 2 spaces
        autocmd BufWritePre * set viminfo="NONE"              " Turn off 'history' before making the pre-write substitutions
        autocmd BufWritePre * %substitute/^\( \+\)\1/\1/e " Halve the number of spaces of indentation
        autocmd BufWritePre * set tabstop=2               " Make sure that tabs = 2 spaces before re-tabbing
        autocmd BufWritePre * retab                       " Turn tabs into two spaces

        " When opening a file (and after writing the file) turn 2 spaces into (and 4 tabs) into 4 spaces
        autocmd BufReadPost,BufWritePost * set tabstop=4         " Make sure to display in 4 tabs
        autocmd BufReadPost,BufWritePost * %substitute/^ \+/&&/e " Double the number of spaces of indentation on Reading and writing
        autocmd BufReadPost,BufWritePost * set viminfo='20,\"200 " Turn back on history
    augroup END
endfunction
我已尝试设置viminfo=NONE和设置viminfo=。两者似乎都没有效果

任何帮助都将不胜感激

谢谢

编辑

这里是我现在使用这个的地方,但是我仍然没有完全让它工作,现在缩进被打破了,但是histdel也不太工作。保存文件后,光标移动到一个全新的位置,撤消历史记录被分支或出现一些奇怪的情况:

function! s:CompressIndent()
    augroup CompressIndent
        autocmd!

        " Befor writing, change 4 spaces (and single tabs) into 2 spaces
        autocmd BufWritePre * call s:SpaceSubstitution("2") " Halve the number of    spaces of indentation
        autocmd BufWritePre * set tabstop=2                 " Make sure that tabs = 2 spaces before re-tabbing
        autocmd BufWritePre * retab                         " Turn tabs into two spaces

        " When opening a file (and after writing the file) turn 2 spaces into (and 4 tabs) into 4 spaces
        autocmd BufReadPost,BufWritePost * set tabstop=4    " Make sure to display in 4 tabs
        autocmd BufReadPost,BufWritePost * call s:SpaceSubstitution("4") " Double the number of spaces of indentation on Reading and writing
    augroup END
endfunction
command! -n=0 -bar CompressIndent :call s:CompressIndent()

function! s:SpaceSubstitution(toSpaces)
    if a:toSpaces == "2"
        %substitute/^\( \+\)\1/\1/e
    else
        %substitute/^ \+/&&/e
    endif

    call histdel('search', -1)
endfunction

Vim有四个用于操纵历史的函数,:h历史函数为您提供了一个列表和简短描述。在这四个选项中,您需要的是:

histdel()

您可以在:h histdel中了解它。

Vim有四个用于操纵历史的函数,:h history函数为您提供了一个列表和简短的描述。在这四个选项中,您需要的是:

histdel()
你可以在:h histdel中读到。

操纵“viminfo”是一个太大的棍子,在这里挥舞不起来。由:autocmd执行的命令不会添加到命令历史记录中

我唯一看到的是:替换会污染搜索历史和当前的搜索模式。通过将命令移动到:函数中,并从autocmd调用该函数,可以避免很多问题。请参阅:帮助功能搜索撤消

在函数结束时,您需要做的唯一一件事是从历史记录中删除搜索模式:

:call histdel('search', -1)
编辑:若要保留当前光标位置,请将:替换换行为以下内容:

let l:save_view = winsaveview()
    %substitute/...
call winrestview(l:save_view)
操纵“viminfo”是一个太大的棍子,不能在这里挥舞。由:autocmd执行的命令不会添加到命令历史记录中

我唯一看到的是:替换会污染搜索历史和当前的搜索模式。通过将命令移动到:函数中,并从autocmd调用该函数,可以避免很多问题。请参阅:帮助功能搜索撤消

在函数结束时,您需要做的唯一一件事是从历史记录中删除搜索模式:

:call histdel('search', -1)
编辑:若要保留当前光标位置,请将:替换换行为以下内容:

let l:save_view = winsaveview()
    %substitute/...
call winrestview(l:save_view)

写入前将4个空格更改为2,写入后将2个空格更改为4。我可以问一下这样的舞蹈有什么意义吗?关键是能够在4个空格中编辑,并在2个空格中保存。你可以在写之前将4个空格更改为2,在写之后将2个空格更改为4。我可以问一下这样的舞蹈有什么意义吗?关键是能够在4个空间中编辑,并在2个空间中保存。你认为retab可能也会影响它吗?嘿,我试着实现了这一点。见我的编辑上面。还是不太管用。有什么想法吗?谢谢:-搜索历史记录未修改。要保持光标位置,请使用winsaveview;我已经把它添加到我的答案中了。哦,那太好了!不是在Linux atm中,否则我会试试。但是,谢谢你!另一件有点古怪的事情是撤销。有时它会添加一个额外的撤销,有时它会分支撤销,所以我不得不使用g-或g+来撤销。你是用我的函数来试的还是你自己的函数?我用的是你的函数。%s将创建一个撤消点,但分支取决于您以前取消的操作。没办法。你认为retab也会影响它吗?嘿,我试过实现这个。见我的编辑上面。还是不太管用。有什么想法吗?谢谢:-搜索历史记录未修改。要保持光标位置,请使用winsaveview;我已经把它添加到我的答案中了。哦,那太好了!不是在Linux atm中,否则我会试试。但是,谢谢你!另一件有点古怪的事情是撤销。有时它会添加一个额外的撤销,有时它会分支撤销,所以我不得不使用g-或g+来撤销。你是用我的函数来试的还是你自己的函数?我用的是你的函数。%s将创建一个撤消点,但分支取决于您以前取消的操作。没办法。嘿,我试过实现这个。见我的编辑上面。还是不太管用。有什么想法吗?谢谢-我试过实现这个。见我的编辑上面。还是不太管用。有什么想法吗?谢谢