Vim - top of screen follows cursor - vim

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 ?

Related

How to insert tabs on new line in Vim before a character is typed

If I write an if statement in my C program, press enter three times, then write a comment, the below is my output. Notice the two lines between the condition and the comment are completely empty.
if(my_condition) {
<Tab>// My comment here
My issue is that Vim does not insert any tab character(s) between the beginning of the line and the cursor position until a character is typed. This is very annoying for me, because I like to move my cursor up and down the block of code often. Since there isn't a real tab on the two lines, if I moved up one line my cursor would go to the beginning of the line, instead of staying on the same column. I come from Sublime Text and other editors where this has never been a problem.
Is there a plugin or setting such that I can accomplish the following?
if(my_condition) {
<Tab>
<Tab>
<Tab>// My comment here
All help is appreciated. I've looked into using Visual mode, but have had undesirable side effects of enabling it all the time. Certainly there is a simple way to automatically add the tabs when I make a new line?
This is very annoying for me, because I like to move my cursor up and down the block of code often.
Well, as you might have noticed, switching to vim means that you need to change your own editing behavior. And that might be the toughest, more than learning the new commands, because habits die hard!
I'm not saying that you should stop scrolling around your function in an useless manner, though, but that you should stop moving around with the "cursor" keys in insert mode.
When you're doing movements when in insert mode it has the side effect you're exposing as "inconvenient", but it also has the side effect of breaking the "repeat" command (.). After a cursor movement in insert mode, a . will only repeat characters typed after that movement.
So, what you should consider in your editing behavior, is to avoid empty lines, avoid trailing spaces/tabs and never move around in insert mode. Insert mode is for insertion, and the normal mode is for moving around and doing actions on the text.
There are a lot of move commands you can abuse in normal mode (j/k, <C-e>/<C-y>, {/}, …).
That being said, if you get yourself in a situation where you've fscked the indentation, you might want to keep on editing, not caring about the indent, and once you're back in normal mode issue a =i{ that will indent everything within the block following the syntax file (and your indent settings).

How can I enable a see-through block cursor in vim/my terminal?

While in command mode in vim, I can't see through my cursor.
For example, the gibberish text
nuhsantoheun renders as:
I can solve this by enabling a blinking cursor in my terminal emulator settings, however I'd like to find some sort of cursor that, rather than blinking, simply shows a highlighted or reverse-highlighted letter.
Solved this while writing the question, so figured I might as well leave it up here to help out someone else.
In your terminal editor, simply set your cursor color to be something other than your text color, which produces the desired behavior:

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

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.

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.

Readline's vi-mode in vim ex mode

Let's see if I can explain myself.
I use vi-mode in bash, which is really great since I'm used to Vi.
When I'm inside vim and type : (to go to ex mode), since I'm used to the vi-mode from bash, I feel the slowliness of having to use this mode like the "regular" way of using bash.
Question is: is there a way of using vim's ex-mode like bash's (or readline) vi-mode?
Not sure if I understand what you're trying to do, but it might be something like hitting q: in normal mode?
For users that use Vim or vi bindings almost everywhere, including on their shell command line, it really hurts when you leave that environment. If you're used to the vi bindings hyperdrive, going back to chords for skipping words and other manoeuvres is painful and slow. Operating systems also differ on their default bindings so Mac, for instance, supports option-arrow instead of control-arrow, adding to the pain.
But there is one place where this also happens where it's really upsetting: in Vim itself. When working in Vim and entering command mode using : the default readline editing returns. Chords all over again. How to fix this?
Simple: When in "normal" mode, that is, when navigating around, type q:
Vim will drop you at the bottom of a full Vim full screen editing experience, go for your life
Additionally the command history is available on previous lines in the buffer
You can yank and paste lines and edit the commands as much as you wish
To execute a command in "command" or "ex" mode just hit ENTER on the line you want to execute
Hitting enter on an empty line closes the buffer and does nothing
But this is just another buffer so you can quit it as usual with :q as well
Although ESC leaves the "ex" command line, ESC in the buffer will not leave the buffer, because it's an actual buffer
The q prefix is used to introduce macro recording, so the q: variant is perfectly mnemonic for entering recording of an "ex" command line.
Note that q: to enter the buffer editing mode is very similar to :q ! You may have hit that by accident sometimes ;-) Now you know how to get out of it!
Zigdon had this answer a long time ago, of course, but it's pretty darn sparse, but then again, so is the question. If Zigdon adds this extra detail to his answer I'll be happy to delete this answer so that there can be one good answer.

Resources