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 / vim_barebones.sh
Created March 24, 2020 02:12
Starting vim with minimal settings
vim -N --cmd 'set rtp=$VIM,$VIMRUNTIME,$VIM/after' -U NONE -u <(echo 'set rtp+=~/.vim/bundle/vim-signature')
@kshenoy
kshenoy / rgf.sh
Last active December 15, 2018 01:00
Wrapper around ripgrep which adds a --files-from option similar to ack
#!/usr/bin/env bash
#
# Provides a --files-from option: rgf --files-from=[-|FILELIST]
# The list of files to be searched is specified in FILELIST and must be separated by newlines.
# If FILELIST is "-", the list is loaded from standard input.
# This option may be specified multiple times.
#
# Note that this affects how the -t option is applied. When --files-from is specified,
# -t is used to filter the list of files and then ripgrep searches for PATTERN on the list of filtered files
#
@kshenoy
kshenoy / par_jump.vim
Last active March 13, 2021 13:42
Paragraph Jumper to land on non-blank lines
function! ParJump(dir, ...)
" Description: Paragraph jumping to land on non-blank lines
" Arguments:
" dir = 1 : Search forward for the last line of the current paragraph or first line of the next one
" 0 : Search backward for the first line of the current paragraph or last line of the next one
" a:1 : Output of visualmode()
" TODO:
" * Cursor doesn't stay in the same column in Visual mode
let l:curr_line = line('.')
@kshenoy
kshenoy / CapsUnlocked.ahk
Created June 12, 2015 07:37
Use CapsLock as Control/Escape in Windows
; This is a complete solution to map the CapsLock key to Control and Escape without losing the ability to toggle CapsLock
; We use two tools here - any remapping software to map CapsLock to LControl and AutoHotkey to execute the following script
; This has been tested with MapKeyboard (by Inchwest)
; This will allow you to
; * Use CapsLock as Escape if it's the only key that is pressed and released within 300ms (this can be changed below)
; * Use CapsLock as LControl when used in conjunction with some other key or if it's held longer than 300ms
; * Toggle CapsLock by pressing LControl/CapsLock + RControl
~*LControl::
@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 / 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 / ScrollBind.vim
Last active December 17, 2015 19:39
Function to toggle/enable/disable scrollbind for a set of open window splits
function! ScrollBind(...)
" Description: Toggle scrollbind amongst window splits
" Arguments: 'mode' ( optional ) If not given, toggle scrollbind
" = 0 - Disable scrollbind
" 1 - Enable scrollbind
let l:curr_bufnr = bufnr('%')
let g:scb_status = ( a:0 > 0 ? a:1 : !exists('g:scb_status') || !g:scb_status )
if !exists('g:scb_pos') | let g:scb_pos = {} | endif
let l:loop_cont = 1
@kshenoy
kshenoy / MethodJump.vim
Last active December 17, 2015 19:39
Function to jump to start/end of next/prev method. Basically jumps to { and }. Similar to ]], [[ and ]m, ]M etc. but more useful and convenient to use.
function! MethodJump( dir, pos )
" Description: Jump to next/previous start/end of method
" Arguments:
" dir = 'next' - Jump to next instance
" 'prev' - Jump to previous instance
" pos = 'start' - Jump to start of method
" 'end' - Jump to end of method
let curr_search = @/
let curr_hlsearch = &hlsearch
let curr_wrapscan = &wrapscan
@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 )
@kshenoy
kshenoy / FoldText.vim
Last active April 21, 2019 06:03
Function to set the foldtext
function! FoldText()
" Description: Folding configuration
let nucolwidth = &fdc + &number*&numberwidth
let winwidth = winwidth(0) - nucolwidth - 3
let foldlinecount = foldclosedend(v:foldstart) - foldclosed(v:foldstart) + 1
let dashtext = strpart(string(v:folddashes),1,len(string(v:folddashes))-2)
let foldinfo = "+" . dashtext . " Fold: " . string(v:foldlevel) . ", " . string(foldlinecount) . " lines "
let firstline = strpart(getline(v:foldstart), 0 , winwidth - len(foldinfo))
let fillcharcount = winwidth - len(firstline) - len(foldinfo)
return firstline . repeat(" ",fillcharcount) . foldinfo