Skip to content

Instantly share code, notes, and snippets.

View manasthakur's full-sized avatar

Manas Thakur manasthakur

View GitHub Profile
@manasthakur
manasthakur / grepping.md
Last active September 24, 2022 13:30
Vim: Creating your own ack.vim/ag.vim

Creating your own ag.vim

Vim provides built-in mechanisms to search through projects in the form of the grep command. However, on large projects, grep is known to be slow; and hence people have been switching to simpler searchers like ack, and faster, parallel (metal?) searchers like ag and pt. Correspondingly, several plugins have been created that integrate these tools in vim: ack.vim, ag.vim, etc.

However, it's actually very easy to get the functionalities these plugins provide (faster search, results in quickfix-window, jumps, previews, and so on) in vanilla Vim itself; in fact, Vim already populates the grep-search results in a quickfix window. We just need to tell Vim to do the following things (use-case: ag):

  • Use ag as the default grep program
  • Open quickfix window by default
  • Create mappin
@manasthakur
manasthakur / plugins.md
Last active June 2, 2024 07:29
Managing plugins in Vim

Managing plugins in Vim: The basics

Let's say the plugin is at a GitHub URL https://github.com/manasthakur/foo. First get the plugin by either cloning it (git clone https://github.com/manasthakur.foo.git) or simply downloading it as a zip (from its GitHub page).

Adding a plugin in Vim is equivalent to adding the plugin's code properly into its runtimepath (includes the $HOME/.vim directory by default). For example, if the layout of a plugin foo is as follows:

foo/autoload/foo.vim
foo/plugin/foo.vim
@manasthakur
manasthakur / submodules.md
Last active October 17, 2024 08:11
Using git submodules to version-control Vim plugins

Using git-submodules to version-control Vim plugins

If you work across many computers (and even otherwise!), it's a good idea to keep a copy of your setup on the cloud, preferably in a git repository, and clone it on another machine when you need. Thus, you should keep the .vim directory along with your .vimrc version-controlled.

But when you have plugins installed inside .vim/bundle (if you use pathogen), or inside .vim/pack (if you use Vim 8's packages), keeping a copy where you want to be able to update the plugins (individual git repositories), as well as your vim-configuration as a whole, requires you to use git submodules.

Creating the repository

Initialize a git repository inside your .vim directory, add everything (including the vimrc), commit and push to a GitHub/BitBucket/GitLab repository:

cd ~/.vim
@manasthakur
manasthakur / latex-fold.vim
Last active March 20, 2017 04:31
Expression-based folding for latex files in vim
function! MyFoldLevel(lnum)
let cur_line = getline(a:lnum)
" Fold sections at level 1
if cur_line =~ '^\s*\\section'
return '>1'
endif
" Fold subsections at level 2
if cur_line =~ '^\s*\\subsection'
@manasthakur
manasthakur / better-global-searches.md
Last active March 26, 2017 17:25
Hassle-free buffer-local searches in vim

Listing pattern-matches in the current file

Option 1: The :global command

We can search for a pattern in the current file and list out the matching lines using the powerful global command:

:g[lobal]/pattern/#
@manasthakur
manasthakur / solus.md
Last active February 4, 2018 11:45
Solus, I owe you one!

Solus, I owe you one!

I am a relatively experienced Linux user -- started with Ubuntu 8.04 LTS in late 2009 as part of the labs in my undergrad institute. Various technology magazines made me a distro hopper in 2011.

Eight years with Ubuntu

When I stabilized back to Ubuntu, I started getting familiar with bash-script, learnt building unavailable packages, and became an ardent Vimmer. In 2012 I ditched Windows completely and started using Ubuntu 10.04 as the standalone OS on my Dell Studio 1450 laptop. That was a liberating experience -- no startup errors, superfast bootup, no antivirus scans -- awesome! When I got my new Lenovo laptop in 2014, I vowed to always keep my machine a Linux box.

@manasthakur
manasthakur / vim.md
Created August 7, 2017 07:24
A curated list of my Vim plugins and gists
@manasthakur
manasthakur / search-no-comments.vim
Last active January 13, 2018 14:03
Search ignoring commented text
" Function to skip commented text while searching
function! SearchNoComments(pattern)
let l:matchpos = getpos('.')
let l:fileOver = []
while search(a:pattern, 'w') > 0
if l:fileOver == []
let l:fileOver = getpos('.')
elseif l:fileOver == getpos('.')
" Break if we are back to where we started
break