vim incremental search stop at end of file

search, vim

Solution

Turn off the `'wrapscan'` option.

set nowrapscan

Problem

In Vim, when I'm doing an incremental search for "x" by entering `/x` I then press `n` to jump to the next occurrence. If I have just matched the last occurrence at the file, when I press `n` the cursor will start to look for a match at the beginning of the file---it will loop back to the beginning. I do not want it to loop back to the beginning. I want `n` to simply not find any more matches after it reaches the final occurrence. The reason I want this behavior is so that I can easily see when I have searched through the entire file. Does anyone know how to effect this behavior? FYI: I am using the following .vimrc options: ``` colorscheme zenburn " zenburn colorscheme set nocompatible " prevent Vim from emulating Vi's bugs set scrolloff=5 " keeps cursor away from top/bottom of screen set nobackup " don't make automatic backups set incsearch " incremental searching set ignorecase " case insensitive matching set smartcase " smart case matching set showmatch " show matching bracket set autoindent " indentation set smartindent " indentation set cindent " indenting for C code set tabstop=4 " 4-space tabs set shiftwidth=4 " 4-space tabs syntax on " syntax highlighting filetype on " behavior based on file type filetype plugin on " behavior based on file type filetype indent on " behavior based on file type set visualbell " replace beeping with flashing screen set gfn=Lucida_Sans_Typewriter:h10:cANSI ```

Original source