Moving the cursor around in vi produces unexpected characters. How come? - linux

I took a couple screenshots of the problem I'm having. Basically what I'm used to with vi and what I'm expecting, is to be able to move around the document using the arrow keys, and still be able to read the actual content of the document.
Here is a shot of vi editor as I initially open a configuration file.
A shot of vi again, after I have pressed the down, left, and right arrow keys a few times.
If for some reason you cannot view the screenshots, what I see is: as I move the cursor around in vi, the place where my cursor just was gets replaced by numbers, commas, dashes, or curly braces. Sometimes it jumps one character over, but sometimes it jumps several.
Obviously I'm doing something wrong here. And here I thought I knew how to use vi...

I'm not exactly why the problem occured, but I do know what fixed it.
Solution:
As you can tell from the screenshot, I was in an SSH session. I disconnected and re-established a new SSH connection.

Please try runnning vi with different terminal emulation to see if it makes difference. I reckon its terminal related.
Something like:
TERM=linux vi
or
TERM=vt100 vi
Also running 'reset' command might also help without reconnecting. This resets terminal to its defaults.

Related

Vim - top of screen follows cursor

In insert mode, whenever I move the cursor up or down, the top of the display window immediately follows the cursor, not letting me see any lines above. Is there any commands to fix this?
If I understood you well, I don't see any problem there. I mean as you write more, it's part of the usability of Vim, you wont see lines above. On the either hand, if you can see only the line where you are in , there is a problem. It this happen using other kind of editors like VI, Cat, or gedit ?

ZSH history-incremental-search-backward indents cursor

I've just started using ZSH with Cygwin/rxvt today (along with a default install of oh-my-zsh), and I'm noticing the reverse history search has a little quirk which is bothering me quite a bit. The search functionality works fine, but entering the search indents the cursor a bit:
This on it's own isn't really problematic, but if I execute the command, it will remain indented there. In addition, if I cancel out of the search, the cursor remains indented afterward:
I can live with this if I must, but I wonder if anyone knows what could be causing this? Given the number of variables involved (Cygwin, rxvt, zsh, oh-my-zsh, etc.), and how new I am to zsh in general, I'm not sure where to start.
It looks very much like the issue here or here: you added colors to your prompt but forgot to tell zsh that these sequences have no width.

Changing the VIM/GVIM message window behavior

When I type :!ls, for example, and see the result, it shifts up the current window to make space for it.
I've been annoyed by how the whole content moves up and down. I'm wondering if there's a way to fix that in either vim or gvim 7.3 - like in Emacs.
So for example, if I have lines 1~30, and the message area takes up 5 lines, I want my code window to show lines 1~25 instead of 6~30. That's what Emacs does, I think.
Thanks.
As far as I am aware, this is not possible in vim. However, there are ways to get around it. You can use screen or tmux and use that to create a lower window to execute commands in. You can also take a look into conque, which simulates a terminal within vim.

vi randomly echoing key presses

When using vi it sometimes echoes keypresses to the screen. For example, if I press escape, it will show ^[ on the screen. The actual characters don't get written to the file, because if I go to another place in the file and come back, the characters aren't there. Still, it's confusing when this happens, especially if the characters appear where there's text.
I also have gvim installed. It never happens there, but it happens in all the various types of vi that run in a terminal.
Why does this happen, and how can it be fixed?
It's okay when you are working on slow connection.
It also happened to me, when I used vim/vi on remote machine over slow connection. It's because the slow connection extends the internal speed vim responds to your keystrokes. For me, nothing harmful but it's slow, and gives exception to eyes. At least VI is designed in this kind of condition, it can handle slow connection very well.
This doesn't really help you fix the problem, but if it's just noise in the terminal, you could use the :redr[aw]! command to clean up your screen.

How to see the last few keystrokes in vim?

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.

Resources