Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After being opened then closed once, files are always opened in a horizontal split regardless of the command used #298

Closed
gmalkas opened this issue Jul 7, 2017 · 6 comments

Comments

@gmalkas
Copy link

gmalkas commented Jul 7, 2017

Hi,

I'm having some weird issue with opening files from command-t.

It works as expected at first (<C-v> opens in a vertical split, <CR> opens in the current buffer, etc) but then when opening the same file every mapping opens in a horizontal split. Opening a file that was not opened yet in the current vim process works as expected.

Here's an example:

Expected Behavior

When opening user.ex for the second time using <C-v>, it should be opened in a vertical split.

Observed Behavior

It is opened in a horizontal split.

All subsequent opening of a file that was already opened (then closed) leads to a horizontal split, regardless of the command used.

Setup

I'm running on Mac OS X with iterm2, vagrant and a Ubuntu VM. I've tried outside of tmux and the same behavior is observed. I have stty -ixon in my .profile.

I've removed all plugins apart from command-t before testing (I'm using pathogen, I simply directed pathogen to a different folder than bundle containing only command-t).

Of course I'm not 100% sure it's due to a command-t bug, but the fact that it initially works properly seems to rule out any kind of weird keybinding interaction between iterm/tmux/bash/vim.

Note: I'm pretty sure I pulled from master a week or two ago so it may have appeared recently. Not 100% sure though so to take with a grain of salt.

.vimrc

I've tried with the following "minimal" .vimrc and it still behaved as described:

set encoding=utf-8

execute pathogen#infect('temp/{}')

syntax enable

filetype plugin on
filetype indent on

let mapleader = "\<Space>"

vim --version

I've compiled vim myself as I wanted some additional support for clipboard server-side:

VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Jun 25 2017 12:00:29)
Included patches: 1-675
Compiled by vagrant@ubuntu
Huge version with X11-Athena GUI.  Features included (+) or not (-):
+acl             +file_in_path    +mouse_sgr       +tag_old_static
+arabic          +find_in_path    -mouse_sysmouse  -tag_any_white
+autocmd         +float           +mouse_urxvt     -tcl
+balloon_eval    +folding         +mouse_xterm     +termguicolors
+browse          -footer          +multi_byte      +terminfo
++builtin_terms  +fork()          +multi_lang      +termresponse
+byte_offset     -gettext         -mzscheme        +textobjects
+channel         -hangul_input    -netbeans_intg   +timers
+cindent         +iconv           +num64           +title
+clientserver    +insert_expand   +packages        +toolbar
+clipboard       +job             +path_extra      +user_commands
+cmdline_compl   +jumplist        -perl            +vertsplit
+cmdline_hist    +keymap          +persistent_undo +virtualedit
+cmdline_info    +lambda          +postscript      +visual
+comments        +langmap         +printer         +visualextra
+conceal         +libcall         +profile         +viminfo
+cryptv          +linebreak       -python          +vreplace
+cscope          +lispindent      +python3         +wildignore
+cursorbind      +listcmds        +quickfix        +wildmenu
+cursorshape     +localmap        +reltime         +windows
+dialog_con_gui  -lua             +rightleft       +writebackup
+diff            +menu            +ruby            +X11
+digraphs        +mksession       +scrollbind      +xfontset
-dnd             +modify_fname    +signs           +xim
-ebcdic          +mouse           +smartindent     +xpm
+emacs_tags      +mouseshape      +startuptime     +xsmp_interact
+eval            +mouse_dec       +statusline      +xterm_clipboard
+ex_extra        -mouse_gpm       -sun_workshop    -xterm_save
+extra_search    -mouse_jsbterm   +syntax
+farsi           +mouse_netterm   +tag_binary
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/home/vagrant/tools/vim/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_ATHENA     -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -fstack-protector -rdynamic -Wl,-export-dynamic  -L/usr/local/lib -Wl,--as-needed -o vim -lXaw -lXmu -lXext -lXt -lSM -lICE -lXpm -lXt -lX11 -lXdmcp -lSM -lICE -ldl  -lm -ltinfo -lnsl   -ldl     -L/usr/lib/python3.5/config -lpython3.5m  -Wl,-R/home/vagrant/.asdf/installs/ruby/2.4.1/lib -L/home/vagrant/.asdf/installs/ruby/2.4.1/lib -lruby -lpthread -lgmp -ldl -lcrypt -lm

Thank you for your time and thanks a ton for the amazing work on command-t, it's an essential part of my workflow.

@wincent
Copy link
Owner

wincent commented Jul 8, 2017

Thanks for the awesome bug report @gmalkas. I haven't seen this myself, but I'll see whether I can repro using your recipe.

@wincent
Copy link
Owner

wincent commented Jul 11, 2017

I haven't been able to repro this. What version of Command-T are you using? What is the output of :verbose set swb?.

@gmalkas
Copy link
Author

gmalkas commented Jul 11, 2017

:verbose set swb? gives me switchbuf=usetab (I actually set it in my .vimrc after reading about it in some Github issue here)

As for Command-T version:

* 29f2606 - (HEAD -> master, origin/master, origin/HEAD) Prefer longer, more explicit command names (3 weeks ago) <Greg Hurrell>

Let me know if there's anything else I can try. Thanks!

@gmalkas
Copy link
Author

gmalkas commented Jul 11, 2017

@wincent So I went debugging with the good old file.write("I am here") and here's what I found.

The Ruby code is doing the correct thing as far as I can tell, it's passing the proper command to the vimscript (e.g. vsplit when I do <C-v> on the selection).

The vimscript is where the issue is. I've changed autoload/commandt.vim#159 with the following:

  if bufwinnr('^' . l:file . '$') != -1 ||
        \ (bufexists(l:file) && !s:BufHidden(l:file))
    call writefile(["I am in the if"], "/tmp/gotooropen.log")
    execute 'sbuffer ' . l:file
  else
    call writefile(["I am in the else"], "/tmp/gotooropen.log")
    execute l:command . l:file
  endif

When I open with a vertical split the first time and it works, I see "I am in the else". When I try a vertical split again, I see "I am in the if".

bufwinnr('^' . l:file . '$') always evaluates to -1 so that's not the issue. bufexists(l:file) is 0 at first but evaluates to 1 the second time I open the same file, although of course I've closed it at this point. !s:BufHidden(l:file) evalutes to 1.

The issue is that bufexists(l:file) matches both lib/discord/api.ex and lib/discord/api/user.ex so as long as I have lib/discord/api.ex open, lib/discord/api/user.ex will always open horizontally.

Changing bufexists(l:file) to bufexists('^' . l:file . '$') seems to have fixed the problem.

Let me know if all that makes sense to you.

Thanks again for taking a look.

@wincent
Copy link
Owner

wincent commented Jul 12, 2017

The issue is that bufexists(l:file) matches both lib/discord/api.ex and lib/discord/api/user.ex so as long as I have lib/discord/api.ex open, lib/discord/api/user.ex will always open horizontally.

No wonder my simple attempt at reproing didn't work.

Changing bufexists(l:file) to bufexists('^' . l:file . '$') seems to have fixed the problem.

Thanks for digging in to that!

@wincent
Copy link
Owner

wincent commented Jul 12, 2017

Let's see if that fixes it without breaking any other use cases. If it does, we'll squish them as they come up.

ZyX-I pushed a commit to powerline/deps that referenced this issue Jul 31, 2017
vim-plugins/command-t tip:

    commit 85949ce7a70a26abf6f9d355e38d1473facba022
    Author: Greg Hurrell <[email protected]>
    Date:   Tue Jul 11 18:35:24 2017 -0700

        Fix unwanted split opening behavior

        Similar to the fix we applied in 595976eb70ba3a2f7a2932eeb4 to fix
        wincent/command-t#295 looks like we have to
        deal with this edge case too.

        Closes wincent/command-t#298
wincent added a commit that referenced this issue Sep 6, 2017
This is a regression introduced in 85949ce.

That one attempted to fix #298 by applying a similar fix to the one used
in #295. However, it only worked by luck: `bufexists()` doesn't support
patterns or use of "$"/"^" to anchor the match like `bufwinnr()` does.
This meant that adding those anchors made it always false.

That fixed the unwanted splits in #298, but it meant that you couldn't
go back to an existing file in another tab.

The fix is pretty straightforward: switch from `bufexists()` to
`bufname()`, because the latter does support anchoring. As far as I can
tell, this fixes #306 without breaking the scenario detailed in #298.
The one gotcha here is that we can't rely on the truthiness of the
non-empty string returned by `bufname()` here, because crazy old
Vimscript coerces also strings to `0`; we therefore have to use an
explicit check against `''`.

Closes: #306
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants