This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Description: Find a file in the current directory or in its parent directories (e.g. ".gitignore"). | |
| # Usage: find_file_parent_dirs ".gitignore" | |
| # Author: James Cherti | |
| # URL: https://gist.github.com/jamescherti/9c129c5621a9899ff7c9f3192855cce3 | |
| # License: MIT | |
| find_file_parent_dirs() { | |
| local filename="$1" | |
| local error=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Language: Vim script | |
| " Description: Change the current working directory to the directory of the current buffer. | |
| " Author: James Cherti | |
| " URL: https://gist.github.com/jamescherti/238f5876c71c9be39801535f5a12a292 | |
| " License: MIT | |
| function! ChdirBufferDir() abort | |
| if &buftype !=# '' | |
| echo printf('The buffer type ''%s'' is not supported.', &buftype) | |
| return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Config file: Add lines to ~/.inputrc | |
| " Description: Add hjkl bindings to ~/.inputrc | |
| " (used by the readline and command line | |
| " shells bash, sh...). | |
| " Alt-h: left | |
| " Alt-j: down | |
| " Alt-k: up | |
| " Alt-j: right | |
| " Author: James Cherti | |
| " GitHub Gist: https://gist.github.com/jamescherti/3b6582c6079ba80e55c9927021d1edc5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Language: Vim script | |
| " Description: Unfold a line and move the cursor to the start of the fold. | |
| " Author: James Cherti | |
| " URL: https://gist.github.com/jamescherti/c8c4d54f9d823cc574f337ad463c78ad | |
| " License: MIT | |
| function! s:unfold_move_to_start_fold(unfold_mapping) abort | |
| let l:first_line_fold = foldclosed('.') | |
| let l:last_line_fold = foldclosedend('.') | |
| if l:first_line_fold !=# -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Language: Vim script | |
| " Description: Create aliases for Vim built-in commands. | |
| " The function uses abbreviations (cnoreabbrev) | |
| " to get around this limitation. | |
| " Author: James Cherti | |
| " URL: https://gist.github.com/jamescherti/4693568eae7f9b87a56903f942487e75 | |
| " License: MIT | |
| function! CmdAlias(cmd, ...) abort | |
| for l:alias in a:000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Language: Vim script | |
| " Description: Return the path to viminfo. | |
| " Author: James Cherti | |
| " URL: https://gist.github.com/jamescherti/3651dfc40aac4181f01fffad4095094e | |
| " License: MIT | |
| function! VimInfoPath() abort | |
| if &viminfofile | |
| return fnamemodify(&viminfofile, ':p') | |
| endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # License: MIT | |
| # Author: James Cherti | |
| # URL: https://gist.github.com/jamescherti/30b5c80a1dd64d6327bb36ac3c956312 | |
| """Escape the characters that occur in a string.""" | |
| def escape(string: str, chars: str): | |
| """Escape the characters in 'chars' that occur in 'string'.""" | |
| result = "" | |
| for char in string: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # License: MIT | |
| # Author: James Cherti | |
| # URL: https://gist.github.com/jamescherti/981306ca16f92115a57796e1ae3d241d | |
| """Escape all characters.""" | |
| import re | |
| def escape_all(string: str): | |
| """Escape all characters.""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Language: Vim script | |
| " Description: a function that returns the MIME type of a file | |
| " (UNIX / Linux only). | |
| " Author: James Cherti | |
| " URL: https://gist.github.com/jamescherti/c7d92a3679f87438c72ffaa3a79b9f21 | |
| " License: MIT | |
| function! MimeType(filename) abort | |
| if !executable('file') | |
| throw 'No ''file'' in ' . $PATH |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Language: Vim script | |
| " Description: Save all modified files when the focus is lost. | |
| " Author: James Cherti | |
| " URL: https://gist.github.com/jamescherti/14a87b56e6e72e8eccd90e7d28cb73f1 | |
| " License: MIT | |
| function! SaveAll() abort | |
| let s:confirm = &confirm | |
| try | |
| set noconfirm |