Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Jedi

  • Loading branch information...
commit 344308380a3e908f1befe08bd5d968037cda2e62 1 parent 624c2df
@robertmeta authored
View
7 .vimrc
@@ -32,7 +32,7 @@
" }}}
" Newish {{{
set history=9999 " big old history
- set timeoutlen=400 " super low delay (works for me)
+ set timeoutlen=300 " super low delay (works for me)
set formatoptions+=n " Recognize numbered lists
set formatlistpat=^\\s*\\(\\d\\\|[-*]\\)\\+[\\]:.)}\\t\ ]\\s* "and bullets, too
set viminfo+=! " Store upper-case registers in viminfo
@@ -111,7 +111,7 @@
" +-- full path to file in the buffer
" }}}
" Text Formatting/Layout {{{
- set completeopt= " don't use a pop up menu for completions
+ set completeopt=menuone " don't use a pop up menu for completions
set expandtab " no real tabs please!
set formatoptions=rq " Automatically insert comment leader on return, and let gq format comments
set ignorecase " case insensitive by default
@@ -157,6 +157,8 @@
let NERDChristmasTree = 1
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 0
+
+ let g:jedi#use_tabs_not_buffers = 1
" }}}
" Mappings {{{
" hit f11 to paste
@@ -240,5 +242,4 @@ endif
" Odds n Ends {{{
hi Folded ctermbg=black guibg=black
set ttymouse=xterm2 " makes it work in everything
- match ErrorMsg '\%>120v.\+'
" }}}
View
34 after/syntax/python.vim
@@ -0,0 +1,34 @@
+if g:jedi#show_function_definition == 1 && has('conceal')
+ " conceal is normal for vim >= 7.3
+
+ let e = g:jedi#function_definition_escape
+ let l1 = e.'jedi=[^'.e.']*'.e.'[^'.e.']*'.e.'jedi'.e
+ let l2 = e.'jedi=\?[^'.e.']*'.e
+ exe 'syn match jediIgnore "'.l2.'" contained conceal'
+ setlocal conceallevel=2
+ syn match jediFatSymbol "*" contained conceal
+ syn match jediFat "\*[^*]\+\*" contained contains=jediFatSymbol
+ syn match jediSpace "\v[ ]+( )@=" contained
+ exe 'syn match jediFunction "'.l1.'" keepend extend contains=jediIgnore,jediFat,jediSpace'
+
+ hi def link jediIgnore Ignore
+ hi def link jediFatSymbol Ignore
+ hi def link jediSpace Normal
+ hi jediFat term=bold,underline cterm=bold,underline gui=bold,underline ctermbg=0 guibg=#555555
+ hi jediFunction term=NONE cterm=NONE ctermfg=6 guifg=Black gui=NONE ctermbg=0 guibg=Grey
+
+ " override defaults (add jediFunction to contains)
+ syn match pythonComment "#.*$" contains=pythonTodo,@Spell,jediFunction
+ syn region pythonString
+ \ start=+[uU]\=\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
+ \ contains=pythonEscape,@Spell,jediFunction
+ syn region pythonString
+ \ start=+[uU]\=\z('''\|"""\)+ end="\z1" keepend
+ \ contains=pythonEscape,pythonSpaceError,pythonDoctest,@Spell,jediFunction
+ syn region pythonRawString
+ \ start=+[uU]\=[rR]\z(['"]\)+ end="\z1" skip="\\\\\|\\\z1"
+ \ contains=@Spell,jediFunction
+ syn region pythonRawString
+ \ start=+[uU]\=[rR]\z('''\|"""\)+ end="\z1" keepend
+ \ contains=pythonSpaceError,pythonDoctest,@Spell,jediFunction
+endif
View
167 autoload/jedi.vim
@@ -0,0 +1,167 @@
+" ------------------------------------------------------------------------
+" functions that call python code
+" ------------------------------------------------------------------------
+function! jedi#goto()
+ python jedi_vim.goto()
+endfunction
+
+
+function! jedi#get_definition()
+ python jedi_vim.goto(is_definition=True)
+endfunction
+
+
+function! jedi#related_names()
+ python jedi_vim.goto(is_related_name=True)
+endfunction
+
+
+function! jedi#rename(...)
+ python jedi_vim.rename()
+endfunction
+
+
+function! jedi#complete(findstart, base)
+ python jedi_vim.complete()
+endfunction
+
+
+function! jedi#show_func_def()
+ python jedi_vim.show_func_def()
+endfunction
+
+
+" ------------------------------------------------------------------------
+" show_pydoc
+" ------------------------------------------------------------------------
+function! jedi#show_pydoc()
+python << PYTHONEOF
+if 1:
+ script = jedi_vim.get_script()
+ try:
+ definitions = script.get_definition()
+ except jedi_vim.jedi.NotFoundError:
+ definitions = []
+ except Exception:
+ # print to stdout, will be in :messages
+ definitions = []
+ print("Exception, this shouldn't happen.")
+ print(traceback.format_exc())
+
+ if not definitions:
+ vim.command('return')
+ else:
+ docs = ['Docstring for %s\n%s\n%s' % (d.desc_with_module, '='*40, d.doc) if d.doc
+ else '|No Docstring for %s|' % d for d in definitions]
+ text = ('\n' + '-' * 79 + '\n').join(docs)
+ vim.command('let l:doc = %s' % repr(jedi_vim.PythonToVimStr(text)))
+ vim.command('let l:doc_lines = %s' % len(text.split('\n')))
+PYTHONEOF
+ if bufnr("__doc__") > 0
+ " If the __doc__ buffer is open in the current window, jump to it
+ silent execute "sbuffer ".bufnr("__doc__")
+ else
+ split '__doc__'
+ endif
+
+ setlocal modifiable
+ setlocal noswapfile
+ setlocal buftype=nofile
+ silent normal! ggdG
+ silent $put=l:doc
+ silent normal! 1Gdd
+ setlocal nomodifiable
+ setlocal nomodified
+ setlocal filetype=rst
+
+ if l:doc_lines > 30 " max lines for plugin
+ let l:doc_lines = 30
+ endif
+ execute "resize ".l:doc_lines
+
+ " quit comands
+ nnoremap <buffer> q ZQ
+ nnoremap <buffer> K ZQ
+
+ " highlight python code within rst
+ unlet! b:current_syntax
+ syn include @rstPythonScript syntax/python.vim
+ " 4 spaces
+ syn region rstPythonRegion start=/^\v {4}/ end=/\v^( {4}|\n)@!/ contains=@rstPythonScript
+ " >>> python code -> (doctests)
+ syn region rstPythonRegion matchgroup=pythonDoctest start=/^>>>\s*/ end=/\n/ contains=@rstPythonScript
+ let b:current_syntax = "rst"
+endfunction
+
+
+" ------------------------------------------------------------------------
+" helper functions
+" ------------------------------------------------------------------------
+function! jedi#new_buffer(path)
+ if g:jedi#use_tabs_not_buffers
+ python jedi_vim.tabnew(vim.eval('a:path'))
+ else
+ if !&hidden && &modified
+ w
+ endif
+ execute 'edit '.a:path
+ endif
+endfunction
+
+function! s:add_goto_window()
+ set lazyredraw
+ cclose
+ execute 'belowright copen 3'
+ set nolazyredraw
+ if g:jedi#use_tabs_not_buffers == 1
+ map <buffer> <CR> :call jedi#goto_window_on_enter()<CR>
+ endif
+ au WinLeave <buffer> q " automatically leave, if an option is chosen
+ redraw!
+endfunction
+
+
+function! jedi#goto_window_on_enter()
+ let l:list = getqflist()
+ let l:data = l:list[line('.') - 1]
+ if l:data.bufnr
+ " close goto_window buffer
+ normal ZQ
+ python jedi_vim.tabnew(vim.eval("bufname(l:data.bufnr)"))
+ call cursor(l:data.lnum, l:data.col)
+ else
+ echohl WarningMsg | echo "Builtin module cannot be opened." | echohl None
+ endif
+endfunction
+
+
+function! jedi#syn_stack()
+ if !exists("*synstack")
+ return []
+ endif
+ return map(synstack(line('.'), col('.') - 1), 'synIDattr(v:val, "name")')
+endfunc
+
+
+function! jedi#do_popup_on_dot()
+ let highlight_groups = jedi#syn_stack()
+ for a in highlight_groups
+ if a == 'pythonDoctest'
+ return 1
+ endif
+ endfor
+
+ for a in highlight_groups
+ for b in ['pythonString', 'pythonComment', 'pythonNumber']
+ if a == b
+ return 0
+ endif
+ endfor
+ endfor
+ return 1
+endfunc
+
+function! jedi#configure_function_definition()
+ autocmd InsertLeave <buffer> python jedi_vim.clear_func_def()
+ autocmd CursorMovedI <buffer> call jedi#show_func_def()
+endfunction
View
121 doc/NERD_commenter.txt
@@ -83,40 +83,40 @@ See |filetype-plugin-on| for details, but basically, stick this in your vimrc >
The following key mappings are provided by default (there is also a menu
with items corresponding to all the mappings below):
-[count]|<Leader>|cc |NERDComComment|
+[count]<leader>cc |NERDComComment|
Comment out the current line or text selected in visual mode.
-[count]|<Leader>|cn |NERDComNestedComment|
-Same as |<Leader>|cc but forces nesting.
+[count]<leader>cn |NERDComNestedComment|
+Same as <leader>cc but forces nesting.
-[count]|<Leader>|c<space> |NERDComToggleComment|
+[count]<leader>c<space> |NERDComToggleComment|
Toggles the comment state of the selected line(s). If the topmost selected
line is commented, all selected lines are uncommented and vice versa.
-[count]|<Leader>|cm |NERDComMinimalComment|
+[count]<leader>cm |NERDComMinimalComment|
Comments the given lines using only one set of multipart delimiters.
-[count]|<Leader>|ci |NERDComInvertComment|
+[count]<leader>ci |NERDComInvertComment|
Toggles the comment state of the selected line(s) individually.
-[count]|<Leader>|cs |NERDComSexyComment|
+[count]<leader>cs |NERDComSexyComment|
Comments out the selected lines ``sexily''
-[count]|<Leader>|cy |NERDComYankComment|
-Same as |<Leader>|cc except that the commented line(s) are yanked first.
+[count]<leader>cy |NERDComYankComment|
+Same as <leader>cc except that the commented line(s) are yanked first.
-|<Leader>|c$ |NERDComEOLComment|
+<leader>c$ |NERDComEOLComment|
Comments the current line from the cursor to the end of line.
-|<Leader>|cA |NERDComAppendComment|
+<leader>cA |NERDComAppendComment|
Adds comment delimiters to the end of line and goes into insert mode between
them.
@@ -126,30 +126,26 @@ Adds comment delimiters at the current cursor position and inserts between.
Disabled by default.
-|<Leader>|ca |NERDComAltDelim|
+<leader>ca |NERDComAltDelim|
Switches to the alternative set of delimiters.
-[count]|<Leader>|cl
-[count]|<Leader>|cb |NERDComAlignedComment|
+[count]<leader>cl
+[count]<leader>cb |NERDComAlignedComment|
Same as |NERDComComment| except that the delimiters are aligned down the
-left side (|<Leader>|cl) or both sides (|<Leader>|cb).
+left side (<leader>cl) or both sides (<leader>cb).
-[count]|<Leader>|cu |NERDComUncommentLine|
+[count]<leader>cu |NERDComUncommentLine|
Uncomments the selected line(s).
-
-With the optional repeat.vim plugin (vimscript #2136), the mappings can also
-be repeated via |.|
-
------------------------------------------------------------------------------
3.2 Functionality details *NERDComFunctionalityDetails*
------------------------------------------------------------------------------
3.2.1 Comment map *NERDComComment*
-Default mapping: [count]|<Leader>|cc
+Default mapping: [count]<leader>cc
Mapped to: <plug>NERDCommenterComment
Applicable modes: normal visual visual-line visual-block.
@@ -165,11 +161,11 @@ lines were selected in visual-line mode.
------------------------------------------------------------------------------
3.2.2 Nested comment map *NERDComNestedComment*
-Default mapping: [count]|<Leader>|cn
-Mapped to: <plug>NERDCommenterNested
+Default mapping: [count]<leader>cn
+Mapped to: <plug>NERDCommenterNest
Applicable modes: normal visual visual-line visual-block.
-Performs nested commenting. Works the same as |<Leader>|cc except that if a line
+Performs nested commenting. Works the same as <leader>cc except that if a line
is already commented then it will be commented again.
If |'NERDUsePlaceHolders'| is set then the previous comment delimiters will
@@ -186,7 +182,7 @@ Related options:
------------------------------------------------------------------------------
3.2.3 Toggle comment map *NERDComToggleComment*
-Default mapping: [count]|<Leader>|c<space>
+Default mapping: [count]<leader>c<space>
Mapped to: <plug>NERDCommenterToggle
Applicable modes: normal visual-line.
@@ -203,14 +199,14 @@ lines were selected in visual-line mode.
------------------------------------------------------------------------------
3.2.4 Minimal comment map *NERDComMinimalComment*
-Default mapping: [count]|<Leader>|cm
+Default mapping: [count]<leader>cm
Mapped to: <plug>NERDCommenterMinimal
Applicable modes: normal visual-line.
Comments the selected lines using one set of multipart delimiters if possible.
For example: if you are programming in c and you select 5 lines and press
-|<Leader>|cm then a '/*' will be placed at the start of the top line and a '*/'
+<leader>cm then a '/*' will be placed at the start of the top line and a '*/'
will be placed at the end of the last line.
Sets of multipart comment delimiters that are between the top and bottom
@@ -225,7 +221,7 @@ lines were selected in visual-line mode.
------------------------------------------------------------------------------
3.2.5 Invert comment map *NERDComInvertComment*
-Default mapping: |<Leader>|ci
+Default mapping: <leader>ci
Mapped to: <plug>NERDCommenterInvert
Applicable modes: normal visual-line.
@@ -242,7 +238,7 @@ lines were selected in visual-line mode.
------------------------------------------------------------------------------
3.2.6 Sexy comment map *NERDComSexyComment*
-Default mapping: [count]|<Leader>|cs
+Default mapping: [count]<leader>cs
Mapped to: <plug>NERDCommenterSexy
Applicable modes: normal, visual-line.
@@ -262,16 +258,16 @@ Related options:
------------------------------------------------------------------------------
3.2.7 Yank comment map *NERDComYankComment*
-Default mapping: [count]|<Leader>|cy
+Default mapping: [count]<leader>cy
Mapped to: <plug>NERDCommenterYank
Applicable modes: normal visual visual-line visual-block.
-Same as |<Leader>|cc except that it yanks the line(s) that are commented first.
+Same as <leader>cc except that it yanks the line(s) that are commented first.
------------------------------------------------------------------------------
3.2.8 Comment to EOL map *NERDComEOLComment*
-Default mapping: |<Leader>|c$
+Default mapping: <leader>c$
Mapped to: <plug>NERDCommenterToEOL
Applicable modes: normal.
@@ -281,7 +277,7 @@ the line.
------------------------------------------------------------------------------
3.2.9 Append com to line map *NERDComAppendComment*
-Default mapping: |<Leader>|cA
+Default mapping: <leader>cA
Mapped to: <plug>NERDCommenterAppend
Applicable modes: normal.
@@ -292,7 +288,7 @@ to insert mode between the new delimiters.
3.2.10 Insert comment map *NERDComInsertComment*
Default mapping: disabled by default.
-Map it to: <plug>NERDCommenterInsert
+Map it to: <plug>NERDCommenterInInsert
Applicable modes: insert.
Adds comment delimiters at the current cursor position and inserts
@@ -307,12 +303,12 @@ to your vimrc.
------------------------------------------------------------------------------
3.2.11 Use alternate delims map *NERDComAltDelim*
-Default mapping: |<Leader>|ca
+Default mapping: <leader>ca
Mapped to: <plug>NERDCommenterAltDelims
Applicable modes: normal.
Changes to the alternative commenting style if one is available. For example,
-if the user is editing a c++ file using // comments and they hit |<Leader>|ca
+if the user is editing a c++ file using // comments and they hit <leader>ca
then they will be switched over to /**/ comments.
See also |NERDComDefaultDelims|
@@ -320,12 +316,12 @@ See also |NERDComDefaultDelims|
------------------------------------------------------------------------------
3.2.12 Comment aligned maps *NERDComAlignedComment*
-Default mappings: [count]|<Leader>|cl [count]|<Leader>|cb
+Default mappings: [count]<leader>cl [count]<leader>cb
Mapped to: <plug>NERDCommenterAlignLeft
<plug>NERDCommenterAlignBoth
Applicable modes: normal visual-line.
-Same as |<Leader>|cc except that the comment delimiters are aligned on the left
+Same as <leader>cc except that the comment delimiters are aligned on the left
side or both sides respectively. These comments are always nested if the
line(s) are already commented.
@@ -335,7 +331,7 @@ lines were selected in visual-line mode.
------------------------------------------------------------------------------
3.2.13 Uncomment line map *NERDComUncommentLine*
-Default mapping: [count]|<Leader>|cu
+Default mapping: [count]<leader>cu
Mapped to: <plug>NERDCommenterUncomment
Applicable modes: normal visual visual-line visual-block.
@@ -376,14 +372,16 @@ Here the multipart delimiters are /* and */ and the marker is *.
All of the NERD commenter mappings and menu items invoke a single function
which delegates the commenting work to other functions. This function is
public and has the prototype: >
- function! NERDComment(mode, type)
+ function! NERDComment(isVisual, type)
<
The arguments to this function are simple:
- - mode: a character indicating the mode in which the comment is requested:
- 'n' for Normal mode, 'x' for Visual mode
+ - isVisual: if you wish to do any kind of visual comment then set this to
+ 1 and the function will use the '< and '> marks to find the comment
+ boundries. If set to 0 then the function will operate on the current
+ line.
- type: is used to specify what type of commenting operation is to be
performed, and it can be one of the following: "sexy", "invert",
- "minimal", "toggle", "alignLeft", "alignBoth", "comment", "nested",
+ "minimal", "toggle", "alignLeft", "alignBoth", "norm", "nested",
"toEOL", "append", "insert", "uncomment", "yank"
For example, if you typed >
@@ -406,8 +404,6 @@ then the script would do a sexy comment on the last visual selection.
doing visual-block comments.
|'NERDCommentWholeLinesInVMode'| Changes behaviour of visual comments.
|'NERDCreateDefaultMappings'| Turn the default mappings on/off.
-|'NERDCustomDelimiters'| Add or override delimiters for any
- filetypes.
|'NERDDefaultNesting'| Tells the script to use nested comments
by default.
|'NERDMenuMode'| Specifies how the NERD commenter menu
@@ -554,7 +550,7 @@ Note that this option does not affect the behaviour of commenting in
|visual-block| mode.
------------------------------------------------------------------------------
- *'NERDCreateDefaultMappings'*
+ *'NERDCreateDefaultMappings'*
Values: 0 or 1.
Default: 1.
@@ -563,25 +559,6 @@ If set to 0, none of the default mappings will be created.
See also |NERDComMappings|.
------------------------------------------------------------------------------
- *'NERDCustomDelimiters'*
-Values: A map (format specified below).
-Default: {}
-
-Use this option if you have new filetypes you want the script to handle, or if
-you want to override the default delimiters of a filetype.
-
-Example: >
- let g:NERDCustomDelimiters = {
- \ 'ruby': { 'left': '#', 'leftAlt': 'FOO', 'rightAlt': 'BAR' },
- \ 'grondle': { 'left': '{{', 'right': '}}' }
- \ }
-<
-
-Here we override the delimiter settings for ruby and add FOO/BAR as alternative
-delimiters. We also add {{ and }} as delimiters for a new filetype called
-'grondle'.
-
-------------------------------------------------------------------------------
*'NERDRemoveAltComs'*
Values: 0 or 1.
Default: 1.
@@ -591,7 +568,7 @@ this option tells the script whether to look for, and remove, comment
delimiters of the alternative style.
For example, if you are editing a c++ file using // style comments and you go
-|<Leader>|cu on this line: >
+<leader>cu on this line: >
/* This is a c++ comment baby! */
<
It will not be uncommented if the NERDRemoveAltComs is set to 0.
@@ -599,7 +576,7 @@ It will not be uncommented if the NERDRemoveAltComs is set to 0.
------------------------------------------------------------------------------
*'NERDRemoveExtraSpaces'*
Values: 0 or 1.
-Default: 0.
+Default: 1.
By default, the NERD commenter will remove spaces around comment delimiters if
either:
@@ -622,6 +599,8 @@ Otherwise they would become: >
int bar = 10;
int baz = foo + bar
<
+If you want the spaces to be removed only if |'NERDSpaceDelims'| is set then
+set NERDRemoveExtraSpaces to 0.
------------------------------------------------------------------------------
*'NERDLPlace'*
@@ -641,7 +620,7 @@ To set these options use lines like: >
Following the above example, if we have line of c code: >
/* int horse */
<
-and we comment it with |<Leader>|cn it will be changed to: >
+and we comment it with <leader>cn it will be changed to: >
/*FOO int horse BAR*/
<
When we uncomment this line it will go back to what it was.
@@ -654,7 +633,7 @@ Default: 3
This option can take 4 values:
"0": Turns the menu off.
"1": Turns the 'comment' menu on with no menu shortcut.
- "2": Turns the 'comment' menu on with <alt>-c as the shortcut.
+ "2": Turns the 'comment 'menu on with <alt>-c as the shortcut.
"3": Turns the 'Plugin -> comment' menu on with <alt>-c as the shortcut.
------------------------------------------------------------------------------
@@ -706,7 +685,7 @@ Values: 0 or 1.
Default 1.
When this option is set to 1, comments are nested automatically. That is, if
-you hit |<Leader>|cc on a line that is already commented it will be commented
+you hit <leader>cc on a line that is already commented it will be commented
again.
------------------------------------------------------------------------------
@@ -807,7 +786,7 @@ The latest dev versions are on github
runtime for vim > 7.0 unless the script stores an alternate set of
delimiters
- make the script complain if the user doesnt have filetype plugins enabled
- - use |<Leader>| instead of comma to start the default mappings
+ - use <leader> instead of comma to start the default mappings
- fix a couple of bugs with sexy comments - thanks to Tim Smart
- lots of refactoring
View
32 ftplugin/python/jedi.vim
@@ -0,0 +1,32 @@
+
+" ------------------------------------------------------------------------
+" Initialization of jedi-vim
+" ------------------------------------------------------------------------
+
+if g:jedi#auto_initialization
+ setlocal omnifunc=jedi#complete
+ " map ctrl+space for autocompletion
+ inoremap <buffer> <Nul> <C-X><C-O>
+
+ " goto / get_definition / related_names
+ execute "noremap <buffer>".g:jedi#goto_command." :call jedi#goto()<CR>"
+ execute "noremap <buffer>".g:jedi#get_definition_command." :call jedi#get_definition()<CR>"
+ execute "noremap <buffer>".g:jedi#related_names_command." :call jedi#related_names()<CR>"
+ " rename
+ execute "noremap <buffer>".g:jedi#rename_command." :call jedi#rename()<CR>"
+ " pydoc
+ execute "nnoremap <silent> <buffer>".g:jedi#pydoc." :call jedi#show_pydoc()<CR>"
+
+ if g:jedi#show_function_definition == 1 && has('conceal')
+ call jedi#configure_function_definition()
+ endif
+end
+
+if g:jedi#popup_on_dot
+ inoremap <buffer> . .<C-R>=jedi#do_popup_on_dot() ? "\<lt>C-X>\<lt>C-O>" : ""<CR>
+end
+
+if g:jedi#auto_close_doc
+ " close preview if its still open after insert
+ autocmd InsertLeave <buffer> if pumvisible() == 0|pclose|endif
+end
View
327 plugin/NERD_commenter.vim
@@ -3,7 +3,7 @@
" Description: vim global plugin that provides easy code commenting
" Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
" Version: 2.3.0
-" Last Change: Wed Dec 14 08:00 AM 2011 EST
+" Last Change: 08th December, 2010
" License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
@@ -34,7 +34,7 @@ let loaded_nerd_comments = 1
" 1 if the var is set, 0 otherwise
function s:InitVariable(var, value)
if !exists(a:var)
- execute 'let ' . a:var . ' = ' . "'" . a:value . "'"
+ exec 'let ' . a:var . ' = ' . "'" . a:value . "'"
return 1
endif
return 0
@@ -47,7 +47,7 @@ endfunction
let s:spaceStr = ' '
let s:lenSpaceStr = strlen(s:spaceStr)
-" Section: variable initialization {{{2
+" Section: variable init calls {{{2
call s:InitVariable("g:NERDAllowAnyVisualDelims", 1)
call s:InitVariable("g:NERDBlockComIgnoreEmpty", 0)
call s:InitVariable("g:NERDCommentWholeLinesInVMode", 0)
@@ -58,11 +58,13 @@ call s:InitVariable("g:NERDMenuMode", 3)
call s:InitVariable("g:NERDLPlace", "[>")
call s:InitVariable("g:NERDUsePlaceHolders", 1)
call s:InitVariable("g:NERDRemoveAltComs", 1)
-call s:InitVariable("g:NERDRemoveExtraSpaces", 0)
+call s:InitVariable("g:NERDRemoveExtraSpaces", 1)
call s:InitVariable("g:NERDRPlace", "<]")
call s:InitVariable("g:NERDSpaceDelims", 0)
+call s:InitVariable("g:NERDDelimiterRequests", 1)
let s:NERDFileNameEscape="[]#*$%'\" ?`!&();<>\\"
+"vf ;;dA:hcs"'A {j^f(lyi(k$p0f{a A }0f{a 'left':jdd^
let s:delimiterMap = {
\ 'aap': { 'left': '#' },
@@ -79,11 +81,10 @@ let s:delimiterMap = {
\ 'apachestyle': { 'left': '#' },
\ 'asciidoc': { 'left': '//' },
\ 'applescript': { 'left': '--', 'leftAlt': '(*', 'rightAlt': '*)' },
- \ 'armasm': { 'left': ';' },
\ 'asm68k': { 'left': ';' },
\ 'asm': { 'left': ';', 'leftAlt': '#' },
\ 'asn': { 'left': '--' },
- \ 'aspvbs': { 'left': '''', 'leftAlt': '<!--', 'rightAlt': '-->' },
+ \ 'aspvbs': { 'left': '''' },
\ 'asterisk': { 'left': ';' },
\ 'asy': { 'left': '//' },
\ 'atlas': { 'left': 'C', 'right': '$' },
@@ -98,12 +99,10 @@ let s:delimiterMap = {
\ 'bindzone': { 'left': ';' },
\ 'bst': { 'left': '%' },
\ 'btm': { 'left': '::' },
- \ 'cabal': { 'left': '--' },
\ 'caos': { 'left': '*' },
\ 'calibre': { 'left': '//' },
\ 'catalog': { 'left': '--', 'right': '--' },
\ 'c': { 'left': '/*','right': '*/', 'leftAlt': '//' },
- \ 'cf': { 'left': '<!---', 'right': '--->' },
\ 'cfg': { 'left': '#' },
\ 'cg': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'ch': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
@@ -112,7 +111,6 @@ let s:delimiterMap = {
\ 'clipper': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'clojure': { 'left': ';' },
\ 'cmake': { 'left': '#' },
- \ 'coffee': { 'left': '#' },
\ 'conkyrc': { 'left': '#' },
\ 'cpp': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'crontab': { 'left': '#' },
@@ -146,17 +144,15 @@ let s:delimiterMap = {
\ 'eiffel': { 'left': '--' },
\ 'elf': { 'left': "'" },
\ 'elmfilt': { 'left': '#' },
- \ 'erlang': { 'left': '%', 'leftAlt': '%%' },
+ \ 'erlang': { 'left': '%' },
\ 'eruby': { 'left': '<%#', 'right': '%>', 'leftAlt': '<!--', 'rightAlt': '-->' },
\ 'expect': { 'left': '#' },
\ 'exports': { 'left': '#' },
- \ 'fancy': { 'left': '#' },
\ 'factor': { 'left': '! ', 'leftAlt': '!# ' },
\ 'fgl': { 'left': '#' },
\ 'focexec': { 'left': '-*' },
\ 'form': { 'left': '*' },
\ 'foxpro': { 'left': '*' },
- \ 'fsharp': { 'left': '(*', 'right': '*)', 'leftAlt': '//' },
\ 'fstab': { 'left': '#' },
\ 'fvwm': { 'left': '#' },
\ 'fx': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
@@ -176,22 +172,19 @@ let s:delimiterMap = {
\ 'gitconfig': { 'left': ';' },
\ 'gitrebase': { 'left': '#' },
\ 'gnuplot': { 'left': '#' },
- \ 'go': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'groovy': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
- \ 'gsp': { 'left': '<%--', 'right': '--%>', 'leftAlt': '<!--','rightAlt': '-->'},
+ \ 'gsp': { 'left': '<%--', 'right': '--%>' },
\ 'gtkrc': { 'left': '#' },
- \ 'haskell': { 'left': '{-','right': '-}', 'leftAlt': '-- ' },
+ \ 'haskell': { 'left': '{-','right': '-}', 'leftAlt': '--' },
\ 'hb': { 'left': '#' },
\ 'h': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'haml': { 'left': '-#', 'leftAlt': '/' },
- \ 'haxe': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'hercules': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'hog': { 'left': '#' },
\ 'hostsaccess': { 'left': '#' },
\ 'htmlcheetah': { 'left': '##' },
\ 'htmldjango': { 'left': '<!--','right': '-->', 'leftAlt': '{#', 'rightAlt': '#}' },
\ 'htmlos': { 'left': '#', 'right': '/#' },
- \ 'hxml': { 'left': '#' },
\ 'ia64': { 'left': '#' },
\ 'icon': { 'left': '#' },
\ 'idlang': { 'left': ';' },
@@ -201,7 +194,6 @@ let s:delimiterMap = {
\ 'ishd': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'iss': { 'left': ';' },
\ 'ist': { 'left': '%' },
- \ 'jade': { 'left': '//-', 'leftAlt': '//' },
\ 'java': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'javacc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'javascript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
@@ -214,11 +206,9 @@ let s:delimiterMap = {
\ 'kscript': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'lace': { 'left': '--' },
\ 'ldif': { 'left': '#' },
- \ 'less': { 'left': '/*','right': '*/' },
- \ 'lhaskell': { 'left': '>{-','right': '-}', 'leftAlt': '>-- ' },
\ 'lilo': { 'left': '#' },
\ 'lilypond': { 'left': '%' },
- \ 'liquid': { 'left': '{% comment %}', 'right': '{% endcomment %}' },
+ \ 'liquid': { 'left': '{%', 'right': '%}' },
\ 'lisp': { 'left': ';', 'leftAlt': '#|', 'rightAlt': '|#' },
\ 'llvm': { 'left': ';' },
\ 'lotos': { 'left': '(*', 'right': '*)' },
@@ -241,7 +231,6 @@ let s:delimiterMap = {
\ 'matlab': { 'left': '%' },
\ 'mel': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'mib': { 'left': '--' },
- \ 'mirah': {'left': '#'},
\ 'mkd': { 'left': '>' },
\ 'mma': { 'left': '(*', 'right': '*)' },
\ 'model': { 'left': '$', 'right': '$' },
@@ -250,15 +239,12 @@ let s:delimiterMap = {
\ 'modula3': { 'left': '(*', 'right': '*)' },
\ 'monk': { 'left': ';' },
\ 'mush': { 'left': '#' },
- \ 'mustache': { 'left': '{{!', 'right': '}}' },
\ 'named': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'nasm': { 'left': ';' },
\ 'nastran': { 'left': '$' },
\ 'natural': { 'left': '/*' },
\ 'ncf': { 'left': ';' },
\ 'newlisp': { 'left': ';' },
- \ 'nginx': { 'left': '#' },
- \ 'nimrod': { 'left': '#' },
\ 'nroff': { 'left': '\"' },
\ 'nsis': { 'left': '#' },
\ 'ntp': { 'left': '#' },
@@ -269,7 +255,6 @@ let s:delimiterMap = {
\ 'occam': { 'left': '--' },
\ 'omlet': { 'left': '(*', 'right': '*)' },
\ 'omnimark': { 'left': ';' },
- \ 'ooc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'openroad': { 'left': '//' },
\ 'opl': { 'left': "REM" },
\ 'ora': { 'left': '#' },
@@ -279,7 +264,6 @@ let s:delimiterMap = {
\ 'pcap': { 'left': '#' },
\ 'pccts': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'pdf': { 'left': '%' },
- \ 'perl': { 'left': '#' },
\ 'pfmain': { 'left': '//' },
\ 'php': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'pic': { 'left': ';' },
@@ -299,7 +283,6 @@ let s:delimiterMap = {
\ 'ps1': { 'left': '#' },
\ 'psf': { 'left': '#' },
\ 'ptcap': { 'left': '#' },
- \ 'puppet': { 'left': '#' },
\ 'python': { 'left': '#' },
\ 'radiance': { 'left': '#' },
\ 'ratpoison': { 'left': '#' },
@@ -312,27 +295,22 @@ let s:delimiterMap = {
\ 'rgb': { 'left': '!' },
\ 'rib': { 'left': '#' },
\ 'robots': { 'left': '#' },
- \ 'ruby': { 'left': '#' },
\ 'sa': { 'left': '--' },
\ 'samba': { 'left': ';', 'leftAlt': '#' },
\ 'sass': { 'left': '//', 'leftAlt': '/*' },
\ 'sather': { 'left': '--' },
\ 'scala': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
- \ 'scheme': { 'left': ';', 'leftAlt': '#|', 'rightAlt': '|#' },
\ 'scilab': { 'left': '//' },
\ 'scsh': { 'left': ';' },
- \ 'scss': { 'left': '/*', 'right': '*/', 'leftAlt': '//' },
\ 'sed': { 'left': '#' },
\ 'sgmldecl': { 'left': '--', 'right': '--' },
\ 'sgmllnx': { 'left': '<!--', 'right': '-->' },
- \ 'sh': { 'left': '#' },
\ 'sicad': { 'left': '*' },
\ 'simula': { 'left': '%', 'leftAlt': '--' },
\ 'sinda': { 'left': '$' },
\ 'skill': { 'left': ';' },
\ 'slang': { 'left': '%' },
\ 'slice': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
- \ 'slim': { 'left': '/', 'leftAlt': '/!' },
\ 'slrnrc': { 'left': '%' },
\ 'sm': { 'left': '#' },
\ 'smarty': { 'left': '{*', 'right': '*}' },
@@ -354,7 +332,6 @@ let s:delimiterMap = {
\ 'squid': { 'left': '#' },
\ 'st': { 'left': '"' },
\ 'stp': { 'left': '--' },
- \ 'supercollider': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'systemverilog': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'tads': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'tags': { 'left': ';' },
@@ -372,7 +349,6 @@ let s:delimiterMap = {
\ 'tsscl': { 'left': '#' },
\ 'tssgm': { 'left': "comment = '", 'right': "'" },
\ 'txt2tags': { 'left': '%' },
- \ 'twig': { 'left': '{#', 'right': '#}' },
\ 'uc': { 'left': '//', 'leftAlt': '/*', 'rightAlt': '*/' },
\ 'uil': { 'left': '!' },
\ 'vb': { 'left': "'" },
@@ -400,16 +376,12 @@ let s:delimiterMap = {
\ 'z8a': { 'left': ';' }
\ }
-if exists("g:NERDCustomDelimiters")
- call extend(s:delimiterMap, g:NERDCustomDelimiters)
-endif
-
" Section: Comment mapping functions, autocommands and commands {{{1
" ============================================================================
" Section: Comment enabler autocommands {{{2
" ============================================================================
-augroup NERDCommenter
+augroup commentEnablers
"if the user enters a buffer or reads a buffer then we gotta set up
"the comment delimiters for that new filetype
@@ -431,24 +403,10 @@ augroup END
" set for this buffer.
"
function s:SetUpForNewFiletype(filetype, forceReset)
- let ft = a:filetype
-
- "for compound filetypes, if we dont know how to handle the full filetype
- "then break it down and use the first part that we know how to handle
- if ft =~ '\.' && !has_key(s:delimiterMap, ft)
- let filetypes = split(a:filetype, '\.')
- for i in filetypes
- if has_key(s:delimiterMap, i)
- let ft = i
- break
- endif
- endfor
- endif
-
let b:NERDSexyComMarker = ''
- if has_key(s:delimiterMap, ft)
- let b:NERDCommenterDelims = s:delimiterMap[ft]
+ if has_key(s:delimiterMap, a:filetype)
+ let b:NERDCommenterDelims = s:delimiterMap[a:filetype]
for i in ['left', 'leftAlt', 'right', 'rightAlt']
if !has_key(b:NERDCommenterDelims, i)
let b:NERDCommenterDelims[i] = ''
@@ -1029,17 +987,16 @@ function s:InvertComment(firstLine, lastLine)
endwhile
endfunction
-" Function: NERDComment(mode, type) function {{{2
+" Function: NERDComment(isVisual, type) function {{{2
" This function is a Wrapper for the main commenting functions
"
" Args:
-" -mode: a character indicating the mode in which the comment is requested:
-" 'n' for Normal mode, 'x' for Visual mode
-" -type: the type of commenting requested. Can be 'Sexy', 'Invert',
-" 'Minimal', 'Toggle', 'AlignLeft', 'AlignBoth', 'Comment',
-" 'Nested', 'ToEOL', 'Append', 'Insert', 'Uncomment', 'Yank'
-function! NERDComment(mode, type) range
- let isVisual = a:mode =~ '[vsx]'
+" -isVisual: a flag indicating whether the comment is requested in visual
+" mode or not
+" -type: the type of commenting requested. Can be 'sexy', 'invert',
+" 'minimal', 'toggle', 'alignLeft', 'alignBoth', 'norm',
+" 'nested', 'toEOL', 'append', 'insert', 'uncomment', 'yank'
+function! NERDComment(isVisual, type) range
" we want case sensitivity when commenting
let oldIgnoreCase = &ignorecase
set noignorecase
@@ -1048,7 +1005,7 @@ function! NERDComment(mode, type) range
call s:NerdEcho("filetype plugins should be enabled. See :help NERDComInstallation and :help :filetype-plugin-on", 0)
endif
- if isVisual
+ if a:isVisual
let firstLine = line("'<")
let lastLine = line("'>")
let firstCol = col("'<")
@@ -1058,32 +1015,32 @@ function! NERDComment(mode, type) range
let lastLine = a:lastline
endif
- let countWasGiven = (!isVisual && firstLine != lastLine)
+ let countWasGiven = (a:isVisual == 0 && firstLine != lastLine)
- let forceNested = (a:type ==? 'Nested' || g:NERDDefaultNesting)
+ let forceNested = (a:type == 'nested' || g:NERDDefaultNesting)
- if a:type ==? 'Comment' || a:type ==? 'Nested'
- if isVisual && visualmode() == "\<C-V>"
+ if a:type == 'norm' || a:type == 'nested'
+ if a:isVisual && visualmode() == ""
call s:CommentBlock(firstLine, lastLine, firstCol, lastCol, forceNested)
- elseif isVisual && visualmode() == "v" && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims()))
+ elseif a:isVisual && visualmode() == "v" && (g:NERDCommentWholeLinesInVMode==0 || (g:NERDCommentWholeLinesInVMode==2 && s:HasMultipartDelims()))
call s:CommentRegion(firstLine, firstCol, lastLine, lastCol, forceNested)
else
call s:CommentLines(forceNested, "none", firstLine, lastLine)
endif
- elseif a:type ==? 'AlignLeft' || a:type ==? 'AlignBoth'
+ elseif a:type == 'alignLeft' || a:type == 'alignBoth'
let align = "none"
- if a:type ==? "AlignLeft"
+ if a:type == "alignLeft"
let align = "left"
- elseif a:type ==? "AlignBoth"
+ elseif a:type == "alignBoth"
let align = "both"
endif
call s:CommentLines(forceNested, align, firstLine, lastLine)
- elseif a:type ==? 'Invert'
+ elseif a:type == 'invert'
call s:InvertComment(firstLine, lastLine)
- elseif a:type ==? 'Sexy'
+ elseif a:type == 'sexy'
try
call s:CommentLinesSexy(firstLine, lastLine)
catch /NERDCommenter.Delimiters/
@@ -1092,7 +1049,7 @@ function! NERDComment(mode, type) range
call s:NerdEcho("Sexy comment aborted. Nested sexy cannot be nested", 0)
endtry
- elseif a:type ==? 'Toggle'
+ elseif a:type == 'toggle'
let theLine = getline(firstLine)
if s:IsInSexyComment(firstLine) || s:IsCommentedFromStartOfLine(s:Left(), theLine) || s:IsCommentedFromStartOfLine(s:Left({'alt': 1}), theLine)
@@ -1101,7 +1058,7 @@ function! NERDComment(mode, type) range
call s:CommentLinesToggle(forceNested, firstLine, lastLine)
endif
- elseif a:type ==? 'Minimal'
+ elseif a:type == 'minimal'
try
call s:CommentLinesMinimal(firstLine, lastLine)
catch /NERDCommenter.Delimiters/
@@ -1110,39 +1067,32 @@ function! NERDComment(mode, type) range
call s:NerdEcho("Place holders are required but disabled.", 0)
endtry
- elseif a:type ==? 'ToEOL'
+ elseif a:type == 'toEOL'
call s:SaveScreenState()
call s:CommentBlock(firstLine, firstLine, col("."), col("$")-1, 1)
call s:RestoreScreenState()
- elseif a:type ==? 'Append'
+ elseif a:type == 'append'
call s:AppendCommentToLine()
- elseif a:type ==? 'Insert'
+ elseif a:type == 'insert'
call s:PlaceDelimitersAndInsBetween()
- elseif a:type ==? 'Uncomment'
+ elseif a:type == 'uncomment'
call s:UncommentLines(firstLine, lastLine)
- elseif a:type ==? 'Yank'
- if isVisual
+ elseif a:type == 'yank'
+ if a:isVisual
normal! gvy
elseif countWasGiven
execute firstLine .','. lastLine .'yank'
else
normal! yy
endif
- execute firstLine .','. lastLine .'call NERDComment("'. a:mode .'", "Comment")'
+ execute firstLine .','. lastLine .'call NERDComment('. a:isVisual .', "norm")'
endif
let &ignorecase = oldIgnoreCase
-
- if isVisual
- let nlines = lastLine - firstLine
- silent! call repeat#set("V" . nlines . "jo" . "\<Plug>NERDCommenter". a:type)
- else
- silent! call repeat#set("\<Plug>NERDCommenter". a:type)
- endif
endfunction
" Function: s:PlaceDelimitersAndInsBetween() function {{{2
@@ -1418,12 +1368,6 @@ endfunction
function s:UncommentLineNormal(line)
let line = a:line
- "get the positions of all delim types on the line
- let indxLeft = s:FindDelimiterIndex(s:Left(), line)
- let indxLeftAlt = s:FindDelimiterIndex(s:Left({'alt': 1}), line)
- let indxRight = s:FindDelimiterIndex(s:Right(), line)
- let indxRightAlt = s:FindDelimiterIndex(s:Right({'alt': 1}), line)
-
"get the comment status on the line so we know how it is commented
let lineCommentStatus = s:IsCommentedOuttermost(s:Left(), s:Right(), s:Left({'alt': 1}), s:Right({'alt': 1}), line)
@@ -1438,23 +1382,34 @@ function s:UncommentLineNormal(line)
"it is not properly commented with any delims so we check if it has
"any random left or right delims on it and remove the outtermost ones
else
+ "get the positions of all delim types on the line
+ let indxLeft = s:FindDelimiterIndex(s:Left(), line)
+ let indxLeftAlt = s:FindDelimiterIndex(s:Left({'alt': 1}), line)
+ let indxRight = s:FindDelimiterIndex(s:Right(), line)
+ let indxRightAlt = s:FindDelimiterIndex(s:Right({'alt': 1}), line)
+
"remove the outter most left comment delim
if indxLeft != -1 && (indxLeft < indxLeftAlt || indxLeftAlt == -1)
let line = s:RemoveDelimiters(s:Left(), '', line)
- elseif indxLeftAlt != -1 && g:NERDRemoveAltComs
+ elseif indxLeftAlt != -1
let line = s:RemoveDelimiters(s:Left({'alt': 1}), '', line)
endif
"remove the outter most right comment delim
if indxRight != -1 && (indxRight < indxRightAlt || indxRightAlt == -1)
let line = s:RemoveDelimiters('', s:Right(), line)
- elseif indxRightAlt != -1 && g:NERDRemoveAltComs
+ elseif indxRightAlt != -1
let line = s:RemoveDelimiters('', s:Right({'alt': 1}), line)
endif
endif
+ let indxLeft = s:FindDelimiterIndex(s:Left(), line)
+ let indxLeftAlt = s:FindDelimiterIndex(s:Left({'alt': 1}), line)
let indxLeftPlace = s:FindDelimiterIndex(g:NERDLPlace, line)
+
+ let indxRightPlace = s:FindDelimiterIndex(g:NERDRPlace, line)
+ let indxRightAlt = s:FindDelimiterIndex(s:Right({'alt': 1}), line)
let indxRightPlace = s:FindDelimiterIndex(g:NERDRPlace, line)
let right = s:Right()
@@ -2708,60 +2663,128 @@ function s:UntabbedCol(line, col)
let lineTabsToSpaces = substitute(lineTruncated, '\t', s:TabSpace(), 'g')
return strlen(lineTabsToSpaces)
endfunction
-" Section: Comment mapping and menu item setup {{{1
+" Section: Comment mapping setup {{{1
" ===========================================================================
-" Create menu items for the specified modes. If a:combo is not empty, then
-" also define mappings and show a:combo in the menu items.
-function! s:CreateMaps(modes, target, desc, combo)
- " Build up a map command like
- " 'noremap <silent> <plug>NERDCommenterComment :call NERDComment("n", "Comment")'
- let plug = '<plug>NERDCommenter' . a:target
- let plug_start = 'noremap <silent> ' . plug . ' :call NERDComment("'
- let plug_end = '", "' . a:target . '")<cr>'
- " Build up a menu command like
- " 'menu <silent> comment.Comment<Tab>\\cc <plug>NERDCommenterComment'
- let menuRoot = get(['', 'comment', '&comment', '&Plugin.&comment'],
- \ g:NERDMenuMode, '')
- let menu_command = 'menu <silent> ' . menuRoot . '.' . escape(a:desc, ' ')
- if strlen(a:combo)
- let leader = exists('g:mapleader') ? g:mapleader : '\'
- let menu_command .= '<Tab>' . escape(leader, '\') . a:combo
- endif
- let menu_command .= ' ' . (strlen(a:combo) ? plug : a:target)
- " Execute the commands built above for each requested mode.
- for mode in (a:modes == '') ? [''] : split(a:modes, '\zs')
- if strlen(a:combo)
- execute mode . plug_start . mode . plug_end
- if g:NERDCreateDefaultMappings && !hasmapto(plug, mode)
- execute mode . 'map <leader>' . a:combo . ' ' . plug
- endif
- endif
- " Check if the user wants the menu to be displayed.
- if g:NERDMenuMode != 0
- execute mode . menu_command
- endif
- endfor
-endfunction
-call s:CreateMaps('nx', 'Comment', 'Comment', 'cc')
-call s:CreateMaps('nx', 'Toggle', 'Toggle', 'c<space>')
-call s:CreateMaps('nx', 'Minimal', 'Minimal', 'cm')
-call s:CreateMaps('nx', 'Nested', 'Nested', 'cn')
-call s:CreateMaps('n', 'ToEOL', 'To EOL', 'c$')
-call s:CreateMaps('nx', 'Invert', 'Invert', 'ci')
-call s:CreateMaps('nx', 'Sexy', 'Sexy', 'cs')
-call s:CreateMaps('nx', 'Yank', 'Yank then comment', 'cy')
-call s:CreateMaps('n', 'Append', 'Append', 'cA')
-call s:CreateMaps('', ':', '-Sep-', '')
-call s:CreateMaps('nx', 'AlignLeft', 'Left aligned', 'cl')
-call s:CreateMaps('nx', 'AlignBoth', 'Left and right aligned', 'cb')
-call s:CreateMaps('', ':', '-Sep2-', '')
-call s:CreateMaps('nx', 'Uncomment', 'Uncomment', 'cu')
-call s:CreateMaps('n', 'AltDelims', 'Switch Delimiters', 'ca')
-call s:CreateMaps('i', 'Insert', 'Insert Comment Here', '')
-call s:CreateMaps('', ':', '-Sep3-', '')
-call s:CreateMaps('', ':help NERDCommenterContents<CR>', 'Help', '')
-
-" switch to/from alternative delimiters (does not use wrapper function)
+" switch to/from alternative delimiters
nnoremap <plug>NERDCommenterAltDelims :call <SID>SwitchToAlternativeDelimiters(1)<cr>
+
+" comment out lines
+nnoremap <silent> <plug>NERDCommenterComment :call NERDComment(0, "norm")<cr>
+vnoremap <silent> <plug>NERDCommenterComment <ESC>:call NERDComment(1, "norm")<cr>
+
+" toggle comments
+nnoremap <silent> <plug>NERDCommenterToggle :call NERDComment(0, "toggle")<cr>
+vnoremap <silent> <plug>NERDCommenterToggle <ESC>:call NERDComment(1, "toggle")<cr>
+
+" minimal comments
+nnoremap <silent> <plug>NERDCommenterMinimal :call NERDComment(0, "minimal")<cr>
+vnoremap <silent> <plug>NERDCommenterMinimal <ESC>:call NERDComment(1, "minimal")<cr>
+
+" sexy comments
+nnoremap <silent> <plug>NERDCommenterSexy :call NERDComment(0, "sexy")<CR>
+vnoremap <silent> <plug>NERDCommenterSexy <ESC>:call NERDComment(1, "sexy")<CR>
+
+" invert comments
+nnoremap <silent> <plug>NERDCommenterInvert :call NERDComment(0, "invert")<CR>
+vnoremap <silent> <plug>NERDCommenterInvert <ESC>:call NERDComment(1, "invert")<CR>
+
+" yank then comment
+nmap <silent> <plug>NERDCommenterYank :call NERDComment(0, "yank")<CR>
+vmap <silent> <plug>NERDCommenterYank <ESC>:call NERDComment(1, "yank")<CR>
+
+" left aligned comments
+nnoremap <silent> <plug>NERDCommenterAlignLeft :call NERDComment(0, "alignLeft")<cr>
+vnoremap <silent> <plug>NERDCommenterAlignLeft <ESC>:call NERDComment(1, "alignLeft")<cr>
+
+" left and right aligned comments
+nnoremap <silent> <plug>NERDCommenterAlignBoth :call NERDComment(0, "alignBoth")<cr>
+vnoremap <silent> <plug>NERDCommenterAlignBoth <ESC>:call NERDComment(1, "alignBoth")<cr>
+
+" nested comments
+nnoremap <silent> <plug>NERDCommenterNest :call NERDComment(0, "nested")<cr>
+vnoremap <silent> <plug>NERDCommenterNest <ESC>:call NERDComment(1, "nested")<cr>
+
+" uncomment
+nnoremap <silent> <plug>NERDCommenterUncomment :call NERDComment(0, "uncomment")<cr>
+vnoremap <silent> <plug>NERDCommenterUncomment :call NERDComment(1, "uncomment")<cr>
+
+" comment till the end of the line
+nnoremap <silent> <plug>NERDCommenterToEOL :call NERDComment(0, "toEOL")<cr>
+
+" append comments
+nmap <silent> <plug>NERDCommenterAppend :call NERDComment(0, "append")<cr>
+
+" insert comments
+inoremap <silent> <plug>NERDCommenterInInsert <SPACE><BS><ESC>:call NERDComment(0, "insert")<CR>
+
+
+function! s:CreateMaps(target, combo)
+ if !hasmapto(a:target, 'n')
+ exec 'nmap ' . a:combo . ' ' . a:target
+ endif
+
+ if !hasmapto(a:target, 'v')
+ exec 'vmap ' . a:combo . ' ' . a:target
+ endif
+endfunction
+
+if g:NERDCreateDefaultMappings
+ call s:CreateMaps('<plug>NERDCommenterComment', '<leader>cc')
+ call s:CreateMaps('<plug>NERDCommenterToggle', '<leader>c<space>')
+ call s:CreateMaps('<plug>NERDCommenterMinimal', '<leader>cm')
+ call s:CreateMaps('<plug>NERDCommenterSexy', '<leader>cs')
+ call s:CreateMaps('<plug>NERDCommenterInvert', '<leader>ci')
+ call s:CreateMaps('<plug>NERDCommenterYank', '<leader>cy')
+ call s:CreateMaps('<plug>NERDCommenterAlignLeft', '<leader>cl')
+ call s:CreateMaps('<plug>NERDCommenterAlignBoth', '<leader>cb')
+ call s:CreateMaps('<plug>NERDCommenterNest', '<leader>cn')
+ call s:CreateMaps('<plug>NERDCommenterUncomment', '<leader>cu')
+ call s:CreateMaps('<plug>NERDCommenterToEOL', '<leader>c$')
+ call s:CreateMaps('<plug>NERDCommenterAppend', '<leader>cA')
+
+ if !hasmapto('<plug>NERDCommenterAltDelims', 'n')
+ nmap <leader>ca <plug>NERDCommenterAltDelims
+ endif
+endif
+
+
+
+" Section: Menu item setup {{{1
+" ===========================================================================
+"check if the user wants the menu to be displayed
+if g:NERDMenuMode != 0
+
+ let menuRoot = ""
+ if g:NERDMenuMode == 1
+ let menuRoot = 'comment'
+ elseif g:NERDMenuMode == 2
+ let menuRoot = '&comment'
+ elseif g:NERDMenuMode == 3
+ let menuRoot = '&Plugin.&comment'
+ endif
+
+ function! s:CreateMenuItems(target, desc, root)
+ exec 'nmenu <silent> ' . a:root . '.' . a:desc . ' ' . a:target
+ exec 'vmenu <silent> ' . a:root . '.' . a:desc . ' ' . a:target
+ endfunction
+ call s:CreateMenuItems("<plug>NERDCommenterComment", 'Comment', menuRoot)
+ call s:CreateMenuItems("<plug>NERDCommenterToggle", 'Toggle', menuRoot)
+ call s:CreateMenuItems('<plug>NERDCommenterMinimal', 'Minimal', menuRoot)
+ call s:CreateMenuItems('<plug>NERDCommenterNest', 'Nested', menuRoot)
+ exec 'nmenu <silent> '. menuRoot .'.To\ EOL <plug>NERDCommenterToEOL'
+ call s:CreateMenuItems('<plug>NERDCommenterInvert', 'Invert', menuRoot)
+ call s:CreateMenuItems('<plug>NERDCommenterSexy', 'Sexy', menuRoot)
+ call s:CreateMenuItems('<plug>NERDCommenterYank', 'Yank\ then\ comment', menuRoot)
+ exec 'nmenu <silent> '. menuRoot .'.Append <plug>NERDCommenterAppend'
+ exec 'menu <silent> '. menuRoot .'.-Sep- :'
+ call s:CreateMenuItems('<plug>NERDCommenterAlignLeft', 'Left\ aligned', menuRoot)
+ call s:CreateMenuItems('<plug>NERDCommenterAlignBoth', 'Left\ and\ right\ aligned', menuRoot)
+ exec 'menu <silent> '. menuRoot .'.-Sep2- :'
+ call s:CreateMenuItems('<plug>NERDCommenterUncomment', 'Uncomment', menuRoot)
+ exec 'nmenu <silent> '. menuRoot .'.Switch\ Delimiters <plug>NERDCommenterAltDelims'
+ exec 'imenu <silent> '. menuRoot .'.Insert\ Comment\ Here <plug>NERDCommenterInInsert'
+ exec 'menu <silent> '. menuRoot .'.-Sep3- :'
+ exec 'menu <silent>'. menuRoot .'.Help :help NERDCommenterContents<CR>'
+endif
" vim: set foldmethod=marker :
View
74 plugin/jedi.vim
@@ -0,0 +1,74 @@
+"py_fuzzycomplete.vim - Omni Completion for python in vim
+" Maintainer: David Halter <davidhalter88@gmail.com>
+" Version: 0.1
+"
+" This part of the software is just the vim interface. The main source code
+" lies in the python files around it.
+
+if !has('python')
+ echomsg "Error: Required vim compiled with +python"
+ finish
+endif
+
+" load plugin only once
+if exists("g:loaded_jedi") || &cp
+ finish
+endif
+let g:loaded_jedi = 1
+
+" ------------------------------------------------------------------------
+" defaults for jedi-vim
+" ------------------------------------------------------------------------
+let s:settings = {
+ \ 'use_tabs_not_buffers': 1,
+ \ 'auto_initialization': 1,
+ \ 'goto_command': "'<leader>g'",
+ \ 'get_definition_command': "'<leader>d'",
+ \ 'related_names_command': "'<leader>n'",
+ \ 'rename_command': "'<leader>r'",
+ \ 'popup_on_dot': 1,
+ \ 'pydoc': "'K'",
+ \ 'show_function_definition': 1,
+ \ 'function_definition_escape': "'≡'",
+ \ 'auto_close_doc': 1
+\ }
+
+for [key, val] in items(s:settings)
+ if !exists('g:jedi#'.key)
+ exe 'let g:jedi#'.key.' = '.val
+ endif
+endfor
+
+
+set switchbuf=useopen " needed for pydoc
+
+if g:jedi#auto_initialization
+ " this is only here because in some cases the VIM library adds their
+ " autocompletion as a default, which may cause problems, depending on the
+ " order of invocation.
+ autocmd FileType python setlocal omnifunc=jedi#complete
+endif
+
+
+
+python << PYTHONEOF
+""" here we initialize the jedi stuff """
+import vim
+
+# update the system path, to include the jedi path
+import sys
+import os
+from os.path import dirname, abspath, join
+sys.path.insert(0, join(dirname(dirname(abspath(vim.eval('expand("<sfile>")')))), 'jedi'))
+
+# to display errors correctly
+import traceback
+
+# update the sys path to include the jedi_vim script
+sys.path.append(dirname(abspath(vim.eval('expand("<sfile>")'))))
+import jedi_vim
+sys.path.pop()
+
+PYTHONEOF
+
+" vim: set et ts=4:
View
291 plugin/jedi_vim.py
@@ -0,0 +1,291 @@
+"""
+The Python parts of the Jedi library for VIM. It is mostly about communicating
+with VIM.
+"""
+
+import traceback # for exception output
+import re
+import os
+
+import vim
+import jedi
+import jedi.keywords
+
+temp_rename = None # used for jedi#rename
+
+
+class PythonToVimStr(str):
+ """ Vim has a different string implementation of single quotes """
+ __slots__ = []
+
+ def __repr__(self):
+ return '"%s"' % self.replace('\\', '\\\\').replace('"', r'\"')
+
+
+def echo_highlight(msg):
+ vim.command('echohl WarningMsg | echo "%s" | echohl None' % msg)
+
+
+def get_script(source=None, column=None):
+ jedi.settings.additional_dynamic_modules = [b.name for b in vim.buffers
+ if b.name is not None and b.name.endswith('.py')]
+ if source is None:
+ source = '\n'.join(vim.current.buffer)
+ row = vim.current.window.cursor[0]
+ if column is None:
+ column = vim.current.window.cursor[1]
+ buf_path = vim.current.buffer.name
+ return jedi.Script(source, row, column, buf_path)
+
+
+def complete():
+ row, column = vim.current.window.cursor
+ clear_func_def()
+ if vim.eval('a:findstart') == '1':
+ count = 0
+ for char in reversed(vim.current.line[:column]):
+ if not re.match('[\w\d]', char):
+ break
+ count += 1
+ vim.command('return %i' % (column - count))
+ else:
+ base = vim.eval('a:base')
+ source = ''
+ for i, line in enumerate(vim.current.buffer):
+ # enter this path again, otherwise source would be incomplete
+ if i == row - 1:
+ source += line[:column] + base + line[column:]
+ else:
+ source += line
+ source += '\n'
+ # here again hacks, because jedi has a different interface than vim
+ column += len(base)
+ try:
+ script = get_script(source=source, column=column)
+ completions = script.complete()
+ call_def = script.get_in_function_call()
+
+ out = []
+ for c in completions:
+ d = dict(word=c.word[:len(base)] + c.complete,
+ abbr=c.word,
+ # stuff directly behind the completion
+ menu=PythonToVimStr(c.description),
+ info=PythonToVimStr(c.doc), # docstr
+ icase=1, # case insensitive
+ dup=1 # allow duplicates (maybe later remove this)
+ )
+ out.append(d)
+
+ out.sort(key=lambda x: x['word'].lower())
+
+ strout = str(out)
+ except Exception:
+ # print to stdout, will be in :messages
+ print(traceback.format_exc())
+ strout = ''
+ completions = []
+ call_def = None
+
+ #print 'end', strout
+ show_func_def(call_def, len(completions))
+ vim.command('return ' + strout)
+
+
+def goto(is_definition=False, is_related_name=False, no_output=False):
+ definitions = []
+ script = get_script()
+ try:
+ if is_related_name:
+ definitions = script.related_names()
+ elif is_definition:
+ definitions = script.get_definition()
+ else:
+ definitions = script.goto()
+ except jedi.NotFoundError:
+ echo_highlight(
+ "Cannot follow nothing. Put your cursor on a valid name.")
+ except Exception:
+ # print to stdout, will be in :messages
+ echo_highlight("Some different eror, this shouldn't happen.")
+ print(traceback.format_exc())
+ else:
+ if no_output:
+ return definitions
+ if not definitions:
+ echo_highlight("Couldn't find any definitions for this.")
+ elif len(definitions) == 1 and not is_related_name:
+ # just add some mark to add the current position to the jumplist.
+ # this is ugly, because it overrides the mark for '`', so if anyone
+ # has a better idea, let me know.
+ vim.command('normal! m`')
+
+ d = list(definitions)[0]
+ if d.in_builtin_module():
+ if isinstance(d.definition, jedi.keywords.Keyword):
+ echo_highlight(
+ "Cannot get the definition of Python keywords.")
+ else:
+ echo_highlight("Builtin modules cannot be displayed.")
+ else:
+ if d.module_path != vim.current.buffer.name:
+ vim.eval('jedi#new_buffer(%s)' % repr(d.module_path))
+ vim.current.window.cursor = d.line_nr, d.column
+ vim.command('normal! zt') # cursor at top of screen
+ else:
+ # multiple solutions
+ lst = []
+ for d in definitions:
+ if d.in_builtin_module():
+ lst.append(dict(text='Builtin ' + d.description))
+ else:
+ lst.append(dict(filename=d.module_path, lnum=d.line_nr,
+ col=d.column + 1, text=d.description))
+ vim.eval('setqflist(%s)' % str(lst))
+ vim.eval('<sid>add_goto_window()')
+ return definitions
+
+
+def clear_func_def():
+ cursor = vim.current.window.cursor
+ e = vim.eval('g:jedi#function_definition_escape')
+ regex = r'%sjedi=([0-9]+), ([^%s]*)%s.*%sjedi%s'.replace('%s', e)
+ for i, line in enumerate(vim.current.buffer):
+ match = re.search(r'%s' % regex, line)
+ if match is not None:
+ vim_regex = r'\v' + regex.replace('=', r'\=') + '.{%s}' % \
+ int(match.group(1))
+ vim.command(r'try | %s,%ss/%s/\2/g | catch | endtry' \
+ % (i + 1, i + 1, vim_regex))
+ vim.eval('histdel("search", -1)')
+ vim.command('let @/ = histget("search", -1)')
+ vim.current.window.cursor = cursor
+
+
+def show_func_def(call_def=None, completion_lines=0):
+ if vim.eval("has('conceal') && g:jedi#show_function_definition") == '0':
+ return
+ try:
+ if call_def == None:
+ call_def = get_script().get_in_function_call()
+ clear_func_def()
+
+ if call_def is None:
+ return
+
+ row, column = call_def.bracket_start
+ if column < 2 or row == 0:
+ return # edge cases, just ignore
+
+ # TODO check if completion menu is above or below
+ row_to_replace = row - 1
+ line = vim.eval("getline(%s)" % row_to_replace)
+
+ insert_column = column - 2 # because it has stuff at the beginning
+
+ params = [p.get_code().replace('\n', '') for p in call_def.params]
+ try:
+ params[call_def.index] = '*%s*' % params[call_def.index]
+ except (IndexError, TypeError):
+ pass
+
+ # This stuff is reaaaaally a hack! I cannot stress enough, that this is
+ # a stupid solution. But there is really no other yet. There is no
+ # possibility in VIM to draw on the screen, but there will be one (see
+ # :help todo Patch to access screen under Python. (Marko Mahni, 2010
+ # Jul 18))
+ text = " (%s) " % ', '.join(params)
+ text = ' ' * (insert_column - len(line)) + text
+ end_column = insert_column + len(text) - 2 # -2 due to bold symbols
+ # replace line before with cursor
+ e = vim.eval('g:jedi#function_definition_escape')
+ regex = "xjedi=%sx%sxjedix".replace('x', e)
+
+ prefix, replace = line[:insert_column], line[insert_column:end_column]
+
+ # Check the replace stuff for strings, to append them
+ # (don't want to break the syntax)
+ regex_quotes = r'''\\*["']+'''
+ # `add` are all the quotation marks.
+ add = ''.join(re.findall(regex_quotes, replace))
+ # search backwards
+ if add and replace[0] in ['"', "'"]:
+ a = re.search(regex_quotes + '$', prefix)
+ add = ('' if a is None else a.group(0)) + add
+
+ tup = '%s, %s' % (len(add), replace)
+ repl = ("%s" + regex + "%s") % \
+ (prefix, tup, text, add + line[end_column:])
+
+ vim.eval('setline(%s, %s)' % \
+ (row_to_replace, repr(PythonToVimStr(repl))))
+ except Exception:
+ print(traceback.format_exc())
+
+
+def rename():
+ global temp_rename
+ if not int(vim.eval('a:0')):
+ temp_rename = goto(is_related_name=True, no_output=True)
+ _rename_cursor = vim.current.window.cursor
+
+ vim.command('normal A ') # otherwise startinsert doesn't work well
+ vim.current.window.cursor = _rename_cursor
+
+ vim.command('augroup jedi_rename')
+ vim.command('autocmd InsertLeave <buffer> call jedi#rename(1)')
+ vim.command('augroup END')
+
+ vim.command('normal! diw')
+ vim.command(':startinsert')
+ else:
+ cursor = vim.current.window.cursor
+ window_path = vim.current.buffer.name
+ # reset autocommand
+ vim.command('autocmd! jedi_rename InsertLeave')
+
+ replace = vim.eval("expand('<cword>')")
+ vim.command('normal! u') # undo new word
+ vim.command('normal! u') # 2u didn't work...
+
+ if replace is None:
+ echo_highlight('No rename possible, if no name is given.')
+ else:
+ for r in temp_rename:
+ if r.in_builtin_module():
+ continue
+ if vim.current.buffer.name != r.module_path:
+ vim.eval("jedi#new_buffer('%s')" % r.module_path)
+
+ vim.current.window.cursor = r.start_pos
+ vim.command('normal! cw%s' % replace)
+
+ vim.current.window.cursor = cursor
+ vim.eval("jedi#new_buffer('%s')" % window_path)
+ echo_highlight('Jedi did %s renames!' % len(temp_rename))
+ # reset rename variables
+ temp_rename = None
+
+
+def tabnew(path):
+ path = os.path.abspath(path)
+ for tab_nr in range(int(vim.eval("tabpagenr('$')"))):
+ for buf_nr in vim.eval("tabpagebuflist(%i + 1)" % tab_nr):
+ buf_nr = int(buf_nr) - 1
+ try:
+ buf_path = vim.buffers[buf_nr].name
+ except IndexError:
+ # Just do good old asking for forgiveness.
+ # don't know why this happens :-)
+ pass
+ else:
+ if buf_path == path:
+ # tab exists, just switch to that tab
+ vim.command('tabfirst | tabnext %i' % (tab_nr + 1))
+ break
+ else:
+ continue
+ break
+ else:
+ # tab doesn't exist, add a new one.
+ vim.command('tabnew %s' % path)
View
BIN  plugin/jedi_vim.pyc
Binary file not shown
Please sign in to comment.
Something went wrong with that request. Please try again.