`vimdiff` not compatible with autocmd? - vim

I was used to use vimdiff and loading the compared files.
Now, on vimdiff execution, it happens:
"a" [readonly] 5454L, 269796C
"b" [readonly] 241L, 10170C
Press ENTER or type command to continue
The only configuration change is the introduction of these two autocmd instructions:
autocmd BufNewFile * call s:Function()
autocmd BufReadPre * call s:Function()
Can this be a normal behavior? Can it be a mistake of mine? Can be something depending on Vim versioning? Can the desired configuration change be combined with a straightforward vimdiff load (no ENTER key needed to continue)?

The dreaded hit-enter prompt is usually triggered by additional :echo[msg] commands, here inside your s:Function(). Either remove them, or silence the output via :silent:
autocmd BufNewFile * silent call s:Function()

If you want to keep whatever messages are displayed in your function, you can set your 'cmdheight' option higher to allow displaying more messages before the "hit enter" prompt appears. This, and other suggestions here: http://vim.wikia.com/wiki/Avoiding_the_"Hit_ENTER_to_continue"_prompts

Related

is it possible to set BufLeave autocmd in vim on the fly?

What I want to do:
Inside a file/buffer in vim, especially an unnamed one (for example, created with :enew), sometimes I feel the content I'm writing is worth saving (say, I suddenly want to send it via an email), but don't feel the particular need to save it to a temp file, nor do I trust myself enough to "remember" to save it upon exit.
So I thought, what if I run
autocmd BufLeave * ggvG"+y
in the vim command line once and be free from the fear of losing this content.
But it doesn't work. When I exit vim, the system clipboard reminds intact.
My questions:
does it do anything if we run autocmd on the fly, as opposed to in vimrc?
is there a way to tell vim to "hey, when you exit, run these"?
Thanks a ton!
Two problems:
1) You didn't leave the buffer to go to another buffer (BufLeave); you left Vim (VimLeave).
2) autocmd expects a command, not normal mode keystrokes.
With that in mind,
autocmd VimLeave * normal gg"+yG

How can I get rid of this "Auto Commands" message from vim?

If I have this line in my vimrc
au VimLeave %bdelete
Then whenever vim starts it says
--- Auto-Commands ---
Press ENTER or type command to continue
I have that line there to empty the buffers from gvim, because new gvim instances have massive :ls output from previous runs. Notably, gvim doesn't actually produce this prompt.
Obviously I can set this instance up to only occur during gvim startup and not console vim, but I'd like to understand this rather than avoid it. Mostly I'm confused that VimLeave seems to cause things to happen on startup.
TIA
Altreus
The problem is that this is an incomplete :autocmd definition, so Vim attempts to list all VimLeave autocommands defined for the pattern %bdelete. You need to specify the any file pattern to make it work:
au VimLeave * %bdelete
Also, check whether you have % in your 'viminfo' option; that one enables the saving and restoring of the buffer list you're complaining about. The f option of file marks may also result in buffers being restored; you could try :set viminfo+=f0.
New Vim instances don't inherit the buffer list of the previous instance unless you add % to the viminfo option.
Setting that option to a sane value will remove the need for your broken fix. Reading the documentation before adding options to your config will prevent you from similar issues.
See :help 'viminfo'.

Hide information below status line

I have laststatus=2 and the statusline with a file name and stuff. I'd like to get rid of the information shown below the status in the command area. Setting noruler has no effect. The text looks e.g. after switching buffers like this:
"localization.cpp" [Modified] line 60 of 118 --50%-- col 1 ((1) of 9)
Any idea?
When switching buffers, Vim prints a message similar to the one in your question (though I don't recognize the exact format). The verbosity of this can be influenced via the 'shortmess' option, but to completely turn this off, you'd have to override the buffer switch commands / mappings to use :silent.
It might also be a custom :autocmd that prints those messages. Can you reproduce this with a plain vim -N -u NONE, and does it disappear when you :set eventignore=all?!
Edit: Since this seems to be the default message from Vim, you can only workaround this by explicitly clearing it via an :autocmd:
:autocmd BufWinEnter * call feedkeys("\<C-\>\<C-n>:\<CR>", 'n')

tail like functionality for gvim

I want to use gvim to view a log file which is being updated continuously, such that I always see the last updated line, much like tail command in unix. Is it possible?
Open logfile and
:setlocal autoread
There is a plugin (Tail Bundle) on the vim site.
I like it short and without a lot of hacking or external scripts.
You can run this oneliner from ex (whithin vim) when needed (or put each command in vimrc, for when log-files are opened.)
:set autoread | au CursorHold * checktime | call feedkeys("lh")
and additionally you can :set syntax=logtalk to color the log
(if you would want to jump (nearly) to the end of the file, just use "G" instead of "lh" with feedkeys)
Explanation:
autoread: reads the file when changed from the outside (but it doesnt work on its own, there is no internal timer or something like that. It will only read the file when vim does an action, like a command in ex :!
CursorHold * checktime: when the cursor isn't moved by the user for the time specified in updatetime (which is 4000 miliseconds by default) checktime is executed, which checks for changes from outside the file
call feedkeys("lh"): the cursor is moved once, right and back left. and then nothing happens (... which means, that CursorHold is triggered, which means we have a loop)
To stop the scrolling when using call feedkeys("G"), execute :set noautoread - now vim will tell, that the file was change ans ask if one wants to read the changes or not)
*from this answer (refering to an answer by PhanHaiQuang and a comment by flukus)
Or a less elegant solution on a vim 7.x would be just do :e! whenever you need the update .

Using vim Sessions Only With GUI?

My usage-scenario may seem a bit unusual, but here it is: When using vim (it's one of about 4 different editors I use regularly), I use it in two different situations. The first is via the GUI, in which I'll have multiple buffers and have some settings different than when I use it from the command-line (by testing "if has('gui_running')"). The other is when I need to do something short-and-quick, from the command-line, such as make a small change to a dot-file or other type of config.
What I would like to do, is have sessions enabled for the GUI, but have any command-line invocations ignore them. That is, I don't want to bring up the full existing session on a CL invocation, nor do I want it (and whatever buffer/file it involved) to alter the session that the GUI is using. As I'm fairly new to the post-vi-functionality of vim, I'm not really sure how to pull this off.
do your session magic in your .gvimrc and everything else in your .vimrc. The GUI will source both, but the CL version will only source the .vimrc.
The session magic is to set up autocommands to write your session to a file on exit, and reload it by sourcing the file upon entrance.
au VimLeave * mksession ~/.gvimsession
au VimEnter * source ~/.gvimsession
You may want to add a ! to mksession so that you won't get an override error message upon exiting everytime.
au VimLeave * mksession! ~/.gvimsession
au VimEnter * source ~/.gvimsession

Resources