|
1 | | -# dicasvim.md Intro - Last Change: 2018 mar 23 06:49 |
| 1 | +# dicasvim.md Intro - Last Change: 2018 mar 23 12:45 |
2 | 2 | vim: set ts=4 et: |
3 | 3 |
|
4 | 4 | + http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/#navigation |
@@ -143,6 +143,7 @@ To copy the line 16 to the line bellow just type: |
143 | 143 | :/user-friend/m$ ......... move next "user-friend" to the final line |
144 | 144 | :g/TITLE/ m+1 ............ moves down lines with TITLE |
145 | 145 | :m+ ...................... move current line to line below |
| 146 | + :g/pattern/t<line number> |
146 | 147 |
|
147 | 148 | This is one anti pattern |
148 | 149 |
|
@@ -1670,35 +1671,70 @@ iab fname <c-r>=expand("%:p")<cr> |
1670 | 1671 | :h g@ |
1671 | 1672 |
|
1672 | 1673 | ```vimL |
| 1674 | +autocmd FileType c,cpp,java let b:comment_leader = '\/\/' |
| 1675 | +autocmd FileType arduino let b:comment_leader = '\/\/' |
| 1676 | +autocmd FileType sh,ruby,python let b:comment_leader = '#' |
| 1677 | +autocmd FileType zsh let b:comment_leader = '#' |
| 1678 | +autocmd FileType conf,fstab let b:comment_leader = '#' |
| 1679 | +autocmd FileType matlab,tex let b:comment_leader = '%' |
| 1680 | +autocmd FileType vim let b:comment_leader = '"' |
| 1681 | +
|
1673 | 1682 | function! ToggleComment() |
1674 | | - let l:win_view = winsaveview() |
1675 | | - if getline('.')[0] == "#" |
1676 | | - normal! 0"_x |
1677 | | - else |
1678 | | - normal! I# |
1679 | | - endif |
1680 | | - call winrestview(l:win_view) |
| 1683 | + if exists('b:comment_leader') |
| 1684 | + let l:pos = col('.') |
| 1685 | + if getline('.') =~ '\v(\s*|\t*)' .b:comment_leader |
| 1686 | + "exec 'normal! _"_2x' |
| 1687 | + execute 'silent s/\v^(\s*|\t*)\zs' .b:comment_leader.'[ ]?//g' |
| 1688 | + let l:pos -= 2 |
| 1689 | + else |
| 1690 | + exec 'normal! I' .b:comment_leader .' ' |
| 1691 | + let l:pos += 2 |
| 1692 | + endif |
| 1693 | + call cursor(line("."), l:pos) |
| 1694 | + else |
| 1695 | + echo 'no comment leader found for filetype' |
| 1696 | + end |
1681 | 1697 | endfunction |
1682 | 1698 | nnoremap <Leader>t :call ToggleComment()<CR> |
1683 | | -vnoremap <Leader>t <C-o>:call ToggleComment()<CR> |
| 1699 | +inoremap <Leader>t <C-o>:call ToggleComment()<CR> |
| 1700 | +xnoremap <Leader>t :'<,'>call ToggleComment()<CR> |
| 1701 | +
|
1684 | 1702 |
|
1685 | | -" Another version |
1686 | | -" Because sometimes comments are not at the beginning of line |
| 1703 | +" another one |
| 1704 | +autocmd FileType c,cpp,java let b:comment_leader = '\/\/' |
| 1705 | +autocmd FileType arduino let b:comment_leader = '\/\/' |
| 1706 | +autocmd FileType sh,ruby,python let b:comment_leader = '#' |
| 1707 | +autocmd FileType conf,fstab let b:comment_leader = '#' |
| 1708 | +autocmd FileType matlab,tex let b:comment_leader = '%' |
| 1709 | +autocmd FileType vim let b:comment_leader = '"' |
1687 | 1710 |
|
1688 | 1711 | function! ToggleComment() |
1689 | | - let l:win_view = winsaveview() |
1690 | | - exec 'normal! _' |
1691 | | - let char = getline('.')[col('.')-1] |
1692 | | - if char == "#" |
1693 | | - normal! _"_x |
| 1712 | +" help with :h \v or pattern-atoms |
| 1713 | + if exists('b:comment_leader') |
| 1714 | + if getline('.') =~ '\v^\s*' .b:comment_leader |
| 1715 | + " uncomment the line |
| 1716 | + execute 'silent s/\v^\s*\zs' .b:comment_leader.'[ ]?//g' |
1694 | 1717 | else |
1695 | | - normal! I# |
| 1718 | + " comment the line |
| 1719 | + execute 'silent s/\v^\s*\zs\ze(\S|\n)/' .b:comment_leader.' /g' |
1696 | 1720 | endif |
1697 | | - call winrestview(l:win_view) |
| 1721 | + else |
| 1722 | + echo 'no comment leader found for filetype' |
| 1723 | + end |
1698 | 1724 | endfunction |
1699 | | -nnoremap <Leader>t :call ToggleComment()<CR> |
1700 | | -inoremap <Leader>t <C-o>:call ToggleComment()<CR> |
| 1725 | +
|
| 1726 | +nnoremap <leader>c :call ToggleComment()<cr> |
1701 | 1727 | ``` |
| 1728 | + |
| 1729 | +```viml |
| 1730 | +nnoremap <expr> gcc getline('.') =~ '\v^(\s+)?#' ? '_"_x' : "gI#\<esc>w" |
| 1731 | +xnoremap <expr> gc ':norm! ' . (getline("'<") =~ '^#' ? '0"_x' : "gI#") . "\<cr>" |
| 1732 | +``` |
| 1733 | + |
| 1734 | +# Set cursor line and column (position) |
| 1735 | + |
| 1736 | + :call cursor(1682,2) |
| 1737 | + |
1702 | 1738 | # Print some lines to pdf |
1703 | 1739 | + http://www.vimweekly.com/ |
1704 | 1740 |
|
@@ -2654,6 +2690,10 @@ Supose you have these lines: |
2654 | 2690 |
|
2655 | 2691 | read more at: `help sub-replace` |
2656 | 2692 |
|
| 2693 | +# get char under cursor |
| 2694 | + |
| 2695 | + :echo matchstr(getline('.'), '\%'.col('.').'c.') |
| 2696 | + |
2657 | 2697 | # Converting numbers to chars |
2658 | 2698 | The range of printable chars spams from 32 to 122 |
2659 | 2699 |
|
@@ -3422,12 +3462,12 @@ OBS: These commands above do exactly the same |
3422 | 3462 | + https://stackoverflow.com/a/49446424/2571881 |
3423 | 3463 |
|
3424 | 3464 | I need to modify the certain charactors between two patterns in each line. |
3425 | | -Eample:: (File content saved as myfile.txt) |
| 3465 | +Eample: (File content saved as myfile.txt) |
3426 | 3466 |
|
3427 | | - abc, def, 1, {jsdfsd kfgdsf lgfgd}, 2, pqr, stu |
3428 | | - abc, def, 1, {jsdfsqwe k fdfsfl}, 2, pqr, stu |
3429 | | - abc, def, 1, {asdasdj kgfdgdf ldsfsdf}, 2, pqr, stu |
3430 | | - abc, def, 1, {jsds kfdsf fdsl}, 2, pqr, stu |
| 3467 | + abc, def, 1, {,jsdfsd,kfgdsf,lgfgd}, 2, pqr, stu |
| 3468 | + abc, def, 1, {,jsdfsqwe,k,fdfsfl}, 2, pqr, stu |
| 3469 | + abc, def, 1, {,asdasdj,kgfdgdf,ldsfsdf}, 2, pqr, stu |
| 3470 | + abc, def, 1, {,jsds,kfdsf,fdsl}, 2, pqr, stu |
3431 | 3471 |
|
3432 | 3472 | Remove commas inside { block |
3433 | 3473 |
|
|
0 commit comments