I recently upgraded to Ubuntu 16.04 and this problem returned. I vaguely recall fixing it on 14.04 but I can't remember how.
I've got the tmux window split into two panes. vim is running in the left pane displaying a file. If the vim cursor is on a parenthesis of any sort when I switch panes, the parenthesis will become a caret on the display though it isn't changed in the file. Switching back to vim and moving the cursor will cause it to redraw correctly.
Outside of tmux TERM is gnome-256color. Inside tmux TERM is screen-256color.
Any ideas on what is causing this?
Update
I can make it happen by simply changing focus using Alt-Tab. That is, I don't need to switch tabs in tmux. Simply moving focus around the screen will cause it to happen.
Update2
It turns out it was unrelated to gnome-terminal so I removed references to it.
This was happening because of vim's parenthesis highlighting on matching.
From :help matchparen
The functionality mentioned here is a standard-plugin.
This plugin is only available if 'compatible' is not set.
You can avoid loading this plugin by setting the "loaded_matchparen" variable:
:let loaded_matchparen = 1
The plugin installs CursorMoved, CursorMovedI and WinEnter autocommands to
redefine the match highlighting.
:NoMatchParen :DoMatchParen
To disable the plugin after it was loaded use this command:
:NoMatchParen
And to enable it again:
:DoMatchParen
You can use autocommands to toggle this.
Something like
:autocmd FocusLost * :NoMatchParen
:autocmd FocusGained * :DoMatchParen
Should work.
You can use tmux-focus-events.vim plugin if your console vim doesn't support these autocommands
Also take a look at this post in unix stachexchange.
Related
When I run, for example, ! yarn lint inside a MacVim. I have this result.
While I run the same command in Terminal's Vim. This is what I get.
Is there any way to make the former colourised as the latter?
The shell used by the MacVim GUI for :! commands is a so-called "dumb shell" that doesn't support styling at all so you can't have colors, there. If you absolutely need styled output, use the built-in :help :terminal.
That said, command-line utilities are expected to know when and when not to use styling. Since the ones you use appear to output escape sequence when they shouldn't, it might be a good idea to notify their maintainers of that flaw.
The reason why you are seeing the different color schemes is because the Terminal and MacVim editor each have their own application-specific configurations, which includes the theme. However, it is possible to unify the two applications to share the same Vim settings in a .vimrc file. The default .vimrc that MacVim looks for is located under $HOME/.vimrc, and the same goes for the Terminal’s version of Vim. If you like the dark background that is being used in the Terminal’s Vim, you can set it with:
set background=dark
I also highly recommend you read up, at least to a basic understanding, on the .vimrc settings.
There are also some good examples out there:
https://gist.github.com/simonista/8703722
https://github.com/amix/vimrc/tree/master/vimrcs
So I followed romainl's suggestion and came up with a solution.
First, :terminal ++close yarn format does colour the terminal result nicely, so I updated my mapping.
map <Leader>l :terminal ++close yarn format<CR>
Then to fix the auto-reload problem. This is what I did.
set autoread
au CursorHold,CursorHoldI * checktime
au FocusGained,BufEnter * :checktime
Thanks to resources from this thread!
https://unix.stackexchange.com/questions/149209/refresh-changed-content-of-file-opened-in-vim
Due to various reasons, I run Vim at sixteen-colors, synced w/ my terminal's colors. In a recent Vim update, I've had to rework my "~/.vimrc" completely to get it back into running order on Linux.
Initially I was shocked to find that this simple line did not work (even w/ "syntax on" preceding it):
:highlight Comment ctermfg=White
I'm also using a "LineNr" ctermfg. No matter where I placed/stacked the "Comment" ctermfg, it didn't work, or interfered w/ everything else sourcing correctly (ie, placed in the same line w/ "LineNr"). However, I found that calling "Comment" after a buffer had loaded would make the comments appear as intended.
I am new to autocmd in Vim (and want to know how it works, anyways). Is there an "autocmd" call that I can have in my "~/.vimrc" that will run the aforementioned line of code immediately after a buffer has loaded?
I have tried several iterations (BufWritePre, BufWritePost, etc.) and been unsuccessful. This was my previous attempt:
autocmd BufWinPost * :highlight Comment ctermfg=white
Don't resort to :autocmd without reason; search harder for the root cause!
Your description lacks specifics; I guess your chosen colorscheme (or a plugin, but no sane plugin should interfere with the default highlightings) overrides your custom one for Comment. You can check who defined this via
:verbose highlight Comment
If this points to your colorscheme, you simply need to execute your :highlight command after it. For this, you need to understand :help initialization, and maybe check the output of :scriptnames. If you have a :colorscheme foo command in your ~/.vimrc, it should be as simple as putting the :highlight command after it.
You do need an :autocmd if you switch colorschemes on the fly, as most colorschemes override the basic Comment definition. The correct event and pattern for that would be ColorScheme *
If I do a quick :h autocmd-events, I find the the event BufWinPost does not exist. I think, you want BufWinEnter instead. The autocmd you wrote should work, except for the :. HTH
I recently discovered Vim colorschemes, and in the process have discovered a rather curious bug: when I run hi Normal ctermbg in Vim, the color change carries over to the shell that I'm running Vim in, like so:
I'm using PuTTYtray (but also see the behavior in PuTTY) with 256 colors enabled , bolded text indicated by font changes, and $TERM set to "putty-256color"; my .vimrc is as follows:
set t_Co=256
colors zenburn
and zenburn.vim can be found here. I've isolated the problem specifically to specifically line 298, where it first configures ctermbg for Normal highlighting.
(As an aside: it seems that when using PuTTY tray with specific color settings, in Normal highlighting, ctermbg has to be first set simultaneously with guifg or guibg, e.g. hi Normal guifg=#dcdccc ctermbg=237, and only after that will hi Normal ctermbg=some_val work.)
Does anyone happen to have any idea why this is happening?
I've also tried to do a workaround by running hi Normal ctermbg=None on VimLeave (although I recognize that this is problematic if I run multiple Vim instances, so if anyone can suggest an alternative that would also be welcome), but with no success. Adding the following to my .vimrc does not work:
function! RESET_ctermbg()
"reset $ctermbg to None"
exec "hi Normal ctermbg=None"
endfunction
au VimLeave * call RESET_ctermbg()
I've fixed the problem by changing $TERM to xterm-256color; my best bet is that putty-256color is not well-supported enough as a shell to handle behavior like the vim colorscheme I was doing, so I don't even need to try to make the workaround work anymore.
I've set this on my .vimrc:
let g:clang_snippets=1
let g:clang_snippets_engine='clang_complete'
let g:clang_conceal_snippets=1
set conceallevel=2 concealcursor=inv
I don't know how conceal is expected to work, maybe the clang_complete's docs should have a tip for a specific setting to hide the snippets adorns.
How do I hide it? I'm using MacVim built with +conceal, but it's not working. This is my messy .vimrc by now.
NOTE:
I'm sticking with g:clang_snippets_engine='clang_complete' because it seems to be more smart than the snipMate parameter completion, switching to NORMAL mode is a wiser choice to navigate between parameters since I can use SuperTab completion for params in INSERT mode while being able to navigate through them with the same tab at NORMAL mode. snipMate engine was acting weird to me sometimes too, sometimes it switched to a parameter after a completion, sometimes not.
Also, I'm missing a final tab to go after the last parameter, right after the function call (snipMate does that), so I can just insert ; and hit Enter.
Disclaimer: This question is related with the issue at https://github.com/Rip-Rip/clang_complete/issues/176.
EDIT:
My problem was with this line at my .vimrc:
au BufNewFile,BufRead *.cpp set syntax=cpp11
I'm using C++11 Syntax Support and #xaizek has discovered and pointed it out as the problem in the comments bellow in the accepted response, it seems the root cause is the use of the syntax clear command in it.
According to :help 'concealcursor':
Sets the modes in which text in the cursor line can also be concealed.
When the current mode is listed then concealing happens just like in
other lines.
n Normal mode
v Visual mode
i Insert mode
c Command line editing, for 'incsearch'
So with concealcursor=iv you asked Vim to hide concealed text in insert and visual modes, but show it in normal mode. So just do:
:set concealcursor=inv
Since mac os x's terminal.app does not support many of the vim visual aspects, including the cursor change from block to line when switching to insert mode, I use osascript to accopmlisch something similar.
In my .vimrc file I've written:
autocmd InsertEnter * silent !osascript -e 'tell application "Terminal" to set current settings of first window to settings set 11`j
autocmd InsertLeave * silent !osascript -e 'tell application "Terminal" to set current settings of first window to settings set 12`j
where settings set 11 is a set of terminal setting that has a line cursor and settings set 12 is one that has a block cursor.
This actually works quite well but there is one small problem.. On InsertLeave the cursor always gets moved one character to the left, which isn't such a big deal but it can be anoying.
I tried to compensate by putting autocmd InsertLeave h into my .vimrc, but to no avail (it gives me an error).
How should I tell vim to:
not shift to the left?
if the above isn't possible, to compensate by shifting to the right
Before answering the question, I'd recommend you to have a look in MacVim (if you haven't). If you would like (or need) to stick with terminal, maybe another terminal like iTerm will provide more functionality. Anyway, the cursor change between block - bar is not present in iTerm (at least I think so) and your way to solve it was phenomenal, it's bookmarked here now. Thanks!
An easy way to solve it would be adding another autocommand, like you said. But in yours, the pattern and the correct command to execute are missing.
The h is not a command. To execute a normal mode sequence, use the :normal command. This may work correctly:
au InsertLeave * normal! h