Vim, split window have only 1-line-size - 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.

Related

Cannot switch to a file when splitting the view and resizing the files

I'm relatively new to vim and I'm facing the issue on VMware(bionic).
I cannot switch to editor when splitting the view (:vspor :sp).
The cursors is placed in newly opened file, but the first file (from which :sp is called) is like frozen and also cannot be resized (dashed line between is not dragable). I'm using .vimrc. Any help would be appreciated.
Mouse user:
Add set mouse=a in your .vimrc. You will be able to switch focus with mouse click, and resize windows by dragging the dash line. See Focus follow mouse in vim.
Keyboard user:
You can type Ctrl-W two times to switch to the next window. Learn more in http://vimdoc.sourceforge.net/htmldoc/windows.html#window-move-cursor.
The way to resize window is less convenient as using the mouse. Ctrl-W > can increase current window width, and Ctrl-W + can increase current window height. See more in http://vimdoc.sourceforge.net/htmldoc/windows.html#window-resize

in VIM, How to set the initial window size via file browser?

I'm using vim to browse through different folders. (i.e., issue :tabe . command in vim)
However, when I open the file either in split window (pressing 'o') or in vertical split window(pressing 'v'), the newly opened window size is really small. (while meanwhile, vim's file browser's windows stays pretty big which I don't really need).
I know that I can manually change the window size by Ctrl+W with either -/+ or split, or for vertical split, or '=' to make the window sizes equal; but that's too troublesome.
I want to check if there're existing ways to set the default size of the window opened using "o" or "v" to be bigger?
Thanks a lot ;)
The new window should take half of the height or half of the width of the current window which can give you small windows pretty quickly.
The option that defines that proportion can be found in :help netrw:
let g:netrw_winsize = 75
Note that using this method will make any further split even smaller than before:
let g:netrw_winsize = 50 (default)
|-netrw--------------------------------------------|
|-netrw------------------|-file--------------------|
|-netrw------|-file------|-file--------------------|
let g:netrw_winsize = 75
|-netrw--------------------------------------------|
|-netrw------|-file--------------------------------|
|-netrw|-file|-file--------------------------------|
The "problem", here is that netrw splits its own window, not the previous window.
Netrw can be used to open the file under the cursor in the current window, in a split window or in another tab but the way it splits its own window makes it hard to use it the way you want. AFAIK, the most common usage is:
open netrw with :Ex,
navigate,
hit <CR> to open the file under the cursor in the current window,
edit,
re-open netrw in its latest state with :Rex (for Peter Rincker),
GOTO 2
An alternative is to use :Vex to open netrw in a vertical split and use P to open the file in the previous window.
I'm afraid Netrw is not really designed to work like what you seem to want it to work. IMO, netrw is more like an "open…" dialog than the kind of file explorer pane you can see in most editors/IDEs. I'd suggest you either get used to it or try NERDTree which has only a subset of netrw's features but is designed to be more like those file explorer panes.
Actually the split size is not relative to netrw, it's the default size vim sets for newly created splits, so if you want to resize the actual split which is in you case the navigator (netrw) you can use this commend:
:vertical resize 30
There is :Lex now to open a left explorer. You can place let g:netrw_winsize=30 in your vimrc file to keep the explorer small.

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?

Changing the size of the split screen in vimdiff

I only know two commands for dealing with vimdiff:
Ctrl-w Ctrl-w switches windows and Ctrl-w = makes the two windows equal width if they became uneven due to, for example, resizing the terminal.
How can I make the left screen much larger than the right, for instance?
You can use any windowing command in vimdiff, for example CTRL-w < to make the left window one column smaller. This can also be combined with a count, for example CTRL-W 5> to make the right window 5 columns smaller. Consult the help page with :help CTRL-w to get a list of window commands.
Additionally, you can use the mouse to change the size of the windows by clicking the boundary between both windows and dragging it into a direction. You might have to enable mouse support by issuing :set mouse=a first.

Specifying width for :vsplit in vim

Is there any way to specify a width when doing :vsplit?
Also, is there a way to increase or decrease the width on a vertically splitted window? Ctrl-w + and Ctrl-w - seems to be working on only horizontally split windows.
According to :help :vsplit, it takes an optional numeric argument as a prefix, e.g., :80vs. Try it out!
Edit: I guess I forgot to mention. You can control the width with Ctrl-W < and Ctrl-W >
For more info, read the manual at :help windows
Ctrl-W n < works, replace n with the number of steps you want to move.
You can also use for example 80| to set your current split width to 80 columns
If you want to fix the adjusted windows width, be sure the cursor is placed inside it and set the boolean
:set winfixwidth
This prevents from unwanted automatic resize of the such locked window width if some other window command like CTRL-= ("make all windows equal") is applied.
:set nowinfixwidth with the cursor placed inside the appropriate window disables the lock.
:mksession stores the window arrangement as calling vim again from the command line likevim -S Session.vim & restores it.
Hope this helps...
Also:
:vs
:vertical resize 30
and:
:sp
:resize 30
I have an Alt+E binding for a vertical file-explorer pane 60 chars wide:
:vs +Explore<CR>:vertical resize 60<CR>
Admittedly, I didn't know about the simple :60vs or :60sp thing in Luis' answer when I wrote that macro.

Resources