Giter VIP home page Giter VIP logo

vim-endwise's Introduction

endwise.vim

This is a simple plugin that helps to end certain structures automatically. In Ruby, this means adding end after if, do, def and several other keywords. In Vimscript, this amounts to appropriately adding endfunction, endif, etc. There's also Bourne shell, Z shell, VB (don't ask), C/C++ preprocessor, Lua, Elixir, Haskell, Objective-C, Matlab, Crystal, Make, Verilog and Jinja templates support.

A primary guiding principle in designing this plugin was that an erroneous insertion is never acceptable. The behavior is only triggered once pressing enter on the end of the line. When this happens, endwise searches for a matching end structure and only adds one if none is found.

While the goal was to make it customizable, this turned out to be a tall order. Every language has vastly different requirements. Nonetheless, for those bold enough to attempt it, you can follow the model of the autocmds in the plugin to set the three magic variables governing endwise's behavior.

Installation

Install using your favorite package manager, or use Vim's built-in package support:

mkdir -p ~/.vim/pack/tpope/start
cd ~/.vim/pack/tpope/start
git clone https://tpope.io/vim/endwise.git

Self-Promotion

Like endwise.vim? Follow the repository on GitHub and vote for it on vim.org. And if you're feeling especially charitable, follow tpope on Twitter and GitHub.

License

Copyright (c) Tim Pope. Distributed under the same terms as Vim itself. See :help license.

vim-endwise's People

Contributors

blueyed avatar bmalkus avatar camthompson avatar csarath avatar danieljaouen avatar emilv2 avatar fireproofsocks avatar gabesoft avatar hugovandevliert avatar huluk avatar imgx64 avatar jbernard avatar jmcantrell avatar jorinvo avatar julow avatar kassio avatar keith avatar kevinushey avatar lazywei avatar lonetwin avatar opt9 avatar sodapopcan avatar sudo-nice avatar sukima avatar synray avatar tangledhelix avatar thetic avatar tpope avatar whatyouhide avatar yous avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vim-endwise's Issues

Request for Vim’s ‘augroup’

Would it be possible for Endwise to insert the matching augroup END after an augroup {name}?

Thanks for writing this plugin, it saves me so many keystrokes.

endwise.vim breaks other mappings on <CR> (such as those from neocomplcache)

See neocomplcache here: http://www.vim.org/scripts/script.php?script_id=2620

When I source the two bundles using pathogen, my mapping craps out and inserts the vim code mapped by neocomplcache instead of executing it. When I disable endwise.vim, the same neocomplcache mappings work just fine.

The relevant neocomplcache vimrc lines (excerpt from the suggested configuration on the vimscripts page)
" Recommended key-mappings.
" : close popup and save indent.
inoremap neocomplcache#smart_close_popup() .""

The output of :verbose imap <CR> after booting vim:
i & neocomplcache#smart_close_popup() ."" 19_DiscretionaryEnd
Last set from ~/dotfiles/vim/bundle/endwise/plugin/endwise.vim

The output of :verbose imap <CR> after manually setting the mapping by running :inoremap <expr><CR> neocomplcache#smart_close_popup() ."\<CR>"
i * neocomplcache#smart_close_popup() .""

It'd be great if these two would cooperate!

Support local functions in Lua?

In Lua, local functions are often a good idea. So instead of

function add(x, y)
  return x + y
end

you'd use

local function add(x, y)
  return x + y
end

How do you feel about endwise supporting this? Thanks.

endwise not working; how to debug?

Hello,
I can't seem to get endwise working. I'm using the example program from why's (poignant) guide to ruby, pasted below in case the link doesn't work:

require 'net/http'
Net::HTTP.start( 'www.ruby-lang.org', 80 ) do |http|
  print( http.get( '/en/LICENSE.txt' ).body )
end

If I omit the end, move my cursor to the end of the print line, and press enter (insert mode) nothing happens. However <c-x><cr> inserts end every time.

Here's what I've tried:

  • remove my .vimrc, add one that only contains runtime bundle/vim-endwise/plugin/endwise.vim
  • checked :imap to make sure it says <cr> is mapped, it reports:
i  <Plug>AlwaysEnd & <SNR>8_AlwaysEnd
i  <Plug>DiscretionaryEnd & <SNR>8_DiscretionaryEnd
i  <SNR>8_AlwaysEnd * <C-R>=<SNR>8_crend(1)<CR>
i  <SNR>8_DiscretionaryEnd * <C-R>=<SNR>8_crend(0)<CR>
i  ï           * <C-O>o
i  <CR>          <CR><Plug>DiscretionaryEnd
i  <C-X><CR>     <CR><Plug>AlwaysEnd
  • checked what's being loaded with :scriptnames, it reports:
  1: /usr/share/vim/vimrc
  2: /usr/share/vim/vim73/debian.vim
  3: /usr/share/vim/vim73/syntax/syntax.vim
  4: /usr/share/vim/vim73/syntax/synload.vim
  5: /usr/share/vim/vim73/syntax/syncolor.vim
  6: /usr/share/vim/vim73/filetype.vim
  7: ~/.vimrc
  8: ~/.vim/bundle/vim-endwise/plugin/endwise.vim
  9: /usr/share/vim/vim73/plugin/getscriptPlugin.vim
 10: /usr/share/vim/vim73/plugin/gzip.vim
 11: /usr/share/vim/vim73/plugin/matchparen.vim
 12: /usr/share/vim/vim73/plugin/netrwPlugin.vim
 13: /usr/share/vim/vim73/plugin/rrhelper.vim
 14: /usr/share/vim/vim73/plugin/spellfile.vim
 15: /usr/share/vim/vim73/plugin/tarPlugin.vim
 16: /usr/share/vim/vim73/plugin/tohtml.vim
 17: /usr/share/vim/vim73/plugin/vimballPlugin.vim
 18: /usr/share/vim/vim73/plugin/zipPlugin.vim
 19: /usr/share/vim/vim73/syntax/ruby.vim

I'm not sure if it'll help, but my version information follows. What should I try next? I'm not sure why it's not working. Thanks for any help, and all the great plugins!

Version info:

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Mar 12 2012 06:24:15)
Included patches: 1-429
Modified by pkg-vim-maintainers@lists.alioth.debian.org
Compiled by buildd@
Huge version without GUI.  Features included (+) or not (-):
+arabic +autocmd -balloon_eval -browse ++builtin_terms +byte_offset +cindent 
-clientserver -clipboard +cmdline_compl +cmdline_hist +cmdline_info +comments 
+conceal +cryptv +cscope +cursorbind +cursorshape +dialog_con +diff +digraphs 
-dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path 
+find_in_path +float +folding -footer +fork() +gettext -hangul_input +iconv 
+insert_expand +jumplist +keymap +langmap +libcall +linebreak +lispindent 
+listcmds +localmap -lua +menu +mksession +modify_fname +mouse -mouseshape 
+mouse_dec +mouse_gpm -mouse_jsbterm +mouse_netterm -mouse_sysmouse 
+mouse_xterm +mouse_urxvt +multi_byte +multi_lang -mzscheme +netbeans_intg 
+path_extra -perl +persistent_undo +postscript +printer +profile +python 
-python3 +quickfix +reltime +rightleft -ruby +scrollbind +signs +smartindent 
-sniff +startuptime +statusline -sun_workshop +syntax +tag_binary 
+tag_old_static -tag_any_white -tcl +terminfo +termresponse +textobjects +title
 -toolbar +user_commands +vertsplit +virtualedit +visual +visualextra +viminfo 
+vreplace +wildignore +wildmenu +windows +writebackup -X11 -xfontset -xim -xsmp
 -xterm_clipboard -xterm_save 
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Wformat-security -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1      
Linking: gcc   -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,--as-needed -o vim       -lm -ltinfo -lnsl  -lselinux  -lacl -lattr -lgpm -ldl     -L/usr/lib/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions      

Support for Makefiles...

It'd be nice to have support for Makefiles:

  • if[n]eq...endif
  • ifdef...endif
  • define...endef

I've tried adding this myself, but I think it needs someone more adept at Vim and it's regular expressions.

Plugin functionality broken

Not sure if this really is the case, but from my POV as a user it is:

  • I installed it via pathogen

( $ ) ls ~/.vim/bundle/
nerdcommenter nerdtree supertab syntastic vim-autoclose vim-endwise vim-fugitive

  • I open up a new window in bash
  • I do a

vi /tmp/foo.rb

and then start with:

if true

and hit ENTER.

Shouldn't the plugin now automatically add an "end" here?

Or is this a configuration issue?

There is no mention of a specific configuration here https://github.com/tpope/vim-endwise so I assumed it would work out of the box with reasonable defaults.

Endwise / SuperTab conflict?

When using SuperTab, it also maps <CR> and causes <Plug>DiscretionaryEnd to appear on the screen when pressing <CR>.

I'm not sure if this is a problem with endwise, supertab or vim itself as my vim-fu is horrible.

Keeping SuperTab from mapping <CR> fixes the problem. In your vimrc:

let g:SuperTabCrMapping = 0

But this seems more like a hack than anything else.

At the very least, it might be nice to have this noted in the wiki/README.

vim-endwise doesn't support ruby 2.1-style method prefixes

In Ruby 2.1, the def ... end syntax returns the defined method's name as a symbol. This lets us do things like private def ... end, helper_method def ... end, &c. However, an end isn't inserted because the regular expression used seems to require the def only be prepended by whitespace.

Sorry for not putting together a pull request for this, but I'm not sure how this weirdo regexp syntax works.

add extra indentation on nested if

it might be that there is something wrong with my configuration.

first it is working

if a
|
end

but when i add tab and then create another if it goes like this

if a
  if b
    |
    end
end

here is my .vimrc

set nu
syn on
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set mouse=a
set smartindent
set autoindent
set pastetoggle=<F3>
set ttymouse=xterm2

syntax on
filetype on
filetype plugin indent on

"window commands
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
map  <F12> :set hls!<CR>
imap <F12> <ESC>:set hls!<CR>a
vmap <F12> <ESC>:set hls!<CR>gv


"tab commands
map <C-S-]> gt
map <C-S-[> gT
map <C-1> 1gt
map <C-2> 2gt
map <C-3> 3gt
map <C-4> 4gt
map <C-5> 5gt
map <C-6> 6gt
map <C-7> 7gt
map <C-8> 8gt
map <C-9> 9gt
map <C-0> :tablast<CR> 

"Plugins and phatogen
call pathogen#infect()
map <F2> :NERDTreeToggle<CR>

if $TERM =~ '^screen-256color'
    map <Esc>OH <Home>
    map! <Esc>OH <Home>
    map <Esc>OF <End>
    map! <Esc>OF <End>
endif

Feature request: Ctrl+J support

Since Ctrl+J is equivalent to the Enter key (I'm not sure how universal is that though), would it be possible to make the plugin work for both and ?

It would be awesome, since I've been using Ctrl+J a lot more than enter (it is way more comfortable with CapsLock mapped to Ctrl).

Thanks!

Mess up with getchar()

Hi tpope,

Thanks for sharing your work.
I've encountered an issue with vim-endwise. When I call something like "let c = getchar()" a string is inserted at the current line. This happens only when the plugin is, well, plugged.

Problem typing ï on a mac in vim

The standard mac way to type ï is (in vim parlance) " i"

This does not work in MacVim or the OS X system /usr/bin/vim when endwise is loaded (via pathogen).

A similar approach works for many other accented letters, including umlauts (so ü is no problem).

I've tried disabling everything else besides endwise (except pathogen), and the problem persists. I've looked through the various lists of active mappings and can find nothing. I tried disabling winaltkeys, and that wasn't it.

I think this is the oddest bug I've ever found. So, at least that's something. I hope you have some ideas! For now, I'm just disabling endwise.

Support for Elixir def*

Currently, endwise only works partially with Elixir. For example (| is the cursor):

receive do|

# after hitting <CR>, this becomes:

receive do
  |
end

but

defmodule Fnord do|

# after hitting <CR>, this becomes:

defmodule Fnord do
|

Endiwse break smartindent in C-like languages

Hello!
I'm using Vundle as a package manaker for vim.

Without endwise I have following scenario:

function ()
{|}

when I press enter:

function ()
{
    |
}

With endwise installed:

function ()
{|}

press enter:

function ()
{
|}
:verbose imap <cr>
i  <CR>          <CR><Plug>DiscretionaryEnd                                                             
        Last set from ~/vimfiles/vim/bundle/vim-endwise/plugin/endwise.vim                      

Is possible to retrieve initial functionality?

Incompatibility with autocomplpop / does not handle pumvisible()

A visible popup menu will cause <cr> to do (effectively) nothing, instead
of accepting the selected element.

To reproduce:

  1. Install autocomplpop
  2. vim test.sh
  3. enter this text:

    !/bin/ba

  4. A popup will appear suggesting /bin/bash, but selecting it won't do anything.

This does not happen in general, but I have noticed it in the corner case mentioned above only.
This might be related to the shell-filetype only.

LaTex

Please add support for LaTex........

Auto add curly braces support for C/C++/Objective-C

Is there some reason this plugin doesn't have the support for curly braces in those languages? I think it's pretty safe to add a closing curly brace if the use typed }<CR> Or maybe I am missing something.
Looks like this is easy to add and I guess the question is why it may be wrong.
Thanks.

PS More a personal question to Tim: do you use any auto-braces-closing plugin or do you prefer closing them yourself?

Jumping past end

Once you've reached the "end" of your definition (or if, etc), what's the fastest way to jump past it and continue coding?

Indentation of `esac` is off

With vim-endwise installed, the indentation of case...esac structures in shell scripts is off.

The result is something like this:

case "$1" in                                                               
     foo)                                                                
         echo hello                                                    
         ;;                                                                   
     esac

An earlier comment suggests that this is a known problem. However, @tangledhelix seems to say there that the problem occurs with or without vim-endwise. That's not the case, I don't think. I only have this problem with vim-endwise installed.

Enter conflicts with neocomplcache

This is cross-posting from neocomplcache issues as recommended by @Shougo.

Note that I'm also using vim-endwise. Using the recommended snippet from doc/neocomplcache.txt (see 351a2f102460):

  inoremap <expr><silent> <CR> <SID>my_cr_function()
  function! s:my_cr_function()
    return pumvisible() ? neocomplcache#close_popup() . "\<CR>" : "\<CR>"
  endfunction

when pressing enter when choosing autocompletion from the menu it selects this autocompletion and also moves you to the next line (i.e. <CR> is literally inserted), while using the previous snippet for <CR> mapping in insert mode (inoremap <expr><CR> neocomplcache#smart_close_popup() . "\<CR>") without the vim-endwise plugin when pressing <cr> in insert mode on autocomplete menu item it would only select the item from the autocompletion menu and would not insert a <cr> in the code.

Also note that using this snippet: inoremap <expr><CR> neocomplcache#smart_close_popup() . "\<CR>" conflicts with vim-endwise, which is issue #88.

After hit <CR>, endwise repeat the function name in the end, why?

screen shot 2013-08-14 at 1 55 26

As the screenshot above, I was editing .vimrc, I try to write a new function, but as soon as I hit the , endwise will insert my function name right after the endfunction and with a ! appended.

I double checked the mapping which is correct to response endwise, so I can't figure out why this is happening.

[Feature] Add class/module/method names after 'end' keyword

Would it be possible to have commented-out class/module/method names automatically added behind end keywords? Example:

module Module
  class Superclass
    class Subclass
      def foo
      end # def foo
    end # class Subclass

    class SubclassB
    end # class SubclassB
  end # class Superclass
end # module Module

<CR> in insert mode is causing two newlines w/ supertab installed

As of commit 7225610 (Fix duplicates on ), when I hit enter in insert mode, I am getting two newlines instead of just one.

Ran a git bisect to find the specific commit that introduced the bug.

Removing supertab from my bundle list resolves the issue as does disabling CR binding in supertab.

BTW. Keep up the great work. Your plugins are fantastic.

Crystal support

Hello,

I’d like to add support for Crystal, which syntax is heavily inspired by Ruby: I think the rules will be the same as Ruby except one more keyword: macro, which is used like def but executed at compile-time.

I don’t understand what are b:endwise_pattern and b:endwise_syngroups for. Would you explain them?
Thanks.

Requires `syntax on`?

I apologize if this is a very stupid question, but am I correct
that this plugin depends on syntax (i.e. syntax highlighting)
being turned on?

It's a shame if so, but if that's the only way you could see to
make this work and it's intended behavior, that's fine. I just
wanted to confirm that the side-effect was intended.

Closing latex environments

I was trying to add latex environment to endwise by adding the following code:

let b:endwise_addition = '\\end{\=submatch(1)}'
let b:endwise_addition = 'end'
let b:endwise_words = 'begin'
let b:endwise_pattern = '^\s*\\begin{\(.\+\)}.*$' 
let b:endwise_syngroups = 'texBeginEndName'

to ftplugin/tex.vim and it fails.

I guess I completely do not understand how configuration is supposed to be done. The idea is to close the following block:

\begin{env}[optional]{parameters}

\end{env}

The block may be indented. Is it possible to add the latex support to the endwise?

Thanks!

<CR> in Insert-mode breaks up changes

Normally if you enter Insert-mode, everything from entering the mode until you return to Normal-mode is stored as one change.

It seems like every <CR> in Insert-mode breaks the change up into one more. So if between entering Insert-mode and exiting back to Normal-mode involved pressing <CR> three times, then you'd have three changes in total, instead of the expected one.

Enter key conflict with AutoPairs

Both endwise and AutoPairs bind the Enter key in insert mode:

:imap <cr>
i  <CR>        *@AutoPairsReturn()
i  <CR>          <CR><Plug>DiscretionaryEnd

But only AutoPairs' binding is taking effect. How can I make them both work? Thanks.

Add support for 'o'

Just a thought, it would be nice (though perhaps difficult, I can't say) to also add support for o and get similar behavior as we get with a <CR>. Since you don't have this support I will assume you've already considered and rejected the idea for some reason, just wanted to know your thoughts. You can close it giving an explanation if this doesn't appeal.

Adds pumvisible() ? "\" : "\\ to every Enter keypress

This is likely a conflict with another plugin, but whenever I go into insert mode in a file recognized by endwise and hit enter, it adds this to the previous line and then beeps:

    pumvisible() ? "\" : "\\

On every enter press:

        "pumvisible() ? "\\" : "\\
        "pumvisible() ? "\\" : "\\
        "pumvisible() ? "\\" : "\\

Any idea how how to track down what's inserting this? I see that command used in 3 other plugins I have but none of them with that syntax

~/.vim/bundle (master ✎ ) $ ack pumvisible

    match-tag/ftplugin/html.vim
    22:    if pumvisible() || (&t_Co < 8 && !has("gui_running"))

    ultisnips/autoload/UltiSnips.vim
    44:    if pumvisible()

    ultisnips/doc/UltiSnips.txt
    1295:  inoremap <silent> <F12> <C-R>=(pumvisible()? "\<LT>C-E>":"")<CR><C-R>=UltiSnipsCallUnite()<CR>
    1296:  nnoremap <silent> <F12> a<C-R>=(pumvisible()? "\<LT>C-E>":"")<CR><C-R>=UltiSnipsCallUnite()<CR>

Confirmations of substitution does not work correctly on command-line window

A document in current buffer is as follows.

test
test
test

Expected behaviors

In vim

q:i
%s/test/Yeah/gc^M

( ^M is an enter key. )

I can see some confirmations like replace with Yeah (y/n/a/q/l/^E/^Y)? about 3 times.

Actual behaviors

In vim

q:i
%s/test/Yeah/gc^M

I can NOT see some confirmations like replace with Yeah (y/n/a/q/l/^E/^Y)? .

I see as follows as an alternative,

search hit BOTTOM, continuing at TOP

... and already replaced strings without confirmations.

Yeah
Yeah
Yeah

Cannot input Russian 'п' character under Cygwin (codepage Windows-1251)

I use vim under Cygwin v1.7.22 (Windows 7. Codepage Windows-1251)
When vim-endwise is loaded, I cannot input Russian letter 'п' (ASCII code 238 (0xEF)). When I press this letter line breaks as if I pressed RETURN.
This breakage is introduced definitly with vim-endwise (I removed all other plugins when I was finding out the reason) installed both as "standalone" plugin or with vim-pathogen.

not working?

I'm sure it's something obvious, but as a complete vim noob I cannot get this plugin to work for me.
If I do :imap I do see that the endwise mappings are set, and I am editing a rb file.
But nothing is happening. My .vimrc is

set nocompatible
set ff=unix
set ts=8
set sw=4
set sts=4
filetype on
filetype indent on
filetype plugin on
autocmd BufEnter * lcd %:p:h

Help? Thanks.

Request: support for ERB

It would be nice if Endwise could turn the following:

<% if true %> |

into the following:

<% if true %>
    |
<% end %>

(with | being the cursor)

Remove ending if entered manually

It would be nice if it emulated the behaviour of paren-matching plugins that skip over the closing parenthesis if you enter it, rather than inserting a new one. For example:

def foo
   |
end

If you type end and hit enter with the cursor at the |, it should remove the the existing end and move the cursor to the line after it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.