Vim User-Defined Functions

Source: Internet
Author: User
"Toggle Number Display

Map <leader> TN: Call toggle_number () <CR>
Function! Toggle_number ()
If! Exists ("B: togglenum ")
Let B: togglenum = 1
Endif
If B: togglenum = 1
Execute "set Nonu"
Let B: togglenum = 0
Else
Let B: togglenum = 1
Execute "set nu"
Endif
Endfunction
"Auto add tags from project rootau bufreadpost, bufnewfile * Call add_tags ()
Function! Add_tags ()
If expand ("%: P: H ")! = Getcwd ()
Echohl warningmsg | echo "fail to make! This file is not in the current Dir! Press <F7> to redirect to the Dir of this file. "| echohl none
Return
Endif
Let srcdir = expand ("%: P: H ")
Let I = 0
While isdirectory (srcdir)
If I> 3
Break
Endif
If filereadable (srcdir. "/tags ")
Let file = srcdir. "/tags"
"Echo printf (" set tags % s ", file)
If I = 0
Execute "set tags =". File
Else
Execute "set tags + =". File
Endif
Endif
Let newdir = fnamemodify (srcdir, ": P: H ")
"Echo printf (" newdir % s ", newdir)
If newdir! = Srcdir
Let srcdir = newdir
Else
Break
Endif
Let I = I + 1
Endwhile
Endfunction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.