Skip to content

Instantly share code, notes, and snippets.

View romainl's full-sized avatar
💰
Alwayz Into Somethin'

Romain Lafourcade romainl

💰
Alwayz Into Somethin'
  • Razorfish France
  • Paris, France
View GitHub Profile
@romainl
romainl / isdiff.vim
Created August 13, 2016 12:24
Diff detection in vimscript
" this should echo '1' when entering 'diff mode' and '0' otherwise
function! IsDiff(opt)
let isdiff = 0
if v:progname =~ "diff"
let isdiff = isdiff + 1
endif
if &diff == 1
@romainl
romainl / Vim_pushing_built-in_features_beyond_their_limits.markdown
Last active June 25, 2025 10:55
Vim: pushing built-in features beyond their limits

Vim: pushing built-in features beyond their limits

The situation

Searching can be an efficient way to navigate the current buffer.

The first search commands we learn are usually / and ?. These are seriously cool, especially with the incsearch option enabled which lets us keep typing to refine our search pattern. / and ? really shine when all we want is to jump to something we already have our eyeballs on but they are not fit for every situation:

  • when we want to search something that's not directly there, those two commands can make us lose context very quickly,
  • when we need to compare the matches.
@romainl
romainl / apprentice.md
Last active April 6, 2023 07:11
Apprentice — The Making Of

WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP WIP

Looking for the perfect colorscheme is no doubt part of everyone's experience with text editors and IDEs. For the luckiest among us, that perfect colorscheme will be the one enabled by default or the one that everyone on the internet seems to use. For the less lucky, the quest can be long and eventually lead them to actually build their own "perfect" colorscheme.

As a budding vimmer, it did not take long for me to start looking around for a nice colorscheme. I started my journey with that huge colorscheme test page that crashed so many browsers for so many years. Then, noticing that it did not have every colorscheme, I turned to the scripts section of vim.org and spent too much time looking at too many screenshots and installing too many colorschemes…

vim.org is where I eventually found a bea

@romainl
romainl / guessindent.vim
Created May 7, 2017 10:53 — forked from adscriven/guessindent.vim
Vim: guess indentation
" [email protected] 2017-05-07. Public domain.
" From vimrc. Usual caveats apply. Comparable in effectiveness to
" DetectIndent and Sleuth in practice, IME. Different trade-offs.
" This works better for code rather than for arbitrarily formatted
" files such as the help files, though it sometimes gets those right
" too. If somebody has used set noet ts=4 in a file that should be
" et sw=4, there's no easy way to detect that. You'll probably get
" ts=8 in that situation. But the file will need fixing anyway.
@romainl
romainl / redir.md
Last active January 2, 2025 00:36
Redirect the output of a Vim or external command into a scratch buffer

Redirect the output of a Vim or external command into a scratch buffer

Usage (any shell)

Show full output of command :hi in scratch window:

:Redir hi

Show full output of command :!ls -al in scratch window:

@romainl
romainl / breakhere.vim
Created May 26, 2017 09:13
Universal opposite of J
function! BreakHere()
s/^\(\s*\)\(.\{-}\)\(\s*\)\(\%#\)\(\s*\)\(.*\)/\1\2\r\1\4\6
call histdel("/", -1)
endfunction
nnoremap <key> :<C-u>call BreakHere()<CR>
@romainl
romainl / ccr.vim
Last active November 9, 2024 21:06
Make various list-like commands more intuitive
" Background here: https://gist.github.com/romainl/047aca21e338df7ccf771f96858edb86
" with help from https://github.com/teoljungberg
function! CCR()
let cmdline = getcmdline()
let filter_stub = '\v\C^((filt|filte|filter) .+ )*'
command! -bar Z silent set more|delcommand Z
if getcmdtype() !~ ':'
return "\<CR>"
endif
@romainl
romainl / paste.vim
Last active February 28, 2025 02:58
Sharing is caring
" Mac OS X (requires curl)
" ------------------------
command! -range=% SP <line1>,<line2>w !curl -F 'sprunge=<-' http://sprunge.us | tr -d '\n' | pbcopy
command! -range=% CL <line1>,<line2>w !curl -F 'clbin=<-' https://clbin.com | tr -d '\n' | pbcopy
command! -range=% VP <line1>,<line2>w !curl -F 'text=<-' http://vpaste.net | tr -d '\n' | pbcopy
command! -range=% PB <line1>,<line2>w !curl -F 'c=@-' https://ptpb.pw/?u=1 | tr -d '\n' | pbcopy
command! -range=% IX <line1>,<line2>w !curl -F 'f:1=<-' http://ix.io | tr -d '\n' | pbcopy
command! -range=% EN <line1>,<line2>w !curl -F 'file=@-;' https://envs.sh | tr -d '\n' | pbcopy
command! -range=% XO <line1>,<line2>w !curl -F 'file=@-' https://0x0.st | tr -d '\n' | pbcopy
command! -range=% TB <line1>,<line2>w !nc termbin.com 9999 | tr -d '\n' | pbcopy
@romainl
romainl / pseudo-text-objects.md
Last active March 3, 2025 06:04
Custom pseudo-text objects

This is a list of custom pseudo-text objects for Vim.

Note the use of "pseudo", here. Conceptually, text object are "special" motions but there is no proper mechanism dedicated to creating text objects, specifically. We are left with the generic mechanism succinctly described under the easy-to-miss :help omap-info.

Writing one's own pseudo-text objects and motions is a great way to extend Vim without perverting its nature ;-).


My Vim-related gists.