Search notes:

vim script: array indexes

"
"  ..\run_ array_indexes


redir > array_indexes.out

let a = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']

echo a[2]
" two

let  two_through_four = a[2:4]
echo two_through_four
" ['two', 'three', 'four']

let  first_four = a[:3]
echo first_four
" ['zero', 'one', 'two', 'three']

let  last_three = a[-3:]
echo last_three
" ['seven', 'eight', 'nine']

let  all_but_last_two = a[:-3]
echo all_but_last_two
" ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven']

" Accessing non existing indexes: {

try
  echo a[10]
catch /E684/
   echo "list index out of range "
endtry

" Use get() instead
echo get(a, 10, 'does not exist')
" does not exist
" }

redir END

q
Github repository about-vim, path: /vimscript/arrays-and-hashes/array_indexes.vim

See also

array and hashes
VIM script

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759619436, '216.73.216.149', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/vim/script/vimscript/arrays-and-hashes/array_indexes(83): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78