Skip to content

Instantly share code, notes, and snippets.

View kshenoy's full-sized avatar

Kartik Shenoy kshenoy

  • AMD
  • Fort Collins, CO
View GitHub Profile
@kshenoy
kshenoy / IListpp.vim
Last active August 29, 2015 13:57 — forked from dahu/gist:9718037
An unholy amalgam of [I and :ilist. This function allows to specify a pattern and then displays all lines matching that pattern and also jumps to one of the lines
function! IListpp()
let term = input("IList: /")
if term == ''
let term = expand('<cword>')
endif
let v:errmsg = ''
redir =>slist
exe 'ilist /' . term
redir END
if v:errmsg == ''
@kshenoy
kshenoy / FindAndList.vim
Created March 23, 2014 07:23
Find all the lines that contain the search term and display them in the location lis
function! myFunctions#FindAndList()
let term = input("Find: /")
let v:errmsg = ""
if term == ""
term = expand('<cword>'))
endif
if v:errmsg == ""
execute "lvimgrep! /" . term . "/ " . fnameescape(expand('%:p'))
lopen
endif
@kshenoy
kshenoy / typedef.c
Created July 12, 2012 01:34
Use of typedefs with struct and enum in C/C++
// 1a) Struct declaration and instantiation w/o typedef
struct veg_t{
int cost;
char c;
};
struct veg_t potato;
// 1b) or its equivalent with declaration and instantiation combined…
struct veg_t{
int cost;
@kshenoy
kshenoy / MapKey.vim
Last active October 7, 2015 16:37
Function to complement the maparg() function in Vim. Given the 'rhs' of a mapping, this function returns the 'lhs'
function! MapKey( rhs, mode )
" Description: Get LHS of a mapping. Inverse of maparg().
" Note that hasmapto() returns a binary result while MapKey() returns the value of the LHS.
" Pass in a key sequence and the first letter of a vim mode.
" Returns key mapping mapped to it in that mode, else '' if none.
" Eg:
" :nnoremap <Tab> :bn<CR>
" :call Mapkey(':bn<CR>', 'n')
" returns <Tab>
" TODO:
@kshenoy
kshenoy / ReTab.vim
Last active October 7, 2015 16:37
Vim function to perform easy retabs ( eg. change file with softtabstop=4 to softtabstop=2 )
function! ReTab( tabsize )
" Description: Change indentation when tab size is changed
" Primarily used to convert an indentation of eg. 4 to 2 or vice-versa
if &expandtab
let l:tabstop_old = &tabstop
let l:softtabstop_old = &softtabstop
let l:shiftwidth_old = &shiftwidth
let &tabstop = &softtabstop
set noexpandtab
" Motion for "next/last object".
" For example, 'din(' will go to the Next '()' pair and delete its contents.
" and 'dip(' will go to the Previous '()' pair and delete its contents.
onoremap an :<c-u>call <SID>NextTextObject('a', 'f')<cr>
xnoremap an :<c-u>call <SID>NextTextObject('a', 'f')<cr>
onoremap in :<c-u>call <SID>NextTextObject('i', 'f')<cr>
xnoremap in :<c-u>call <SID>NextTextObject('i', 'f')<cr>
onoremap ap :<c-u>call <SID>NextTextObject('a', 'F')<cr>
@kshenoy
kshenoy / FoldAllBut.vim
Last active December 15, 2015 18:09
Function to open folds that have less than the specified number of lines
function! FoldAllBut( foldminlines )
" Description: Function to open folds that have less than the specified number of lines
" We assume that the folds are initially closed
" If a fold exists and is closed and has lesser number of lines than specified, open it and all nested folds
" Note: This does not work on nested folds
folddoclosed
\ if (( foldclosed(".") >= 0 ) && ( foldclosedend(".") - foldclosed(".") + 1 < a:foldminlines ))
\ exe 'normal! zO'
\ endif
endfunction
" Statusline modifications, added Fugitive Status Line & Syntastic Error Message
let g:last_mode = ''
function! Mode()
let l:mode = mode()
if l:mode !=# g:last_mode
let g:last_mode = l:mode
hi User2 guifg=#005f00 guibg=#dfff00 gui=BOLD ctermfg=22 ctermbg=190 cterm=BOLD
hi User3 guifg=#FFFFFF guibg=#414243 ctermfg=255 ctermbg=241
@kshenoy
kshenoy / buffers_tabs.vim
Created May 16, 2013 19:40
Mapping to toggle between buffers and tabs
nnoremap <silent> <F8> :let notabs=!notabs<Bar>:if notabs<Bar>:tabo<Bar>:else<Bar>:tab ball<Bar>:tabn<Bar>:endif<CR>
@kshenoy
kshenoy / Preserve.vim
Last active December 17, 2015 19:39
Function to execute commands without modifying the original settings like cursor position, search string etc.
function! Preserve( command )
" Description: Function to execute commands without modifying the original settings like cursor position, search string etc.
" Save last search, and cursor position.
let currview = winsaveview()
" Do the business
silent! execute a:command
" Restore previous search history, and cursor position
call winrestview( currview )