I'm trying to have text longer than a vim windows displayed on several lines. For this, I tried to follow the advice of this blog by entering set wrap in the .vimrc file but nothing changes and the text is still longer than the window width. Is there another function in my .vimrc file that desables it. Here is the .vimrc file:

" Set the line number

set clipboard=unnamed
set modeline
set hlsearch
set ruler
set laststatus=2
set statusline+=%F
set title
set shiftwidth=0
set autoindent
set smartindent
set ignorecase
set smartcase
" set number relativenumber
set nolist
set number 
set spelllang=en
set spell
set expandtab " define the size of indentation 
set shiftwidth=4 " define the size of indentation

set wrap "wrap lines longer than the screen's width " https://agilesysadmin.net/how-to-manage-long-lines-in-vim/

" setlocal foldmethod=syntax

" NERDtree https://shapeshed.com/vim-netrw/
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 25
"augroup ProjectDrawer
"  autocmd!
"  autocmd VimEnter * :Vexplore
"augroup END

xnoremap p pgvy " keep copied item in clipoard even after command p

" set syntax (e.g. color highlighting in code)
" syntax enable 
syntax on
" colorscheme distinguished
colorscheme onedark
" colorscheme desert
" colorscheme delek
" colorscheme blue
" colorscheme darkblue
" colorscheme default
" colorscheme delek
" colorscheme desert
" colorscheme elflord
" colorscheme evening
" colorscheme koehler
" colorscheme morning
" colorscheme murphy
" colorscheme pablo
" colorscheme peachpuff
" colorscheme ron
" colorscheme shine
" colorscheme slate
" colorscheme torte
" colorscheme zellner

hi Normal guibg=NONE ctermbg=NONE

" set nocompatible              " be iMproved, required
" filetype off                  " required

" automatically close brackets, parenthesis etc...
" inoremap " ""<left>
" inoremap ' ''<left>
" inoremap ( ()<left>
" inoremap [ []<left>
" inoremap { {}<left>
" inoremap {<CR> {<CR>}<ESC>O
" inoremap {;<CR> {<CR>};<ESC>O

call plug#begin()

Plug 'dag/vim-fish'

call plug#end()

filetype plugin on
filetype plugin indent on  " optional!
"syntax enable
highlight LineNr ctermfg=grey

"set nocompatible
"filetype off
"set rtp+=~/.vim/bundle/vundle/
"call vundle#rc()
"Bundle 'gmarik/vundle'
"Bundle 'dag/vim-fish'
"filetype plugin indent on    " required
"highlight LineNr ctermfg=grey

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

Plugin 'JuliaEditorSupport/julia-vim'
Plugin 'lervag/vimtex'

" A Vim Plugin for Lively Previewing LaTeX PDF Output
Plugin 'xuhdev/vim-latex-live-preview'
let g:livepreview_previewer = 'evince'
let g:tex_flavor='latex'
" let g:livepreview_previewer = 'open -a Preview'
" autocmd Filetype tex setl updatetime=700 

"let g:Tex_DefaultTargetFormat='pdf'

" All of your Plugins must be added before the following line
call vundle#end()            " required

" call plug#begin(g:plugged_home)
"     " other plugins...
"     " --------- adding the following three plugins for Latex ---------
"     Plug 'lervag/vimtex'
"     Plug 'Konfekt/FastFold'
"     Plug 'matze/vim-tex-fold'
"     " other plugins...
" call plug#end()

" Autocomplete for Python
Plugin 'davidhalter/jedi-vim'


The help :h 'wrap' tells us that the option is local to a window. So setting it up in your vimrc will not affect the windows you will open while using vim.

You have several solutions then:

  • Manually using :set wrap on windows where you need the option enabled.

  • Using an autocommand to set the option everywhere:

    augroup wrap
      autocmd BufWinEnter * setlocal wrap
    augroup END
  • Using a ftplugin to set the option for the filetypes you need. For example for markdown files create ~/.vim/after/ftplugin/markdown.vim and put setlocal wrap in it.

See :h autocmd, :h autocmd-events and :h ftplugin

| improve this answer | |
  • Sorry if I was a bit to quick for the feedback @statox: :set wrap does indeed work for each new window, but the general command (which is what I'm looking for) augroup wrap autocmd! autocmd WinEnter * setlocal wrap augroup END does not seem to work... – ecjb Jul 16 at 9:16
  • @ecjb My bad I used the wrong autocommand event, it's BufWinEnter not WinEnter – statox Jul 16 at 10:23
  • 1
    many thanks @statox. Now it works! – ecjb Jul 16 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.