How do I get the bottom line in vimscript? - vim

I'm trying to get the line number of the bottom of the current screen. I've tried:
winsaveview()['topline'] + winheight(0) - 1
But this doesn't take into account folds.
How do I get the bottom line of the current screen in vimscript that takes into account folds?

You can use line() with w$ to get last line visible in current window
:echo line('w$')
For more help see :h line()

Related

How to jump to a line inside current view without scroll window

If we jump, using YouCompleteMe, in vim to a line that is already inside current view, it will put cursor to that line, and make that line be in center by scroll window.
for example, current window shows line 100 to line 200, and cursor is on line 160. Now we jump to line 110, which can be seen in current window view. After jumping, line 110 is in the center and window shows line 60 to 160.
I expect that any jump(including come back by ) won't scroll window if target line is inside current view, just put cursor to target place. How can I do this?
PS. I'm actually using YCM for jumping.
After you go to the target line, try pressing zz.
I think this is what you are looking for. There are zt, zb, do :h zt to check out what those commands do.
You can create something else, e.g. I have:
nnoremap zl zt4<c-y>¬

Move to the beginning of New Line - VIM

while in insert mode in vim how do i move to a new line correctly indented.
In many editors this action would be CTRL+ENTER
There is a similar stackoverflow question here however this answer takes you back to the start of the current line SO start of current line
So assuming this is my code, my cursor is just at the T in POST and i want to go to the start of the next line or next line with correct indentation if its a function(using snippets for function so now great concern).
#app.route('/add', method=['POST | '])
expected result
#app.route('/add', method=['POST'])
|
I would use <esc>o. Assuming you have filetype plugin indent on in your vimrc o will automatically go to the correct indent level.
Search for indentation and map to some keys, so you cannot search for every time.
/^^I
^I is tab

How to change the preview result position of vim's taglist plugin (hitting 'p')

While using a preview [p] or jump-to [enter] command in the taglist window, the appropriate line is by default in the file-edit window. Because I mostly need to see more of what's right after the selected tag (functions), I'd love to change the line at which the tag is displayed from the center to let's say 1 third of the current page size (number of lines) or even to an explicit line (let's say 10th line from the top).
Is there a command/settings that would adjust the displayed position of a selected tag? (I couldn't find one in the manual).
Thanks
You're presumably looking for the zt (redraw with current line at the top of the window), and zz (redraw at center) commands, or something in between (which can be achieved with <C-Y> / <C-E> after those commands).
How to incorporate that into the plugin is best discussed with the plugin's author. Since you've found no configuration setting for this, you likely have to directly modify the source code. Write your suggestion to the author; you may get a configuration / hook for this in the next plugin version, or tips how to do this, or maybe the author's opinion of why this is a bad idea.
You could try to tweak the scrolloff setting. I don't know the tagbar plugin but I imagine setting :set so=5 should provide you some context when jumping around.
Well, regarding the Ingo Karkat's comment, I managed to locate the appropriate line in the taglist plugin (begginning at line 3357, version 4.6):
" Jump to the tag
if a:tagpat != ''
" Add the current cursor position to the jump list, so that user can
" jump back using the ' and ` marks.
mark '
silent call search(a:tagpat, 'w')
" Bring the line to the middle of the window
normal! z.
" If the line is inside a fold, open the fold
if foldclosed('.') != -1
.foldopen
endif
endif
Here the part normal! z. needs to be changed appropriately to something that would change a position of the selected line appropriately. As I'm no vim-plugin guru, I changed it in the most dumb way possible as
" Bring the line to the middle of the window
normal! zt
normal! 10k
silent call search(a:tagpat, 'w')
which just walks 10times up and than searches the right position again. Hope this might help someone who 'struggles' with the same issue at the moment until a better solution is suggested or Yegappan Lakshmanan, the author, includes this (or rather something nicer) to his plugin (in case he decides to do that of course :) )

auto-scrollable pagination with vim using vertical split

I want to achieve the following: I want to split a vim session into two (or more) vertical windows (with the :vsplit command). Then, I want to have each window contents vertically offsetted so that the line after the last visible one of the first window becomes the first line of the second window. Then, when I use the arrows to scroll around, the vertical windows are scrollbound so that text flows from the second window into the first. How can I achieve this?
There are plugins for that: MultiPage
You can also use a oneliner described in this post by Chip Campbell:
:nmap <silent> <Leader>ef :vsplit<bar>wincmd l<bar>exe "norm! Ljz<c-v><cr>"<cr>:set scb<cr>:wincmd h<cr> :set scb<cr>
This will bind <Leader>ef to open a vsplit and make the splits continuous.
First, split your window normally and position it according to your needs (last line in one, first line in the other).
Now, run :set scrollbind in the first window. Jump to the second one and do the same, you can also use :set scb for short.
That's it!
And be sure to read :h scroll-binding.

how to put the current line under edit on the top of the screen in vim

It is very inconvenient when the line I'm editing is at the bottom of the screen . Because you can't see any following lines and that prevent you from take any "eye refernce" to the content of the file following the current line .
so my question is there a vim command can refresh the display and put the current line under edit to on the top of the screen ? thanks in advance.
See this reference.
z<return>
:h scroll-cursor
Jonathan's answer is valid, however I prefer zt (as "top") that keeps the cursor where it was. In the same idea, there is zb (as "bottom") and zz (not as "middle", but that puts the current line at the center of the window).
There is also an option to make vim always show context around the current line:
:set scrolloff=5
(or, :se so=5) will show +/−5 lines around your current line. From vim's help about 'scrolloff':
Minimal number of screen lines to keep above and below the cursor. This will make some context visible around where you are working. If you set it to a very large value (999) the cursor line will always be in the middle of the window (except at the start or end of the file or when long lines wrap).

Resources