{"action":"created","issue":{"url":"https://api.github.com/repos/jszakmeister/vim-togglecursor/issues/19","labels_url":"https://api.github.com/repos/jszakmeister/vim-togglecursor/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/jszakmeister/vim-togglecursor/issues/19/comments","events_url":"https://api.github.com/repos/jszakmeister/vim-togglecursor/issues/19/events","html_url":"https://github.com/jszakmeister/vim-togglecursor/issues/19","id":96577330,"number":19,"title":"[Bug] Vim cursor sometimes (always?) disappears on Vim startup when opening a file","user":{"login":"phongvcao","id":874795,"avatar_url":"https://avatars.githubusercontent.com/u/874795?v=3","gravatar_id":"","url":"https://api.github.com/users/phongvcao","html_url":"https://github.com/phongvcao","followers_url":"https://api.github.com/users/phongvcao/followers","following_url":"https://api.github.com/users/phongvcao/following{/other_user}","gists_url":"https://api.github.com/users/phongvcao/gists{/gist_id}","starred_url":"https://api.github.com/users/phongvcao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phongvcao/subscriptions","organizations_url":"https://api.github.com/users/phongvcao/orgs","repos_url":"https://api.github.com/users/phongvcao/repos","events_url":"https://api.github.com/users/phongvcao/events{/privacy}","received_events_url":"https://api.github.com/users/phongvcao/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-22T14:08:22Z","updated_at":"2015-07-22T14:31:49Z","closed_at":null,"body":"For some reasons my cursor keeps disappearing if I opened a file in Vim (using ```vim /path/to/file``` command) inside gnome-terminal with tmux and powerline. When I change my mouse focus from gnome-terminal to another window (I am using Vim under terminal), OR replace ```vim-togglecursor``` with this snippet of Vimscript inside my ```.vimrc```:\r\n\r\n```vim\r\n\" Toggle cursor between block and ibeam shape in different modes (Insert,\r\n\" Normal, Visual, Replace. Also make them blink.\r\nfunction! ToggleCursorByMode()\r\n    if exists('$TMUX')\r\n        if v:insertmode == 'r' || v:insertmode == 'v'\r\n            let &t_SI = \"\\<Esc>Ptmux;\\<Esc>\\e[3 q\\<Esc>\\\\\"\r\n        else\r\n            let &t_SI = \"\\<Esc>Ptmux;\\<Esc>\\e[5 q\\<Esc>\\\\\"\r\n        endif\r\n\r\n        let &t_EI = \"\\<Esc>Ptmux;\\<Esc>\\e[0 q\\<Esc>\\\\\"\r\n\r\n    else\r\n        if v:insertmode == 'r' || v:insertmode == 'v'\r\n            let &t_SI = \"\\e[3 q\"\r\n        else\r\n            let &t_SI = \"\\e[5 q\"\r\n        endif\r\n\r\n        let &t_EI = \"\\e[0 q\"\r\n    endif\r\nendfunction\r\n\r\ncall ToggleCursorByMode()\r\n\r\naugroup AutoCursor\r\n    autocmd InsertEnter * :call ToggleCursorByMode()\r\nautogroup END\r\n```\r\n\r\nEverything was working as expected. Without the above snippet of codes, sometimes even during cursor moving in Normal mode, my cursor disapearred and I had to move the mouse focus to another window beside gnome-terminal again and then move back.\r\n\r\nI believe there is currently a problem of ```autocmd VimEnter *``` statement in ```plugin/togglecursor.vim``` unable to load ```<SID>ToggleCursorInit()``` at Vim startup, because as long as I replaced ```vim-togglecursor``` with the above code, OR tried to move focus to another window (which triggered ```FocusGained``` & ```FocusLost```), the cursor started working again. So I guess you may want to add an ```autocmd BufWinEnter *``` OR invoking <SID>ToggleCursorInit() outside of autocmd (so it will be run when Vim sources the ```.vimrc``` file).\r\n\r\nHere is my version information:\r\nOS: Arch Linux\r\nShell: zsh 5.0.8\r\nMultiplexor: tmux 2.0\r\nVim: VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jul 11 2015 08:44:54)\r\nIncluded patches: 1-778\r\nGNOME: Version 3.16.2\r\n"},"comment":{"url":"https://api.github.com/repos/jszakmeister/vim-togglecursor/issues/comments/123741967","html_url":"https://github.com/jszakmeister/vim-togglecursor/issues/19#issuecomment-123741967","issue_url":"https://api.github.com/repos/jszakmeister/vim-togglecursor/issues/19","id":123741967,"user":{"login":"phongvcao","id":874795,"avatar_url":"https://avatars.githubusercontent.com/u/874795?v=3","gravatar_id":"","url":"https://api.github.com/users/phongvcao","html_url":"https://github.com/phongvcao","followers_url":"https://api.github.com/users/phongvcao/followers","following_url":"https://api.github.com/users/phongvcao/following{/other_user}","gists_url":"https://api.github.com/users/phongvcao/gists{/gist_id}","starred_url":"https://api.github.com/users/phongvcao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phongvcao/subscriptions","organizations_url":"https://api.github.com/users/phongvcao/orgs","repos_url":"https://api.github.com/users/phongvcao/repos","events_url":"https://api.github.com/users/phongvcao/events{/privacy}","received_events_url":"https://api.github.com/users/phongvcao/received_events","type":"User","site_admin":false},"created_at":"2015-07-22T14:31:49Z","updated_at":"2015-07-22T14:31:49Z","body":"Okay I believe I found where the problem lies: It is in this line of code in ```plugin/togglecursor.vim```. When I commented it out, everything worked again as expected:\r\n\r\n```vim\r\nlet &t_ti = s:GetEscapeCode(g:togglecursor_default) . &t_ti\r\n```\r\n\r\nThe reason is this line of code makes ```&t_ti``` equal to ```^[Ptmux;^[^[[2 q^[\\^[Ptmux;^[^[[?1004h^[\\^[[?1004h^[[?1049h``` while in fact ```&t_ti``` must be equal to ```^[Ptmux;^[^[[?1004h^[\\^[[?1004h^[[?1049h``` for the cursor to work. \r\n\r\nSo instead of using concatenation like above, you can either comment it out, or not using concatenation at all, or only using concatenation if we are inside Konsole:\r\n\r\n```vim\r\nif s:supported_terminal == 'cursorshape'\r\n    let &t_ti = s:GetEscapeCode(g:togglecursor_default) . &t_ti\r\nendif\r\n```"}}