Vim, sync screen after selecting line - vim

In Vim we can travel to different lines using ':<line-number>'.
And we can also sync the screen by typing 'zt' in normal mode.
But how do we have the screen get synced automatically every time we go to a specific line?

If by syncing you mean centering the line at the top (what zt does) / middle / bottom, you can achieve an always-on centering of the current line in the middle via:
:set scrolloff=999
For all other, I'd recommend a custom G mapping:
:nnoremap G Gzt
To make this also work with :[N] and all other jump commands, you'd have to define :autocmds, and I would recommend against that.

Related

How to lock vertical scroll view on a line?

While going back and forward on history of undo/redo, I would like to keep vim screen vertically locked (let's say lock on line 100), is that possible? how?
I mean that line should be fixed on screen.
Possible, but requires work. Something like...
Make a mapping that will set (and possibly also reset) the lock. Something like <leader>l to set the b:lock_line variable to the current line. Then use nnoremap to change u, Ctrl-R to execute b:lock_line . "zz" after it does the original binding, if b:lock_line is set.
You can't change the operation of built-in commands like :earlier, :later etc., as Vim does not allow you to redefine them. You can define new commands like :Earlier that would do what you want instead.
No. It is not possible. At anytime, if you want to see the line no. 100, you can type :100 in the command mode or 100G to go to the line.
Once you are in line 100, you can type zz, zt, zb to move the cursor to middle of screen, top of screen, bottom of screen respectively.

vim how to using jk to move page down up without touch to the bottom or top

In ubuntu 17.04, the vim using jk to move page down up without touch to the bottom or top, like following gif screen record:
how to do the same on OSX
In your .vimrc, you can add the following
set so=7 " sets 7 lines up/down of cursor when moving vertically
so stands for "scrolloff". So you can set how many lines you want to buffer. Default is 5 lines up and down. You can learn more at :help 'scrolloff'.

Vim: Only scroll the current line

I would like vim to scroll horizontally like nano does, by scrolling only the current line, not the whole screen.
I tried playing with nowrap and scrolloff settings, without success.
Here are some screenshots (with the cursor at the end of a long line) to explain myself.
Nano:
Vim (wrap):
Vim (nowrap):
Thanks!
No, Vim cannot do this, and I think it would be hard to implement this in a way that isn't inconsistent or confusing to the user. There would need to be an indicator (like with side scrolling) that only the current line is scrolled. Also in Vim, there are several commands (like j / k and i_CTRL-Y / i_CTRL-E) that refer to the same column in above / below lines. A partially scrolled view state would make it difficult to use those.
That said, you can sort-of achieve this with a hack: The foldtext of folded lines does not scroll horizontally. So if you fold each individual line (other than the current one) via a custom 'foldexpr', set the fold text to be the line's text, and automatically close all surrounding folds, you'll get this. However, as you'll lose syntax highlighting and "normal" folding, this is more for demonstration than an actual solution.

Highlight the line number in the middle of screen in Vim?

As it is very convenient to scroll half screen up and down(by using ctrl-d), but it is a little hard to estimate which line will disappear after scroll. It will be great if the middle line number can be highlighted, then I can use it as a marker for half screen scrolling.
These are standard VI commands in Command Mode. You may find them helpful:
z<Enter> - Put current line on top of your window
z. - Put current line in the middle of your window
z- - Put current line on the bottom of your window
See :help z for more information in VIM. There's a lot of stuff on cursor movements there.
That's not possible in Vim, and implementations of highlights while scrolling are notoriously difficult to implement well (leading to the introduction of the built-in 'cursorline' option to address the top use case).
I frankly don't see the need for that highlight, and I think that once you've learned all the various ways of moving (including commands like zt / zz, <C-Y> / <C-E> (which are great for repositioning when you're off a single / few lines only), and plain j / k with the 'relativenumber' option), this becomes a non-issue.

Vim window resizing

I split my windows in Vim horizontally. But after I split, the new window occupies half of the original window size, I want to change this and make sure the new window occupies almost the entire old window.
Basically if I open three files using horizontal split in Vim, I should see three status bars at the bottom of the screen the third file occupying the rest of the screen. The files as I already know can be navigated through Ctrl+W+arrow keys. So if I navigate to second file now, I should see one status bar at the bottom and one status bar at the top.
Kindly let me know how to configure the same. I looked up online all I could find is options to dynamically change the size or resize, but I want static one-time config (for example, in vimrc or bashrc).
If you set the winheight option to 999, the current window occupies as much of the screen as possible, and all other windows occupy only one line (I have seen this called "Rolodex mode"):
set winheight=999
You can type in command mode :res[ize] +N or :res[ize] -N where N is the amount in which your window will grow or shrink respectively.
Go to point 6 (Window resizing) http://vimdoc.sourceforge.net/htmldoc/windows.html but the article has everything on windows management in VIM
Hope this helps!
You might prefer just using vim tabs, which work rather like how you described.
Try this:
vim -p file1 file2 file3
Then use :tabn and :tabp to cycle fwd and back through the tabs.
I also like this mapping in .vimrc to use ctrl-l and ctrl-h to cycle fwd and back respectively:
noremap <C-h> :tabp<CR>
noremap <C-l> :tabn<CR>
Command for split window:
:[N]sp[lit] [++opt] [+cmd]
Where N is height of new window. Default is to use for half the height current window. Same thing for vertcal splitting:
:[N]vsp[lit] [++opt] [+cmd]
N is width for split window.
And so on:
[N]new, [N]vnew
For details read the
:help split
But I can't understand why you do not use buffers?

Resources