Strange String negative index behavior

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange String negative index behavior

Nikolay Aleksandrovich Pavlov
If I want to get some character with negative index I get an empty string:
:let t="abc"
:echo t[-2]
:echo t[-2]==""
1
:echo t[-2:][0]
b


(zyx:~) % LANG=C vim --version
VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Feb 12 2010 07:37:05)
Included patches: 1-303
Modified by Gentoo-7.2.303
Compiled by root@zyx-desktop
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
+cryptv +cscope +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
+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 -osfiletype +path_extra +perl +postscript
+printer +profile +python +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_interact +xterm_clipboard -xterm_save
   system vimrc file: "/etc/vim/vimrc"
     user vimrc file: "$HOME/.vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/usr/share/vim"
Compilation: i686-pc-linux-gnu-gcc -c -I. -Iproto -DHAVE_CONFIG_H     -O2 -march=prescott -mtune=prescott -pipe -mmmx -msse -msse2 -
msse3 -mfpmath=sse -fomit-frame-pointer -D_FORTIFY_SOURCE=1    -we147 -DDEBUGGING   -D_LARGEFILE_SOURCE -
D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm  -I/usr/lib/perl5/5.8.8/i686-linux/CORE  -I/usr/include/python2.6 -pthread  
Linking: i686-pc-linux-gnu-gcc   -rdynamic  -Wl,-O1 -L/usr/local/lib -o vim    -lXt -lcurses -lacl -rdynamic  -L/usr/local/lib
/usr/lib/perl5/5.8.8/i686-linux/auto/DynaLoader/DynaLoader.a -L/usr/lib/perl5/5.8.8/i686-linux/CORE -lperl -lutil -lc -
L/usr/lib/python2.6/config -lpython2.6 -lutil -lm -Xlinker -export-dynamic

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Strange String negative index behavior

Jürgen Krämer-4

Hi,

ZyX wrote:
> If I want to get some character with negative index I get an empty string:
> :let t="abc"
> :echo t[-2]
> :echo t[-2]==""
> 1
> :echo t[-2:][0]
> b

see

  :help expr-[]

Regards,
Jürgen

--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

To unsubscribe, reply using "remove me" as the subject.