diff --git a/autoload/modules.vim b/autoload/modules.vim index 18aad50..259e7e6 100644 --- a/autoload/modules.vim +++ b/autoload/modules.vim @@ -60,7 +60,7 @@ function! modules#GetImports() let [begin, end] = modules#ImportLineRange() let lines = getline(begin, end) - return filter(split(substitute(join(lines, ""), ",", "", "g"), " "), 'v:val !~ "^ *$"')[1:-1] + return sort(filter(split(substitute(join(lines, ""), ",", "", "g"), " "), 'v:val !~ "^ *$"')[1:-1]) endfunction function! modules#ImportMap(imports) diff --git a/autoload/util.vim b/autoload/util.vim index 80434b7..138f4d6 100644 --- a/autoload/util.vim +++ b/autoload/util.vim @@ -219,3 +219,46 @@ endfunction function! util#open_module_doc(module, symbol) call system("$BROWSER " . "http://nim-lang.org/docs/" . a:module . ".html#" . a:symbol) endfunction + +function! util#SelectNimProc(inner) + let curline = nextnonblank(line(".")) + let lastline = line("$") + let sl = curline + + function! s:IsProcStart(l) + return getline(a:l) =~ "\s*\\(proc\\|template\\|macro\\|func\\|method\\)\\s\\+\\w\\+(" + endfunction + + while sl > 0 + if s:IsProcStart(sl) && (curline == sl || indent(sl) < indent(curline)) + break + endif + let sl -= 1 + endwhile + + if !s:IsProcStart(sl) + normal + return + endif + + call cursor(sl, 0) + normal! 0V + let el = sl + 1 + + while getline(el) =~ "^\\s*$" || indent(el) > indent(sl) + let el += 1 + endwhile + + let el -= 1 + if a:inner + while getline(el) =~ "^\\s*$" + let el -= 1 + endwhile + endif + + call cursor(el, 0) + normal! $ + if a:inner + normal! h + endif +endfunction diff --git a/ftplugin/nim.vim b/ftplugin/nim.vim index 75494a8..e1998ff 100644 --- a/ftplugin/nim.vim +++ b/ftplugin/nim.vim @@ -41,6 +41,11 @@ nnoremap gd :NimDefinition nnoremap gt :NimInfo nnoremap gT :NimWeb +onoremap af :call util#SelectNimProc(0) +onoremap if :call util#SelectNimProc(1) +vnoremap af :call util#SelectNimProc(0)gv +vnoremap if :call util#SelectNimProc(1)gv + autocmd! BufReadPost,BufWritePost,CursorHold,InsertLeave,TextChanged,InsertEnter *.nim call highlighter#guard() autocmd! BufWinEnter,BufWritePost,FileWritePost *.nim call features#outline#run(1) autocmd! VimResized,WinEnter * call features#outline#render() diff --git a/plugin/nim.vim b/plugin/nim.vim index 9cbba42..13f41fc 100644 --- a/plugin/nim.vim +++ b/plugin/nim.vim @@ -24,6 +24,9 @@ function! FindNimModulesPath() return "/usr/lib/nim/" endfunction +if exists("g:ycm_semantic_triggers") + let g:ycm_semantic_triggers["nim"] = ['.', '('] +endif let g:nvim_nim_exec_nim = CheckDependency("nim") let g:nvim_nim_exec_nimble = CheckDependency("nimble") @@ -32,8 +35,6 @@ let g:nvim_nim_exec_bash = CheckDependency("bash") let g:nvim_nim_deps_nim = FindNimModulesPath() let g:nvim_nim_deps_nimble = FindNimbleModulesPath() -let g:nvim_nim_highlighter_enable = 1 - let g:nvim_nim_highlighter_enable = 1 let g:nvim_nim_highlighter_semantic = 1 let g:nvim_nim_enable_async = 1