vim on FreeBSD does not react on arrow keys correctly and other vi-like behaviours

5,576

Solution 1

This is generally a terminal setting problem. Check your $TERM environment variable on the FreeBSD side, and check what your local terminal setting is. This is almost certainly the problem with the arrow keys.

In addition to this, make sure you have the standard set of "unbreak my vim" .vimrc settings applied.

set nocompat
set backspace=eol,start,indent

If you're sure the terminal settings are correct, but you're still having backspace issues, take a look at vim's help

:help fixdel

Solution 2

I've just recently set up a FreeBSD 8.2 server after mostly working with Linux, and I had the exact same frustration with VI. The problem is that FreeBSD comes with very different defaults for VI than most Linux distros.

Thanks to stumbling onto this page: http://jmcpherson.org/vimrc.html, here's how I set up my .vimrc file to get VI working the way I'm used to:

set nocompatible
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
set guioptions-=T
set vb t_vb=
set ruler
set nohls
set incsearch
set virtualedit=all
set bs=2

I used the nano text editor to make the file because VI was giving me so much trouble.

For anyone new to VI, just create a text file in your home directory called .vimrc and paste the contents of the code box above and save. Or you can try any of those options right in VI by typing a : then the option, i.e. :set ruler and hitting enter.

Solution 3

Are you typing "vim", or assuming that typing "vi" runs Vim?

On FreeBSD, the command "vi" is likely to get you nvi.

Solution 4

my guess is following could be the possible reason for this issue:

  1. May be in your vimrc file by mistake someone has set vim to behave like vi.
    set compatible
  2. Your vim is pointing to original vi binary.

Solution 5

First thing I do after installing vim:

cp ${LOCALBASE:-"/usr/local"}/share/vim/vim*/vimrc_example.vim ~/.vimrc

That has most sane defaults, except that I set background=dark.

Share:
5,576

Related videos on Youtube

Louis Gerbarg
Author by

Louis Gerbarg

Updated on September 17, 2022

Comments

  • Louis Gerbarg
    Louis Gerbarg over 1 year

    I tried to use vim on FreeBSD (via ssh on Linux xterm-compatible terminal). However vim behaves similar to vi out-of-box. For example it does not react on delete key, insert F character instead of going up while on insert mode etc.

    On FreeBSD X11 is not installed.

    Edit: As asked I post vim --version

    # vim --version
    VIM - Vi IMproved 7.2 (2008 Aug 9, compiled Jul 28 2010 11:48:54)
    Included patches: 1-6, 8-35, 37-48, 50-70, 73, 75-87, 90-92, 94-100, 102-137, 139-149, 151-171,     173-190, 192-193, 195-203, 206-211, 213-215, 217-218, 220-232, 234-246, 251-259, 261-301, 303-319, 321-322, 324-335, 337-351, 353-361, 363, 366-371, 373, 375-376, 378-383, 385-387, 389-398, 401-402, 404-411
    Compiled by [email protected]
    Big 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 -xterm_clipboard -xterm_save 
       system vimrc file: "$VIM/vimrc"
         user vimrc file: "$HOME/.vimrc"
          user exrc file: "$HOME/.exrc"
      fall-back for $VIM: "/usr/local/share/vim"
    Compilation: cc -c -I. -Iproto -DHAVE_CONFIG_H   -I/usr/local/include  -O2 -pipe -fno-strict-aliasing  -D_FORTIFY_SOURCE=1        
    Linking: cc   -L/usr/local/lib -o vim       -lm -ltermlib -liconv  
    
    • gvkv
      gvkv over 13 years
      What keymap are you using on the Linux box?
    • Louis Gerbarg
      Louis Gerbarg over 13 years
      uk (set in /etc/conf.d/keymaps). In X11 uk + some customization. I use gnome-terminal.
    • Louis Gerbarg
      Louis Gerbarg about 8 years
      Any reason for downvote?
  • Louis Gerbarg
    Louis Gerbarg over 13 years
    I'm typing vim.
  • Alex Bitek
    Alex Bitek over 13 years
    In a terminal use: type -a vi and type -a vim After that: ls -ld /usr/bin/vi and ls -ld /usr/bin/vim to see if there's a symbolic link.
  • Louis Gerbarg
    Louis Gerbarg over 13 years
    which vim --> /usr/local/bin/vim, which vi --> /usr/bin/vi. I don't have type --> no such command. None is symlink.
  • Warren Young
    Warren Young over 13 years
    "type" is a Bash builtin. "type -p" is the same thing as "which", and "type -a" just extends that. Can you post the output of "vim --version"?
  • Louis Gerbarg
    Louis Gerbarg over 13 years
    posted in main post
  • Louis Gerbarg
    Louis Gerbarg over 13 years
    As stated it is not pointing. I don't have any vimrc or similar file.
  • xenoterracide
    xenoterracide over 13 years
    @Maciej but does freebsd set any defaults. If I had a nickel for every distro that screwed up vim defaults... have you read the :h compatible? have you checked the vimrc file that freebsd probably has?
  • Hemant
    Hemant over 13 years
    @Maciej: did you check for .vimrc ?
  • Louis Gerbarg
    Louis Gerbarg over 13 years
    I don't have .vimrc
  • Ben Baron
    Ben Baron almost 13 years
    As I interpret the question, it looks like he wasn't just asking about the delete key, or just arrow keys typing letters in insert mode. It looks to me that he's a Linux user using FreeBSD for the first time and frustrated with the VI defaults as compared to the standard defaults used in most Linux distros. The options I posted will get VI working just like it usually does in Linux when installing vim-enhanced. So I think it's a good addition to the accepted answer, and also there's no need to mess with terminal settings (at least I didn't need to). Hopefully my info helps others.
  • zilitron
    zilitron over 11 years
    Thanks for this. It fixed a lot of things for me. It's got a lot of extra stuff, of course, but it's a good starting point.