Is there a way to sort:
:messages
in vim?
Whenever I type in :messages to debug some commands because it is sorted from oldest to newest and I have several hundred messages I have to press space about 20 times to view the most recent message. I tried :h message but couldn't find a place where it mentions sorting. Is it possible to do this?
I usually send the messages into a buffer when I need to analyse them.
new
put=execute('message')
But when I need to debug my own plugins, I use a framework (that I'm maintaining). The debug messages can be emitted either as messages, or as entries in the quickfix/loclist window, or into a file.
Related
I've been using Vim for years, but only recently did I really start using the quickfix list.
One usability issue that immediately struck me is that when I fix the first issue in the quickfix list, the line number of all the following issues are now off by a certain amount. This issue compounds very quickly if I have several errors. I almost always have to recalculate the list by running my linters again after fixing one or two issues.
Is there any way to make Vim keep the line numbers in the quickfix list up to date? When I add or remove lines above a quickfix list entry, the line number of that entry should be incremented or decremented appropriately.
The quickfix list and the quickfix window are not kept up to date with the content of the buffer(s) because they reflect the output of the underlying command (grep, linter, etc.) that was used (in the past) to generate the list.
If you absolutely want to keep the quickfix list and window up to date with the content of the buffer, you will have to:
write the buffer to disk,
run your linter again to get a new quickfix list.
I don't think it is worth the hassle because the commands you use to jump through the list are "smart" enough to handle added and removed lines just fine:
Why you don't get the expected behavior is what needs investigating, here, not how to get it.
I am working on a vim plugin and as part of that I am testing various things like "auto-groups" and events where I can hook bits and pieces in general. While things are running I am using functions that output various debug messages using the echom command. The problem is once I want to have a look at the output, I need to type :message and then keep hitting a key until the end of the messages appear, so I can see what was the last message.
Is there a workaround for this? Like, is there a plugin that would help me see the messages stream in realtime inside a separate buffer?
Thanks.
(OSX, MacVim)
Instead of using :echom directly, write a little s:Log(message) function. It should switch to your log buffer, then append a:message at the bottom (or the top, if you like). Switch back to the current buffer and :execute "echom" a:message.
If you also want to see regular messages in your log buffer, you could use :redir to capture the messages, then append them to your log buffer on a CursorHold event. This is more complicated, and it would tie up one of your named buffers.
:help :wincmd
:help :put
:help append()
:help :redir
:help CursorHold
For me, :echomsg and :messages is fine most of the time. If you need something more elaborate, have a look at the Decho - Vim script internal debugger plugin. It can capture log messages in a separate window.
For hairy parts, no amount of log output will be enough; you can then launch the built-in interactive debugging; see :help debug-scripts.
Is there any way to change the tab order in Vim minibufexplorer? Or when I opened them once, do they have to stay that way until I will close Vim?
Vim always assign the next sequential number for a new buffer. minibufexplorer shows the buffers in this sequential order. Since you can't reassign new buffer numbers, you have three options:
Ask fholgado to implement this feature (he has a minibufexplorer fork, and added a lot of good stuff);
Find another buffer listing plugin that have different sort mechanisms that you like;
Use tabs instead of buffers, one tab per buffer (understand the caveats of this approach). Using gVim, you can move them as you like, using some shortcuts.
I want to trap all events that modify the vim buffer, so I can record them and send them to a server. I want to trap character-by-character events while in insert mode, and also be notified when p or dd etc. commands are executed---any time the document changes.
In Vim 8 this is much easier. Just listen to these to autocmd events:
TextChanged
TextChangedI
Going through the list of events I have selected the following:
|BufFilePre| before changing the name of the current buffer
|BufFilePost| after changing the name of the current buffer
|FileChangedShell| Vim notices that a file changed since editing started
|FileChangedShellPost| After handling a file changed since editing started
|InsertEnter| starting Insert mode
|InsertChange| when typing <Insert> while in Insert or Replace mode
|InsertLeave| when leaving Insert mode
|QuickFixCmdPre| before a quickfix command is run
|QuickFixCmdPost| after a quickfix command is run
Although I have not tried, I believe that the Insert* events include such commands as delete, paste, change etc. You should also look for the 'Writing' events in |autocmd-events|.
A friend pointed me at the terribly-named netbeans module within vim. This looks like what I want.
Sometimes I hit the wrong keys on my laptop's small keyboard, and odd navigation or editing occurs (sometimes a feature that's new to me).
Although I can undo the editing (u) or navigation (control-o), I don't know what I did wrong, so it's difficult to avoid it in future. It's also frustrating to not know what just happened. So, I would like to be able to see my last few keystrokes.
A bit like :set showcmd, but to show the literal keystrokes, and (ideally) a short history of them.
I've only found commandline and navigation history in help/google.
To clarify: I'm not looking for commandline history, but keystroke history. e.g. did I press ) accidentally and go to the next sentence? Did I press dd and delete a line? I guess it's similar to a keystroke logger.
Commandline history (:history) only shows commands entered at the : prompt.
A bit old, but I've just found this on reddit:
You can start vim with the -w flag to write all keystrokes in a file. See :h -w
vim -w filename
To my knowledge, the closest you can get is the q command, which records your keystrokes into a register of your choice. Obviously, that has to be set up a priori as it's intended for complex repeats, although you could probably hack something to start recording on every file open. There's the matter of memory usage and that annoying "recording" prompt though.
Probably the most straightforward way would be to install keylogging software. I don't have any personal experience with these, but the security implications are probably mild if you get it from a trustworthy source or build it yourself, set it to only log to memory not a disk, only have a buffer the size of a sentence or so, or only log for vim windows.
More recently I came across a logging plugin for Vim and it reminded me of this question:
http://wolever.net/~wolever/wiki/vim-logging
It basically records everything you do for later analysis, it was intended for getting statistics about command usage but should work perfectly for finding what those magic commands you accidentally entered were.
:history will show your command history - that should help you uncover the new features that we all uncover in vim with misplaced keystrokes.
Gundo - Is probably worth a look, whilst perhaps not exactly what you are looking it will help slightly.
It lets you visualise the Vim undo tree, this means you will be able to see the last edits that happened. For example if you accidentally deleted a line or some such this will show up in the tree, however, it doesn't show you the actual keystrokes that were pushed and will not show things such as cursor movements.