Skip to content

Instantly share code, notes, and snippets.

@ffledgling
Created August 22, 2013 20:04
Show Gist options
  • Save ffledgling/6312095 to your computer and use it in GitHub Desktop.
Save ffledgling/6312095 to your computer and use it in GitHub Desktop.
Reference vimrc 2 Credits -- Sanidhya Kashyap, IIIT Hyderabad.
"""""""""""""""""""""""""""""""""""""""""""""""""""""
" General Settings -
"""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set the indent length as 3
set shiftwidth=4
" Defining how many undo's can be done in vim at a time
set undolevels=5000
set tabstop=4
set softtabstop=4
" Don't expand tab to spaces
set noexpandtab
" Allow the user of arrow keys for cursor navigation
set esckeys
" Set the file format to unix
set fileformat=unix
" Give smoother output, assuming we have a fast network connection
set ttyfast
" Make vim less vi compatible so that the default is set to better options
set nocompatible
" Set the shell to bash
set shell=/bin/bash
" This helps in copying source code from outside URL
set pastetoggle=<F9>
" Switch on the syntax for every file type automatically
syntax enable
" Set the expansion key as <tab>, just like bash command completion.
set wildchar=<tab>
" Don't go too far down the lane ;)
set scrolloff=5
" This function will automatically give execute permissions to the file
" while saving it ( if its a script I.E. first line starts with a '#!' )
function AddExecPerm()
let line = getline(1)
if strpart(line, 0, 2) == "#!"
call system("chmod +x ". expand("%"))
endif
endfunction
autocmd BufWritePost * :call AddExecPerm()
" After using the underlined function, the tab is much more smart
" TAB will be used to complete while typing words, else it will insert usual
" tab.
function! TabOrComplete()
if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
return "\<C-N>"
else
return "\<Tab>"
endfunction
inoremap <Tab> <C-R>=TabOrComplete()<CR>
" Changing sessionoptions will change the effect of the mksession command. Now
" we can customize what all information we want to store associated with a
" current session.
set sessionoptions=blank,buffers,curdir,folds,globals,help,localoptions,options,resize,tabpages,winsize,winpos
" Find C++ header files
set path+=/usr/include/c++/4.4
" Compile using the appropriate make program
map <silent> <F3> :w<CR> :make<CR><CR>
map <F2> :cn<CR>
"Show matching braces
set showmatch
""""""""""""""""""""""""""""""""""""""""""""""""
" Search settings -
""""""""""""""""""""""""""""""""""""""""""""""""
" Use extended regular expressions in search patterns -
set magic
" search the word at the same time its typed ( no <Enter> required )
set incsearch
" ignore case while matching for the search criteria
set ignorecase
" if the search pattern contains upper case letters, then make the search
" case sensitive
set smartcase
" Search will continue from the top when hitting bottom
set wrapscan
" this function is a better way of toggling highlight search ..
" by pressing Ctrl-H the highlighting of search results will be toggled .
function ToggleHLSearch()
if &hls
set nohls
else
set hls
endif
endfunction
command! ToggleHighLightSearch call ToggleHLSearch()
nmap <c-h> :ToggleHighLightSearch<cr>
""""""""""""""""""""""""""""""""""""""""""""""""
" Vim User Interface
""""""""""""""""""""""""""""""""""""""""""""""""
" Set the number of screen lines for the command line as 2
set cmdheight=2
" Show the current curser position
set ruler
" Allows backspacing over indentation, end of line and start of line
set backspace=indent,eol,start
" We won't go to the start of line with page-up or page-down keys.
set nostartofline
" No sound or visual errors -
" Vim plays sound or blinks screen if some errors happen
set noerrorbells
set novisualbell
set t_vb=
" synmaxcol denotes the maximum column to look for syntax items,
" by setting this, we can avoid very slow redrawing when there are very long
" lines
set synmaxcol=20000
" Setting up the colors settings of the popup menu, while editing the files in
" terminal. Pmenu represents the items in the menu, and PmenuSel represents
" the selected item.
highlight Pmenu ctermfg=Brown ctermbg=LightGray
highlight PmenuSel ctermfg=LightGreen ctermbg=DarkGray
" Display settings ->
" lastline When included, as much as possible of the last line
" in a window will be displayed. When not included, a
" last line that doesn't fit is replaced with "@" lines.
" uhex Show unprintable characters hexadecimal as <xx>
" instead of using ^C and ~C.
set display+=lastline
set display+=uhex
" Highlight *ALL* the changes
set report=0
" Always show the status line, Even when editing only 1 file.
set laststatus=2
" Setting a better command completion menu in vim
set wildmenu
set wildmode=list:longest,full
" Hide the mouse pointer as characters are typed
set mousehide
" Always display uncompleted command.
set showcmd
" Keep track of 10000 last commands
set history=10000
" Show the current mode of editing
set showmode
" When using split, the new window will be placed below the original one.
set splitbelow
" When using vsplit, the new window will be placed right to the original one.
set splitright
" Listings pause when the whole screen is filled and then the more prompt
" comes.
set more
" The mouse will work in all modes now
set mouse=a " the mouse will work in all modes now.
" Vim should give greetings whenever you open a file or close it
autocmd VimEnter * echo "a tinge of beauty is a joy forever!!"
autocmd BufNewFile *.c r ~/.Code/template.c
autocmd BufEnter *.c set makeprg=gcc\ %\ -Wall
autocmd BufEnter *.tex set makeprg=pdflatex\ %
"autocmd BufEnter *.java set makeprg=javac\ %
autocmd BufNewFile *.cpp r ~/.Code/template.cpp
autocmd BufEnter *.cpp set makeprg=g++\ %\ -Wall
"autocmd BufEnter *.py set makeprg=python\ %
autocmd BufNewFile *.cc r ~/.Code/template.cpp
autocmd BufEnter *.cc set makeprg=g++\ %\ -Wall
""""""""""""""""""""""""""
" Keyboard Shortcuts
""""""""""""""""""""""""""
"ctrl-n for new blank file in split mode ..
nmap <c-n> :new<cr>
" use <F6> to cycle through split windows .. and <shift>+<F6> to cycle backwards .. ( wherever possible .. )
nnoremap <F6> <C-W>w
nnoremap <S-F6> <C-W>W
" This is setting keyboard shortcuts for tabbed editing, quite cool trick.
map <C-Right> :tabnext<cr>
map <C-Left> :tabprevious<cr>
map <C-w> :tabclose<cr>
"""""""""""""""""""""""""
" Abbreviations
"""""""""""""""""""""""""
" the Date command of linux can be imported in a file also ..
" using this command whenever you type date in a file and press enter or space
" this date will change in the with the correct time in the standard format ...
iab _date_ <c-r>=strftime("%a %b %d %T %Z %Y")<cr>
iab odate <c-r>=strftime("%d:%m:%y")<cr>
iab otime <c-r>=strftime("%H:%M:%S")<cr>
iab ydt <c-r>=strftime("%y%m%d %T")<cr>
" personel abbreviations
" typing mistakes
iab teh the
iab adn and
iab sanidhay sanidhya
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Spelling and Grammer
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" This function will be used to toggle spell check from on to off.
" We need to switch on the spell checking first
set spell spelllang=
function ToggleSpellCheck()
if &spelllang == "en"
set spelllang=
else
set spelllang=en
endif
endfunction
command! ToggleSpellChecking call ToggleSpellCheck()
"""""""""""""""""""""""""""""""""
" Viminfo Settings
"""""""""""""""""""""""""""""""""
if has("viminfo")
if filewritable(expand("$HOME/.vim/viminfo")) == 1 ||
\ filewritable(expand("$HOME/.vim/")) == 2
set viminfo=!,%,'5000,\"10000,:10000,/10000,n~/.vim/viminfo
else
set viminfo=
endif
endif
""""""""""""""""""""""""""""""""""""""
" File Type Specific settings
"""""""""""""""""""""""""""""""""""""
" Vim to recognize the fileytpe and put appropriate plugins and settings
filetype plugin indent on
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Folding
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable folding.
"set foldmethod=indent
" Recognize .rkt files as scheme source
if version >= 600
au BufNewFile,BufRead *.rkt set filetype=scheme
endif
"highlight OverLength ctermbg=red ctermfg=white guibg=#592929
"match OverLength /\%81v.\+/
" enabling solarized colors
set background=dark
colorscheme solarized
"source cscope_maps.vim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment