问题描述
这真的开始让我紧张,这很奇怪,因为这是一个很小的问题.
This is really starting to get on my nerves, which is weird because it's such a small issue.
假设我在没有插件/没有 vimrc 的情况下启动 (g)vim 7.3 (windows OR linux).我打开一个较长的文件,向下滚动一半.我将光标定位在主窗口的底部.我打开一个垂直拆分窗口 (CTRL+W v).
Let's say I start (g)vim 7.3 (windows OR linux) with no plugins/no vimrc. I open a longer file, scroll down halfway. I position my cursor at the bottom of the main window. I open a vertical split window (CTRL+W v).
接下来发生的事情让我很伤心.光标和它所在的行(以前在原始窗口的底部)跳到到窗口的顶部.右侧的新窗口具有光标所在行在原始窗口中的原始位置.
What happens next is killing me. The cursor and the line it's on (previously at the bottom of the original window) jump up to the top of the window. The new window on the right has the original position where the line the cursor is on was in the original window.
我的问题:如何防止vim改变我分割的窗口的光标位置?老实说,我根本不在乎 新 窗口中的位置是否发生变化,但是拆分更改原始窗口的事实让我想撕掉头发.
My question: How do I keep vim from changing the cursor position of the window I split? Honestly, I wouldn't care at all if the position changed in the new window, but the fact that splitting changes the original window is making me want to tear my hair out.
它曾经是完全可以忽略的.然后我有点生气.然后我慢慢开始变得非常恼火.现在它开始让我生气.非常感谢任何帮助/技巧/黑客!
It used to be completely ignorable. Then I got kind of annoyed. Then I slowly started getting really annoyed. Now it's starting to make me furious. Any help/tricks/hacks are greatly appreciated!!
我的 Windows 和 Linux 的 vim 构建选项(两者都发生):
My vim build options for both Windows and Linux (happening on both):
视窗:
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent
+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
+conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs
-dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path
+find_in_path +float +folding -footer +gettext/dyn -hangul_input +iconv/dyn
+insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape
+multi_byte +multi_lang -mzscheme -netbeans_intg -osfiletype +path_extra -perl
+persistent_undo -postscript +printer -profile -python -python3 +quickfix
+reltime +rightleft -ruby +scrollbind +signs +smartindent -sniff +startuptime
+statusline -sun_workshop +syntax +tag_binary +tag_old_static -tag_any_white
-tcl -tgetent -termresponse +textobjects +title -toolbar +user_commands
+vertsplit +virtualedit +visual +visualextra +viminfo +vreplace +wildignore
+wildmenu +windows +writebackup -xfontset -xim -xterm_save -xpm_w32
system vimrc file: "$VIM\vimrc"
user vimrc file: "$HOME\_vimrc"
2nd user vimrc file: "$VIM\_vimrc"
user exrc file: "$HOME\_exrc"
2nd user exrc file: "$VIM\_exrc"
Compilation: cl -c /W3 /nologo -I. -Iproto -DHAVE_PATHDEF -DWIN32 -DFEAT_CSCOPE -DWINVER=0x0400 -D_WIN32_WINNT=0x0400 /Fo.\ObjC/ /Ox /GL -DNDEBUG /Zl /MT -DDYNAMIC_ICONV -DDYNAMIC_GETTEXT -DFEAT_BIG /Fd.\ObjC/ /Zi
Linking: link /RELEASE /nologo /subsystem:console /LTCG:STATUS oldnames.lib kernel32.lib advapi32.lib shell32.lib gdi32.lib comdlg32.lib ole32.lib uuid.lib /machine:i386 /nodefaultlib libcmt.lib user32.lib /PDB:vim.pdb -debug
Linux:
-arabic +autocmd +balloon_eval +browse +builtin_terms +byte_offset +cindent
+clientserver +clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments
-conceal +cryptv -cscope +cursorbind +cursorshape +dialog_con_gui +diff
+digraphs +dnd -ebcdic -emacs_tags +eval +ex_extra +extra_search -farsi
+file_in_path +find_in_path +float +folding -footer +fork() +gettext
-hangul_input +iconv +insert_expand +jumplist -keymap -langmap +libcall
+linebreak +lispindent +listcmds +localmap -lua +menu +mksession +modify_fname
+mouse +mouseshape -mouse_dec +mouse_gpm -mouse_jsbterm -mouse_netterm
-mouse_sysmouse +mouse_xterm +multi_byte +multi_lang -mzscheme +netbeans_intg
-osfiletype +path_extra -perl +persistent_undo +postscript +printer -profile
+python -python3 +quickfix +reltime -rightleft -ruby +scrollbind +signs
+smartindent -sniff +startuptime +statusline -sun_workshop +syntax +tag_binary
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
+toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo
+vreplace +wildignore +wildmenu +windows +writebackup +X11 -xfontset +xim
+xsmp_interact +xterm_clipboard -xterm_save
system vimrc file: "$VIM/vimrc"
user vimrc file: "$HOME/.vimrc"
user exrc file: "$HOME/.exrc"
system gvimrc file: "$VIM/gvimrc"
user gvimrc file: "$HOME/.gvimrc"
system menu file: "$VIMRUNTIME/menu.vim"
fall-back for $VIM: "/usr/local/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_GTK -I/usr/include/gtk-2.0 -I/usr/lib64/gtk-2.0/include -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng14 -g -O2 -D_FORTIFY_SOURCE=1
Linking: gcc -L/usr/local/lib -o vim -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0 -lgio-2.0 -lpangoft2-1.0 -lgdk_pixbuf-2.0 -lpangocairo-1.0 -lcairo -lpango-1.0 -lfreetype -lfontconfig -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lXt -lncurses -lacl -lgpm -L/usr/lib64/python2.6/config -lpython2.6 -lpthread -lutil -lm -Xlinker -export-dynamic
推荐答案
我可以重现行为,根据您的描述,这确实(乍一看)似乎是一个错误.但我注意到以下几点:
I can reproduce the behaviour, which with your description would (at first sight) appear to be a bug, indeed. But I noticed the following things:
:vert split
与
:debug ver split
(... cont
) 确认没有明显的脚本/自动命令干扰
:debug ver split
(... cont
) confirmed there wasn't an obvious script/autocommand interfering
它只在第一次拆分时发生.换句话说,这是一种解决方法:
It only happens on the first time split. In other words, this is a workaround:
光标实际上没有在原始窗口中移动.新窗口"出现在左侧(您将其命名为原始窗口).这不能用 :echo winnr()
或类似方法显示,但您可以通过执行例如使其更明显:vert new
而不是 :vert split
:新的空窗口出现在左侧.
the cursor does in fact not move in the original window. The 'new window' appears on the left (which you name the original window). This cannot be shown with :echo winnr()
or similar, but you can make it more apparent by doing e.g. :vert new
instead of :vert split
: the new, empty window appears on the left side.
取而代之的是,您可能会通过在之前做一些无用"的事情来欺骗拆分以具有第二次拆分"行为
Instead of this, you might trick the split to have 'second split' behaviour by doing something 'useless' before
:tabnew|bwipeout
现在, 首次获得了所需的行为.
Now, has the desired behaviour first time around.
- 这不是错误(您对 新 窗口的期望已关闭)
- 您可以先创建另一个窗口来解决这个问题.
其他背景
splitright
、splitbelow
选项
可用于控制(在一定程度上)新创建(拆分)窗口出现的位置
winrestview()
函数
可用于显式恢复窗口的精确视图.像这样使用它:
:let savex=winsaveview()
savex
现在包含类似 {'lnum': 1, 'leftcol': 0, 'col': 0, 'topfill': 0, 'topline':1, 'coladd': 0, 'skipcol': 0, 'curswan': 0}
描述当前视图的状态.
savex
now contains something like {'lnum': 1, 'leftcol': 0, 'col': 0, 'topfill': 0, 'topline': 1, 'coladd': 0, 'skipcol': 0, 'curswant': 0}
describing the state of the current view.
(做一些事情,比如)
:call winrestview(savex)
这显然更灵活,但您可能不需要它.
This is obviously a lot more flexible but you might not need it.
这篇关于窗口拆分时 Vim 缓冲区位置更改(烦恼)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!