Automatically increase drop when switching to line number

Is there a way to deploy the code when going to line number? For example, I type :35 , where line 35 is added, then I have to expand this section manually to actually go to this line. I would like to type :35 and then this code is expanded automatically, and my cursor was placed on line 35 without any additional keystrokes.

+6
source share
3 answers

If you use the 35G command instead of :35 , you can achieve this with the following mapping:

 "[count]G Also open fold under cursor when supplying [count] (ie " jumping to a particular line, not the end of the " buffer). Use [count]|gg| if you don't want this. nnoremap <expr> G (v:count ? 'Gzv' : 'G') 

For :35 , that would be hard to achieve. You will need to intercept <CR> through :cmap <expr> , check the entered command with getcmdtype() and getcmdline() , and if this number, manipulate the command, i.e. Add normal! zv normal! zv to her; eg:

 cmap <expr> <CR> getcmdtype() == ':' && getcmdline() =~ '^\d\+$' ? 'normal! zv<CR>' : '<CR>' 
+7
source

zv . From :help zv :

  View cursor line: Open just enough folds to make the line in which the cursor is located not folded. 

Although this command can probably be called automatically in some way, I have not encountered it yet. Using the as-is command has served me well.

+2
source

Define a new team mapping. In this example, I selected \ g z :

 :nmap \gz gg<Bar>zO 
0
source

Source: https://habr.com/ru/post/914910/


All Articles