Skip to content

Instantly share code, notes, and snippets.

@faustind
Last active March 8, 2026 04:46
Show Gist options
  • Select an option

  • Save faustind/eb339bfa37a9c68371c31ecceb3dad2a to your computer and use it in GitHub Desktop.

Select an option

Save faustind/eb339bfa37a9c68371c31ecceb3dad2a to your computer and use it in GitHub Desktop.
Sensible vimrc for ssh machines
" --- General Settings ---
set nocompatible " Disable Vi compatibility to enable powerful Vim features
set encoding=utf-8 " Force UTF-8 encoding
filetype plugin indent on " Enable filetype detection, plugins, and indentation rules
syntax on " Enable syntax highlighting
" --- UI & Visuals ---
set number " Show line numbers
set ruler " Show cursor position (row, col) in status line
set showcmd " Show partial commands in the bottom right
set wildmenu " Enable visual autocomplete menu for command mode
set laststatus=2 " Always show the status line
set cursorline " Highlight the current line (improves visibility)
set scrolloff=5 " Keep 5 lines of context above/below cursor when scrolling
set t_Co=256 " specific to SSH: force 256 colors if terminal supports it
" --- Colors ---
try
colorscheme desert " 'desert' is a standard scheme available on almost all systems
catch
endtry
" --- Indentation (Standard 4-space) ---
set tabstop=4 " Width of a hard tab character
set shiftwidth=4 " Size of an indent
set softtabstop=4 " Number of spaces a tab counts for when editing
set expandtab " Convert tabs to spaces (safer for consistent rendering)
set autoindent " Copy indent from current line when starting a new one
set smartindent " Smarter indentation for C-like languages
" --- Search ---
set incsearch " Search as you type (incremental)
set hlsearch " Highlight all search matches
set ignorecase " Ignore case when searching...
set smartcase " ...unless you type a capital letter
" --- Behavior ---
set backspace=indent,eol,start " Make backspace work as expected over autoindent, line breaks, and start of insert
set history=1000 " increase command history limit
set autoread " Automatically reload files changed outside Vim
set nobackup " Prevent creation of backup files (~) to reduce clutter
set noswapfile " Prevent creation of swap files (.swp) - optional, use with care
" --- Key Mappings ---
let mapleader = "," " Set Leader key to comma
" Press <Leader> + Enter to clear search highlighting
nnoremap <leader><CR> :nohlsearch<CR>
" Quick save with <Leader>w
nnoremap <leader>w :w<CR>
" --- Dumb Auto-Pairs ---
" 1. Auto-close brackets and quotes
inoremap ( ()<Left>
inoremap [ []<Left>
inoremap { {}<Left>
" inoremap " ""<Left>
" inoremap ' ''<Left>
" 2. Smart handling for Enter inside braces (optional but very useful)
" When you type {<Enter>, it expands to:
" {
" |
" }
inoremap {<CR> {<CR>}<Esc>ko
" 3. Allow typing over the closing bracket (Semi-Smart)
" This prevents getting "())" if you manually type the closing bracket.
" It checks if the next character is the closing bracket; if so, it just moves right.
inoremap <expr> ) strpart(getline('.'), col('.')-1, 1) == ")" ? "\<Right>" : ")"
inoremap <expr> ] strpart(getline('.'), col('.')-1, 1) == "]" ? "\<Right>" : "]"
inoremap <expr> } strpart(getline('.'), col('.')-1, 1) == "}" ? "\<Right>" : "}"
" --- Window Navigation ---
" 1. Move between splits using Ctrl + h, j, k, l (bypassing Ctrl+w)
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" 2. Seamless Vim & Tmux Navigation
function! TmuxMove(direction, tmux_flag)
let l:old_win = winnr()
execute 'wincmd ' . a:direction
" If window didn't change and we are in a tmux session, switch tmux pane
if l:old_win == winnr() && !empty($TMUX)
call system('tmux select-pane -' . a:tmux_flag)
endif
endfunction
nnoremap <silent> <C-h> :call TmuxMove('h', 'L')<CR>
nnoremap <silent> <C-j> :call TmuxMove('j', 'D')<CR>
nnoremap <silent> <C-k> :call TmuxMove('k', 'U')<CR>
nnoremap <silent> <C-l> :call TmuxMove('l', 'R')<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment