Tracing Vim into a log file.

177 views
Skip to first unread message

Eddine

unread,
Oct 20, 2011, 5:49:19 PM10/20/11
to vim...@googlegroups.com
Hello
 
Yet another question, I have a strange behavior in my Vim at work.
I often edit logs from process still working and still writing the log I'm reading in VIm (I have set autoread so it reloads)
and I often have a behavior where my file is like folded ;
All the part from the line 1 to current position of cursor disapears  and let this charcter g`
 
let says I Have
 
line1
line2
line3
line4
line5
line6  X <--- position of the cursor
line7
line8
line9
line10
etc...
 
I then have
 
 
g`line6 X
line7
line8
line9
line10
etc...
 
 
Entering command :0
bring me back my whole file.
 
I really don't know what happens.
Is there a way I can trace Vim into a log to know what happens?
 
 
Thank you for your attention.
 
Eddine.
 
 
 

Tony Mechelynck

unread,
Oct 20, 2011, 6:35:18 PM10/20/11
to vim...@googlegroups.com, Eddine

I don't know what happened, just that :0 is supposed to bring you to
"line zero" (but since there is no such line, you get to the first line
instead).

Maybe there was a missing refresh?

Try opening your logfile in readonly mode (e.g. with :view rather than
:edit, :sview rather than :new, gview rather than gvim, view rather than
vim, etc.) and if you still have the problem, try Ctrl-L to redraw the
screen.

BTW, trying to write a single file from two processes at the same time
(such as Vim and the log-writing process) is courting disaster. If you
do, you're bound to get problems sooner rather than later.


Best regards,
Tony.
--
Alexander Graham Bell is alive and well in New York, and still waiting
for a dial tone.

Marc Weber

unread,
Oct 20, 2011, 6:41:53 PM10/20/11
to vim_use
Excerpts from Eddine's message of Thu Oct 20 23:49:19 +0200 2011:
> Entering command :0
Can't you just try <c-l> (which is same as :redraw?)

> I really don't know what happens.
Neihter do I, but pressing c-l may be bearable.

You can debug by vim -V20/tmp/log (viml only).
And you can set cursor debugging (eg one sending bytes to terminal very
slowely), see :h writedelay. That's all I know about. Not sure whether
this is going to help you much though.

Marc Weber

Tony Mechelynck

unread,
Oct 21, 2011, 10:43:20 AM10/21/11
to Eddine, Vim List
On 21/10/11 00:44, Eddine wrote:
> >BTW, trying to write a single file from two processes at the same time
> (such as Vim and the log-writing process) is >courting disaster. If you
> do, you're bound to get problems sooner rather than later.
>
> about the vim log, I mean is there a way to write Vim actions into a
> sperate file of its own ? Not into the file I am editing/reading.

Ah, OK. The fact that you talked about "editing" the logfile (not about
"viewing" it) made me think that you tried to modify it in Vim while the
program writing it was still running.

See:
:help -w
:help -V
and about the latter:
:help 'verbose'
:help 'verbosefile'

Best regards,
Tony.
--
Not far from here, by a white sun, behind a green star, lived the
Steelypips, illustrious, industrious, and they hadn't a care: no spats
in their vats, no rules, no schools, no gloom, no evil influence of the
moon, no trouble from matter or antimatter -- for they had a machine, a
dream of a machine, with springs and gears and perfect in every
respect. And they lived with it, and on it, and under it, and inside
it, for it was all they had -- first they saved up all their atoms,
then they put them all together, and if one didn't fit, why they
chipped at it a bit, and everything was just fine ...
-- Stanislaw Lem, "Cyberiad"

Eddine

unread,
Oct 26, 2011, 4:39:37 PM10/26/11
to vim...@googlegroups.com
Hi
I had this strange behavior again this afternoon,
so I was editing a file, that was being modified by a java process who was writing in it.
And I don't know what happens (maybe a mousse scroll or something like that) and the whole part before the line is erased and I got : g`" instead.
 
I have been able to take a picture with my phone (they are so paranoid in my firm that I avoided to make a screenshot sent by email)  it can be seen here:
 
I tried :redraw, CTrl-L nothing to do.
The strange thing is that the file is not written, cause when I close it vim doesn't ask me if I want to save, and re-opening bring it back to me.
 
Any ideas ?
 
Eddine.



2011/10/20 Eddine <bmok...@googlemail.com>

Benjamin R. Haskell

unread,
Oct 26, 2011, 5:02:02 PM10/26/11
to vim...@googlegroups.com
On Wed, 26 Oct 2011, Eddine wrote:

> Hi
> I had this strange behavior again this afternoon, so I was editing a
> file, that was being modified by a java process who was writing in it.
> And I don't know what happens (maybe a mousse scroll or something like
> that) and the whole part before the line is erased and I got :
> g`" instead.
>  
> I have been able to take a picture with my phone (they are so paranoid
> in my firm that I avoided to make a screenshot sent by email)  it can
> be seen here:
> http://www.flickr.com/photos/69121410@N06/6284304680/in/photostream/lightbox/
>  
> I tried :redraw, CTrl-L nothing to do.
> The strange thing is that the file is not written, cause when I close
> it vim doesn't ask me if I want to save, and re-opening bring it back
> to me.
>  
> Any ideas ?

To me it looks like it's a malfunctioning autocmd, which doesn't
anticipate being called when it's being called. (Pretty sure 'autoread'
doesn't kick in in Insert mode.)

As pointed out in:

:help g`

g`"

jumps to the last known position in a file. So, it's commonly added to
systemwide /etc/vimrc autocmds so that opening a file again will start
you in the same place you were at when you last stopped editing it.

A common example is included in the example rc, IIRC. On Gentoo, it's:

" [...inside augroup gentoo]
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if ! exists("g:leave_my_cursor_position_alone") |
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif |
\ endif

Not sure, but I think this one would be okay regardless of the context.
Maybe you have something simpler, like:

au BufReadPost * normal g`"

Or maybe you have some other command that tries to reread the buffer,
even when in Insert mode. (Which then triggers the bad behavior of the
other command.)

--
Best,
Ben

Eddine

unread,
Oct 26, 2011, 5:12:36 PM10/26/11
to vim...@googlegroups.com
Hey Ben
 
 
I think you give me the right hint I have this autocmd in my _vimrc
 
 
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
 
so is it replacable by the autocmd you gave
 
 au BufReadPost * normal g`"
 
 
  
2011/10/26 Benjamin R. Haskell <v...@benizi.com>
 
 
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
 
 

Benjamin R. Haskell

unread,
Oct 26, 2011, 6:13:47 PM10/26/11
to vim...@googlegroups.com
On Wed, 26 Oct 2011, Eddine wrote:

> Hey Ben
>  
>  
> I think you give me the right hint I have this autocmd in my _vimrc
>  
>  
> autocmd BufReadPost *
> \ if line("'\"") > 0 && line("'\"") <= line("$") |
> \ exe "normal g`\"" |
> \ endif
>
>  
> so is it replacable by the autocmd you gave
>  
>  au BufReadPost * normal g`"
>

No, that's not what I meant at all. I thought something simpler might
be making things worse, though in hindsight, I think it'd be about the
same.

I think the problem is something else that causes that autocmd to be
fired at the wrong time. I mentioned the 'autoread' option (which I
don't think will ever fire when you're in insert mode, but comes into
play with files that change on disk while you're editing). It seems
more likely to me that some other autocmd (possibly on the CursorMovedI
event?) might do something that would trigger a reload of changed files.

What plugins have you installed, or what other autocmds do you have?

--
Best,
Ben

Eddine

unread,
Oct 27, 2011, 1:27:18 AM10/27/11
to vim...@googlegroups.com
Ben
 
this is my _vimrc file:
 
set nocompatible
cd c:\dev
set nobackup
set nowb
set noswapfile
set wildmenu
set novb
set wrap
set number
set backspace=indent,eol,start
set autoindent
set smarttab
set history=500
set ruler
set showcmd
set incsearch
set showbreak=\
set cursorline
set cmdheight=3
set so=10
set visualbell
set digraph
set equalalways
set splitbelow
set hidden
set ignorecase
set noeb
set autowrite
set ek noet nosol
set fo=cqrt
set shm=at
set ww=<,>,h,l
set comments=b:#,:%,n:>
set novb
"set list listchars=tab:»·,trail:·
set su=.bak,~,.o,.h,.info,.swp,.obj,.dvi,.pdf,.log,.aux,.exe,.tar,.gz,.zip,.bz2,.exe
set expandtab
set sb
set lines=40
 
"Mappings
map Q gq
map <F5> :ls<CR>
map <F6> :bd<CR>
map <F7> :bp<CR>
map <F8> :bn<CR>
map j gj
map <DOWN> gj
map k gk
map <UP> gk
map <F9> :make <CR>
map :bd :bd!
vnoremap p :let current_reg = @"gvs=current_reg
" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
endif " has("autocmd")
" MS Windows Behavior shortcuts
source $VIMRUNTIME\mswin.vim
behave mswin
" Auto Commands
" Placing Vim into the directory where the file is.
autocmd VimEnter,BufNewFile,BufRead,BufEnter * if strlen (@%) !=0 | cd %:p:h | endif
au VimEnter,BufNewFile,BufRead,BufEnter *.sql set ft=plsql
" vim -b : edit binary using xxd-format!
augroup Binary
au!
au BufReadPre *.bin *.bqy let &bin=1
au BufReadPost *.bin *.bqy if &bin | %!xxd
au BufReadPost *.bin *.bqy set ft=xxd | endif
au BufWritePre *.bin *.bqy if &bin | %!xxd -r
au BufWritePre *.bin *.bqy endif
au BufWritePost *.bin *.bqy if &bin | %!xxd
au BufWritePost *.bin *.bqy set nomod | endif
augroup END
 
 
 
 What I have noticed is that it occurs on that java log file that are being written while edited, and on where I often do string search.
Maybe I can force the readonly mode for those file as a workarround.
 
Thanks a lot for your help.
 
Eddine.
 
  
2011/10/27 Benjamin R. Haskell <v...@benizi.com>
 
 
--
Best,
Ben
 

Benjamin R. Haskell

unread,
Oct 27, 2011, 5:23:31 AM10/27/11
to vim...@googlegroups.com
On Thu, 27 Oct 2011, Eddine wrote:

> Ben
>
> this is my _vimrc file:
>

> [...]


>
> " When editing a file, always jump to the last known cursor position.
> " Don't do it when the position is invalid or when inside an event handler
> " (happens when dropping a file on gvim).
> autocmd BufReadPost *
> \ if line("'\"") > 0 && line("'\"") <= line("$") |
> \ exe "normal g`\"" |
> \ endif

Should be non-problematic.

> " vim -b : edit binary using xxd-format!
> augroup Binary
> au!
> au BufReadPre *.bin *.bqy let &bin=1
> au BufReadPost *.bin *.bqy if &bin | %!xxd
> au BufReadPost *.bin *.bqy set ft=xxd | endif
> au BufWritePre *.bin *.bqy if &bin | %!xxd -r
> au BufWritePre *.bin *.bqy endif
> au BufWritePost *.bin *.bqy if &bin | %!xxd
> au BufWritePost *.bin *.bqy set nomod | endif
> augroup END

All of those lines are wrong:

1. Should have commas between the patterns:

au {event} {pat},{pat} {command}

E.g.:

au BufReadPre *.bin *.bqy let &bin=1

Must be:

au BufReadPre *.bin,*.bqy let &bin=1

(better, make it local):

au BufReadPre *.bin,*.bqy let &l:bin=1

(shorter, but equivalently: [setl = setlocal])

au BufReadPre *.bin,*.bqy setl bin


2. You can't split the command between two autocmds the way you have.

au BufWritePre *.bin *.bqy if &bin | %!xxd -r
au BufWritePre *.bin *.bqy endif

Needs to be (along with correction #1):

au BufWritePre *.bin,*.bqy if &bin | %!xxd -r | endif


> What I have noticed is that it occurs on that java log file that are
> being written while edited, and on where I often do string search.

Do your *.bin files change while you're editing them? Maybe you're
hitting those malformed autocmds. Unfortunately, otherwise, nothing
jumps out at me. You're under Windows? What version? What version of
Vim?

--
Best,
Ben

Eddine

unread,
Oct 27, 2011, 5:32:13 PM10/27/11
to vim...@googlegroups.com
Indeed the strange behavior I face with Vim is when I edit *.log files ;
I can remove the autocmd for *.bin, *.bqy it will have no effect unfortunatly on the bug.
 
I'm under Windows XP, Vim 7.2
 
Can try to upgrade Vim 7.3 to see if it still occurs.
 
Once again thank you for your help.
 
Eddine.

2011/10/27 Benjamin R. Haskell <v...@benizi.com>
On Thu, 27 Oct 2011, Eddine wrote:



--
Best,
Ben

Reply all
Reply to author
Forward
0 new messages