No edit summary |
(Insert TipProposed template + minor manual clean) |
||
Line 1: | Line 1: | ||
+ | {{TipProposed |
||
+ | |id=0 |
||
+ | |previous=0 |
||
+ | |next=0 |
||
+ | |created=September 9, 2010 |
||
+ | |complexity=basic |
||
+ | |author=jeet |
||
+ | |version=7.0 |
||
+ | |subpage=/201009 |
||
+ | |category1= |
||
+ | |category2= |
||
+ | }} |
||
When trying to "squeeze" code between existing code, the "o" and "O" commands are useful to add a blank line below/above the current one and drop into insert mode. However, sometimes it would be nice to have one (or more) extra lines inserted at the same time, so that, for example, there is an extra line between the line you are currently working on and the code above or below. |
When trying to "squeeze" code between existing code, the "o" and "O" commands are useful to add a blank line below/above the current one and drop into insert mode. However, sometimes it would be nice to have one (or more) extra lines inserted at the same time, so that, for example, there is an extra line between the line you are currently working on and the code above or below. |
||
The following functions and key maps will do this. |
The following functions and key maps will do this. |
||
+ | <pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | function! OpenLinesBelow() |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | + | " '\O' : open multiple lines above and drop into insert mode [count]\O will |
|
− | + | " insert [count] lines above current line, and then drop into insert mode one |
|
− | + | " line above current line (i.e., second line from the bottom of the stack of |
|
− | + | " the newly inserted lines). |
|
− | + | function! OpenLinesAbove() |
|
− | + | let num_lines = v:count1 |
|
− | + | if (num_lines < 2) |
|
− | + | let num_lines = 2 |
|
− | + | endif |
|
− | + | let linesave = line('.') |
|
− | + | let colsave = col('.') |
|
− | + | let new_lines = 1 |
|
− | + | while num_lines > new_lines |
|
− | + | put!='' |
|
− | + | let new_lines = new_lines + 1 |
|
− | + | endwhile |
|
− | + | call cursor(linesave+num_lines-2, colsave) |
|
− | + | endfunction |
|
− | + | nnoremap <Leader>O :<C-u>call OpenLinesAbove()<CR>O<ESC>o |
|
+ | </pre> |
||
− | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | function! OpenLinesAbove() |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | |||
− | [[Special:Contributions/68.95.117.66|68.95.117.66]] 15:06, September 9, 2010 (UTC)jeet |
||
− | |||
− | |||
− | |||
− | ==References== |
||
− | <!-- Put any help links you want here in a list as follows: --> |
||
− | *{{help|toc}} |
||
==Comments== |
==Comments== |
Revision as of 08:22, 20 September 2010
Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).
created September 9, 2010 · complexity basic · author jeet · version 7.0
When trying to "squeeze" code between existing code, the "o" and "O" commands are useful to add a blank line below/above the current one and drop into insert mode. However, sometimes it would be nice to have one (or more) extra lines inserted at the same time, so that, for example, there is an extra line between the line you are currently working on and the code above or below.
The following functions and key maps will do this.
" '\o' : open multiple lines below and drop into insert mode [count]\o will " insert [count] lines below current line, and then drop into insert mode one " line below the current line (i.e., second line from the top of stack of the " newly inserted lines). function! OpenLinesBelow() let num_lines = v:count1 if num_lines < 2 let num_lines = 2 endif let linesave = line('.') let colsave = col('.') let new_lines = 2 while num_lines > new_lines put='' let new_lines = new_lines + 1 endwhile call cursor(linesave, colsave) endfunction nnoremap <Leader>o :<C-u>call OpenLinesBelow()<CR>o<CR> " '\O' : open multiple lines above and drop into insert mode [count]\O will " insert [count] lines above current line, and then drop into insert mode one " line above current line (i.e., second line from the bottom of the stack of " the newly inserted lines). function! OpenLinesAbove() let num_lines = v:count1 if (num_lines < 2) let num_lines = 2 endif let linesave = line('.') let colsave = col('.') let new_lines = 1 while num_lines > new_lines put!='' let new_lines = new_lines + 1 endwhile call cursor(linesave+num_lines-2, colsave) endfunction nnoremap <Leader>O :<C-u>call OpenLinesAbove()<CR>O<ESC>o