Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I always use Vim on our servers (mostly Ubuntu based) and I always lack a good configuration that suits vim over SSH without too much frills.

I'd like to gather as much as possible configuration settings for someone who writes mostly bash, zsh and ruby code directly on the server.

share|improve this question

5 Answers 5

The best thing I've learned recently is using jj instead of <esc> to enter normal mode:

imap jj <Esc>

Also, if you make use of splits via the split (tall terminal) or vsplit (wide terminal) command, then remapping the switch-split command is invaluable; I use , (comma) to switch amongst my splits:

map , <C-w><C-w>

Check out the top questions for vim over on Stack Overflow, too.

share|improve this answer

I use the following on basically every system I use. I haven't really put a lot of effort into modifying it though. I use vim as a config editing tool, over a large range of servers, but I don't tend to do a lot of development in vim these days

set modeline
set background=dark
set autowrite
nmap <tab> :bn<cr>
nmap <s-tab> :bp<cr>

The nmap options let me use tab and shift-tab to switch between multiple open buffers, which I find pretty invaluable.

share|improve this answer

Check the .vimrc and .vim from dakrone's dotfiles.

share|improve this answer

The following is my .vimrc which focuses heavily on perl, mason and javascript IDE functions, but you can adapt what you see here for ruby/sh specifics. Been using it for several years over SSH. Outside the IDE context, the automatic backups have saved my ass more than once.

" Embedded() is a function that will parse a text buffer 
" looking for embedded vim commands, and execute them.
" Call it with a range of lines to check, eg to check the whole 
" file:
" 
"  :%call Embedded() 
"
" Commands should be prefixed by the sequence :vim: .
"
function Embedded() range
    let n = a:firstline
    while n <= a:lastline
        let l = getline(n)
        let p = stridx(l,':vim:')
        if p > -1
            let p = p + 5 
            let c = strpart(l,p)
            execute c
        endif   
        let n = n + 1 
    endwhile 
endfunction
" call Embedded() whenever a file is loaded and 
" parse the entire file.  You may not want to do 
" this for *; maybe just your src tree or certain 
" file types or something.
autocmd BufWinEnter * %call Embedded()

" Create nested folds on custom expressions, based 
" on the current buffer's filetype or syntax. 
"
let g:foldlevel = 0 
let g:foldstartexpr = ''
let g:foldendexpr   = ''
function GetCustomFold()
    if getline(v:lnum) =~ g:foldstartexpr
        let g:foldlevel = g:foldlevel + 1 
        return ">".g:foldlevel
    elseif getline(v:lnum) =~ g:foldendexpr
        let thislevel = g:foldlevel
        let g:foldlevel = g:foldlevel - 1 
        return "<".thislevel
    else
        return g:foldlevel
    endif
endfunction
function SetFoldType()
    let f = &filetype ? &filetype : &syntax
    if f == 'mason'
        let g:foldstartexpr = '^\s*<\(script\|style\|%init\|%attr\|%once\|%args\|%flags\|%shared\|%def\)[^>]*>\s*$'
        let g:foldendexpr   = '^\s*</\(script\|style\|%init\|%attr\|%once\|%args\|%flags\|%shared\|%def\)[^>]*>\s*$'
    elseif f == 'perl'
        let g:foldstartexpr = '^sub.*{\s*$'
        let g:foldendexpr   = '^}\s*$'
    elseif f == 'javascript'
        let g:foldstartexpr = '^function.*{\s*$'
        let g:foldendexpr   = '^}\s*$'
    else
        return
    endif
    setlocal foldexpr=GetCustomFold()
    setlocal foldmethod=expr
endfunction
autocmd BufWinEnter * %call SetFoldType()

function SetPerlIDE()
    " check perl code with :make
    setlocal makeprg=perl\ -c\ %\ $*
    setlocal errorformat=%f:%l:%m
    setlocal autowrite

    " comment/uncomment blocks of code (in vmode)
    map ^C :s/^/#/gi<Enter>
    map ^X :s/^#//gi<Enter>

    " my perl includes pod
    let perl_include_pod = 1

    " syntax color complex things like @{${"foo"}}
    let perl_extended_vars = 1

    " Tidy selected lines (or entire file) with _t:
    nnoremap <silent> _t :%!perltidy -q<Enter>
    vnoremap <silent> _t :!perltidy -q<Enter>

    " perlcritic selected lines (or entire file) with _p:
    nnoremap <silent> _p :%!perlcritic -q<Enter>
    vnoremap <silent> _p :!perlcritic -q<Enter>
endfunction
autocmd FileType perl call SetPerlIDE()


" map II :r ~/.vim/template.pod<CR>

set tabstop=4
set number
set showmatch
set ruler
set backup
set backupdir=~/.vim/backups
set directory=~/.vim/backups
set tags=~/.vim/tags

set backupskip=/tmp/*,/private/tmp/*"

" we get colors, we get lots and lots of colors
syntax on
set bg=dark
colors darkblue
share|improve this answer

small work around from me u may like it if u r using vim

Step 1: Download the latest version of the plugin from vim.org

Download the plugin from vim.org

$ cd /usr/src $ wget -O mru.vim http://www.vim.org/scripts/download%5Fscript.php?src%5Fid=9274

Step 2: Install the MRU vim plugin

$ mkdir ~/.vim # if the directory does not exist already $ cd ~/.vim/plugin/ $ cp /usr/src/mru.vim .

7 Powerful Features of MRU.vim

After installing this plugin, whenever you open a file for reading or writing it will be added to the MRU list. 1. View the Most Recently Used Files in Vi / Vim Editor

:MRU

Note: :MRU (upper-case) works. :mru (lower-case) doesn't work.

:MRU will show “most recently used” files ordered by the recent usage from top to bottom as shown below. To open a file press ENTER while the cursor in that file name. Fig: Vim Editor displaying "Recent Documents" List

Fig: Vim Editor displaying "Recent Documents" List

Note: Immediately after installing the MRU plugin, you may not see any files in the MRU list. Use Vim editor to open few files after installing the plugin, for the MRU list to grow. 2. How to Increase MRU List Count? (Increase the Number of Files Stored)

By default MRU list stores only the last 10 used files. Add the following line to your ~/.vimrc to increase this limit as shown below.

$ cat ~/.vimrc let MRU_Max_Entries = 20

  1. How to Search Files Inside the MRU List

When you increased the number of files, it may be difficult to scroll through the MRU list to pick the file you are looking for. Instead, you can use the normal Vim commands to search inside the MRU list. So you can give (slash)/ and give a pattern to search.

In the following example, the MRU list was very long. I did a “/yum”, which moved the cursor automatically to /etc/yum.conf MRU entry. Pressing enter, will open this file. Fig: Search the MRU List Using /

Fig: Search the MRU List Using /

You can also use the MRU search functionality as explained below.

* Enter the partial file name and press TAB which will fill the file name, which you can open by pressing enter,
* Enter one or two characters of the file name or the path name, and press tabs to rotate around the file names.
  1. Opening Files from MRU List in a New Tab

Pressing enter on an MRU entry will open the file in the same window by default. It will open in new window if the file opened in the current window is not yet saved.

* To open the file from the MRU entry in a new Tab , press ‘t’ when the cursor is on a file name in MRU window.
* :tabn will take you to the next tab
* :tabp will take you to the previous tab
  1. Update the MRU Window

To update the current MRU window, press ‘u’. When ever opening the MRU window it will open the newer content always. 6. Excluding Certain Files Using MRU_Exclude_Files

To exclude certain files from being shown in the MRU, you can store the regex in the MRU_Exclude_Files variable as:

$ cat ~/.vimrc let MRU_Exclude_Files = '^/tmp/.\|^/var/tmp/.' " For Unix

The above will exclude the /tmp and /var/tmp from being stored in MRU. 7. Including Certain Files Using MRU_Include_Files

To include only certain kind of files in MRU, you can store the regex in the MRU_Include_Files variable as shown below. This will include only the files which are in /home/ramesh to be stored in MRU.

$ cat ~/.vimrc let MRU_Include_Files = '^/home/rajat/.*'

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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