Is it possible in Vim to lock the top line of a window so that the first line in buffer is always seen on top of the window?
I have a file, say, dump of a database table. On the first line there are names of columns, other lines contain data. I want to be able to scroll contents up and down, and always see column names.
N.B. Lines can be lengthy, so I use nowrap and want column names and contents to scroll right and left simultaneously. That's why :1split doesn't suit -- unless there's a way to scroll two windows at the same time.
Thanks.
Thanks guys! Let me summarize the actual commands that did the job for me:
:1spl # create an extra window with only 1 line
:set scrollbind # synchronize upper window
ctr+W , arrowDown # switch to other window
:set scrollbind # synchronize lower window
:set sbo=hor # synchronize horizontally
Split your window, decrease the top window height, set the top most line to be the first one and get back to the working window.
:split
:resize 1
gg
Ctrl-w w
You can scroll two windows at the same time, so I think you can do what you want by splitting your window, and locking the scrolling behaviour. See :scrollbind and this tip for more details. Note that you have to lock each window in order that they move in sync.
Related
I want to launch two files from the command line and I want the window to be split horizontally. This can be achieved with the following command:
vim -o index.html index.1
Which gives me the following output split evenly
What I want, instead, is for the top window to be substantially larger, like so
How do I achieve this? Also, currently, the top window is selected, which is what I want. However, if it wasn't selected, or I wanted the bottom window selected, how would I go about achieving this?
You can open the two files with
vim index.html +10sp index.1
After vim has read index.html it executes the ex command 10sp. That means that the current window is split into two with the new window being 10 rows high. After that index.1 is read by vim and loaded into the currently active window.
If you already set splitbelow in your .vimrc index.1 is loaded into the bottom window that is active at the same time.
For example if you want the top window to be active and splitbelow is set you can append the corresponding ex command to the line
vim index.html +10sp index.1 +"wincmd k"
One possible solution would be to make the top window 80% of the available size:
vim +'execute "resize" (&lines / 10) * 8' -o file1 file2
See :help :resize and :help 'lines' for more information.
Small clarification: & is used in front of options to retrieve its value. Thus &lines holds the value of what you could set yourself, e.g.:set lines=100. In this case, &lines gets set by Vim on-the-fly even when you resize the window that holds Vim.
I have the problem with splitting windows. If I open a file with :split the size of the new window includes only one line. I don't know why.
Is there a way to resize the window in vim as I need it?
jump into the window you want to resize (ctrl-w ctrl-w OR ctrl-w direction-arrow), then hit ctrl-w followed by [number followed by] + (or - if you want to decrease the size)
the number is optional and indicates how many "units" you want to enlarge the window by, defaults to 1 if not specified
Or just hit ^W= to make all windows roughly same-size.
Also, :se mouse+=a should enable you to just drag the dividers with the mouse, even on terminal emulators across a GNU screen session.
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?
I want to stop Vim from scrolling (if that's the right word) when I split a window horizontally.
Let's say I edit a 10 line file in Vim. I have a single window onto the buffer and the window is 40 lines high. There's more than enough room for two windows, one on top of the other, with both showing the whole buffer. And let's say scrolloff is set to 4.
When I split the window horizontally, the original window is scrolled so that exactly scrolloff lines are shown between the top of the window and the line the cursor is on -- if there were more than scrolloff lines between the top of the window and the cursor line -- even though there is no need to scroll.
Put another way, if the cursor is on line 1, 2, 3, 4 or 5 when I split the window, the original window doesn't "move" (good). But if the cursor is on line 6, the window scrolls so that line 2 becomes the top-most visible line...ensuring scrolloff lines (4) are visible above the cursor line (annoying). Similarly if the cursor is on line 7 when I split the window, the original window scrolls to that line 3 becomes the top-most visible line. And so on.
Is there a way to configure Vim never to scroll the original window when I split it horizontally?
I imagine it's possible to map <C-W>s to a function which does what I want, but I'd prefer to solve this by configuration if possible.
I've found a solution, borrowing the answer from here.
In my .vimrc I have:
nnoremap <C-W>s Hmx`` \|:split<CR>`xzt``
And now when I split the window horizontally with <C-W>s, the original window doesn't scroll at all.
As an alternative to Andy Stewart's solution here's what I use in my .vimrc:
(3) (5)
++ +--+
|| | |
nnoremap _ Hmx``<C-w>szz<C-w><C-p>`x``<C-w><C-p>
| || | | | | |
+-+-++----+ +--------+ +--------+
(1) (2) (4) (6)
(1) Go top left save mark it to x and go back to where you were.
(2) Create a new split. Cursor will move to this new split window.
(3) Use zz to center the cursorline.
(4) Go back to the window you have created the split.
(5) Go back to x mark and then go back to where you were (to simulate step (1))
(6) Go back to the split you created.
One addition I made is to add zz onto the newly opened split to make the cursor on the new window easier to catch. My brain can automatically focus onto the center row of the new split.
A recently available option is the stable-windows plugin. I've tried it and it's working well.
I can get the bottom of the window to display partial lines by setting display=lastline
Is there a similar option that would allow partial lines to be displayed at the top of a window?
Without this functionality, my vim still scrolls (down) by more than 1 screen line when the topmost file line being displayed is wrapped into multiple screen lines.
For example, in the following scenario, when I press C-E, my vim will scroll down by 3 screen lines. Is there a way to make it scroll by only 1 screen line such that only the first two words in line 1 are hidden, but the following 3 words are still displayed? This will be very useful for editing long paragraphs of text.
Note: I'm referring to the scrolling of the entire screen, not the movement of cursor.
------------------
1 abcdefg abcefg
abcasdfsa sdfsf
sdfc
2 adfadf
3 adfadf
4 adfadf
------------------
I don't think it is possible to do exactly what you want.
Here's the description I get when I type :help CTRL-E
CTRL-E
CTRL-E Scroll windows [count] lines downwards in the buffer.
Mnemonic: Extra lines.
Note that while it says it is scrolling the window, it also mentions that it is scrolling lines in the buffer. You really are scrolling only one (wrapped) line at a time.
I don't think there's another way around this.
I can get the bottom of the window to display partial lines by setting display=lastline
I think display=lastline is a false solution - you still scroll the same amount, you just have more visible.
The real way to solve this is to disable wrapping:
:set nowrap
Edit
Some related threads that show that a "scrolling via screen lines" feature is under consideration, but will take a while to be implemented:
http://vim.1045645.n5.nabble.com/Feature-request-Display-partial-paragraph-at-the-top-of-the-window-td1166809.html (4 years ago)
http://vim.1045645.n5.nabble.com/Scrolling-screen-lines-I-knew-it-s-impossible-td3358342.html (the beginning of this year. Same dev mentioned wanting to implement it: "Ben Schmidt")
For anyone reading this thread:
This thread on the Vi stackexchange offers a slightly hacky (but useable) solution to visual scrolling across wrapped lines.
Now there's a built-in option for this:
'smoothscroll' 'sms' boolean (default off)
local to window
Scrolling works with screen lines. When 'wrap' is set and the first
line in the window wraps part of it may not be visible, as if it is
above the window. "<<<" is displayed at the start of the first line,
highlighted with hl-NonText.
NOTE: only partly implemented, currently works with CTRL-E, CTRL-Y
and scrolling with the mouse.