Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

{<enter>} doesn't respect shiftwidth #36

Closed
duellj opened this Issue Mar 30, 2012 · 8 comments

Comments

Projects
None yet
4 participants

duellj commented Mar 30, 2012

I have my shiftwidth set to 2 (as well as my tabstop), so when I input {<enter>, I expect the following:

{
  #
}

With two spaces. Instead, I get 4 spaces:

{
    #
}

Looks like the plugin isn't respecting shiftwidth and always shifting 4 spaces.

It respects shiftwidth for me.

Owner

kana commented Mar 30, 2012

Thank you for the feedback. The problem seems to depend on how buffer-local options are configured. @duellj, would you mind to tell me your configuration, by pasting the result of :setlocal and :version?

duellj commented Mar 30, 2012

:setlocal

--- Local option values ---
--autoread            cursorline          errorformat=        filetype=php        keywordprg=         makeprg=            path=               shiftwidth=2        tabstop=2           undofile
  cryptmethod=        define=             expandtab           grepprg=            list                number              scroll=15           syntax=php          textwidth=80
  comments=s1:/*,mb:*,ex:*/,://,:#
  commentstring=// %s
  fileencoding=utf-8
  foldtext=PHPFoldText()
  formatoptions=qrowcb
  include=\(require\|include\)\(_once\)\?
  indentexpr=GetPhpIndent()
  indentkeys=0{,0},0),:,!^F,o,O,e,*<Return>,=?>,=<?,=*/
  matchpairs=(:),{:},[:],<:>
  omnifunc=phpcomplete#CompletePHP
  statusline=%!Pl#Statusline(0,1) 

:version

VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Sep 18 2011 16:00:17)
MacOS X (unix) version
Included patches: 1-315
Compiled by Bjorn Winckler <bjorn.winckler@gmail.com>
Huge version with MacVim 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_gui +diff +digraphs +dnd -ebcdic +emacs_tags +eval +ex_extra +extra_search +farsi +file_in_path +find_in_path +float +folding -footer +fork() +fullscreen -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 +multi_byte +multi_lang -mzscheme +netbeans_intg +odbeditor +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
+transparency +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"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe  -DMACOS_X_UNIX -no-cpp-precomp  -g -O2 -D_FORTIFY_SOURCE=1
Linking: gcc   -L.    -L.         -L/usr/local/lib -o Vim -framework Cocoa -framework Carbon      -lncurses  -liconv -framework Cocoa    -fstack-protector -L/usr/local/lib  -L/System/Library/Perl/5.12/darw
in-thread-multi-2level/CORE -lperl -lm -lutil -lc -framework Python   -framework Ruby 
Owner

kana commented Mar 30, 2012

Thank you! I'll try to reproduce the problem later.

Owner

kana commented Apr 2, 2012

I've succeeded to reproduce the problem. It depends on how automatic indentation for the current buffer behaves. At least, the default configuration to indent PHP script (GetPhpIndent) adjusts indentation of the current line before inserting a new line.

For example, if the current buffer contains the following lines:

<?php?
if (foo) {
        }

The result of :3 execute 'normal!' "A\<Enter>X" will be:

<?php?
if (foo) {
}
X

Such behavior is not expected for the default rules to "expand" {} etc. So that both GetPhpIndent and vim-smartinput indent the same line between { and }. That's why the line is indented too deep.

I'll revise the rules later.

@kana kana closed this in 6853833 Apr 3, 2012

sgtpep commented Apr 6, 2012

It still doesn't work correctly with set smartindent. The result looks like:

  body {
  __<caret>
  __}

sgtpep commented Apr 6, 2012

I added this line to my .vimrc as workaround:

call smartinput#define_rule({'at': '{\%#}', 'char': '<Enter>', 'input': '<Enter><Enter><Backspace><Up><C-o>S'})```

(added <Backspace> before <Up>)

Owner

kana commented Apr 6, 2012

@sgtpep That's a separate issue, and the cause of the problem is that } is not automatically indented for the kind of file you edit. It's not a part to be covered by vim-smartinput. And your workaround is not generic for all configurations for automatic indentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment