vimrc

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules

commit 6cb2d530cca2e30b17011fd9cd2f051971e51eb0
parent e0cf4c1dc465e252001831ed01e0cb8d0a6e27ea
Author: Pablo Cárdenas <pablo.cardenas@imca.edu.pe>
Date:   Tue, 31 Oct 2023 17:59:15 -0500

Update ultisnippets and ftplugins

Diffstat:
M.gitmodules | 3+++
MUltiSnips/python.snippets | 217++++++++-----------------------------------------------------------------------
AUltiSnips/python/click.snippets | 7+++++++
AUltiSnips/python/gymnasium.snippets | 34++++++++++++++++++++++++++++++++++
AUltiSnips/python/manim.snippets | 16++++++++++++++++
AUltiSnips/python/matplotlib.snippets | 4++++
AUltiSnips/python/numpy.snippets | 7+++++++
AUltiSnips/python/pandas.snippets | 6++++++
AUltiSnips/python/pygame.snippets | 42++++++++++++++++++++++++++++++++++++++++++
AUltiSnips/python/pyside.snippets | 49+++++++++++++++++++++++++++++++++++++++++++++++++
AUltiSnips/python/torch.snippets | 29+++++++++++++++++++++++++++++
AUltiSnips/python/win32clipboard.py | 5+++++
MUltiSnips/tex.snippets | 31+++++++++++++++++++++++++++++++
Aftplugin/asm.vim | 1+
Mftplugin/markdown.vim | 2+-
Mftplugin/python.vim | 7++++---
Mftplugin/r.vim | 5+++--
Mftplugin/svg.vim | 2+-
Apack/pablo/start/vim-indent-object | 1+
Dplugin/pablo/vimux.vim | 39---------------------------------------
20 files changed, 266 insertions(+), 241 deletions(-)

diff --git a/.gitmodules b/.gitmodules @@ -34,3 +34,6 @@ [submodule "pack/pablo/start/vim-commentary"] path = pack/pablo/start/vim-commentary url = https://github.com/tpope/vim-commentary.git +[submodule "pack/pablo/start/vim-indent-object"] + path = pack/pablo/start/vim-indent-object + url = https://github.com/michaeljsmith/vim-indent-object.git diff --git a/UltiSnips/python.snippets b/UltiSnips/python.snippets @@ -3,17 +3,20 @@ snippet #! "#!/usr/bin/env python" b $0 endsnippet + snippet ifmain "ifmain" b if __name__ == "__main__": ${1:${VISUAL:main()}} endsnippet + snippet with "with" b with ${1:expr}`!p snip.rv = " as " if t[2] else ""`${2:var}: ${3:${VISUAL:pass}} $0 endsnippet + snippet for "for loop" b for ${1:item} in ${2:iterable}: ${3:${VISUAL:pass}} @@ -208,98 +211,20 @@ class ${3:MyClass}: var_3: str endsnippet + snippet namedtuple "namedtuple" b ${1:MyNamedTuple} = namedtuple("$1", (${2:"attr1", "attr2"})) $0 endsnippet -# --------------------------------------------- # - -snippet np "import numpy as np" b -import numpy as np -from numpy.random import default_rng - -np.set_printoptions(linwidth=80, edgeitems=3) -$0 -endsnippet - -snippet plt "import matplotlib.pyplot as plt" b -import matplotlib.pyplot as plt -$0 -endsnippet - -snippet torch "import torch" b -import torch -import torch.nn as nn -import torch.optim as optim -import torch.nn.functional as F -$0 -endsnippet - -# --------------------------------------------- # - -snippet device "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')" b -device = torch.device("cuda" if not torch.cuda.is_available() else "cpu") -endsnippet - -snippet no_grad "with torch.no_grad()" b -with torch.no_grad(): - ${0:${VISUAL:pass}} -endsnippet - -snippet loss "zero_grad, backward, step" b -loss = criterion(${3:input}, ${4:target}) -optimizer.zero_grad() -loss.backward() -# nn.utils.clip_grad_norm_(${1:model}.parameters(), max_norm=${2:1}) -# nn.utils.clip_grad_value_($1.parameters(), clip_value=$2) -optimizer.step() -$0 -endsnippet - -snippet gym "gym loop" b -from itertools import count - -import gymnasium as gym - - -env = gym.make("${1:CartPole-v1}"`!p -snip.rv = ', render_mode="' if t[2] else "" -`${2:human}`!p -snip.rv = '"' if t[2] else "" -`) - -for episode in count(): - observation, info = env.reset(`!p snip.rv = "seed=" if t[3] else ""`${3:42}) - - for t in count(): - # Select an action - action = env.action_space.sample() - - # Perform action in the enviroment - next_observation, reward, terminated, truncated, info = env.step( - action - ) - - $0 - - if terminated or truncated: - break - observation = next_observation - - print(f"{episode=}, {t+1=}") - -env.close() -endsnippet - -# --------------------------------------------- # snippet if "If" b if ${1:condition}: ${2:${VISUAL:pass}} endsnippet + snippet ife "If / Else" b if ${1:condition}: ${2:${VISUAL:pass}} @@ -307,6 +232,7 @@ else: ${3:pass} endsnippet + snippet ifee "If / Elif / Else" b if ${1:condition}: ${2:${VISUAL:pass}} @@ -316,58 +242,6 @@ else: ${5:pass} endsnippet -snippet pygame "pygame template" b -import pygame - -pygame.init() -width, height = 640, 360 -screen = pygame.display.set_mode((width, height)) - -pygame.font.init() -font = pygame.font.Font(None, 20) - -clock = pygame.time.Clock() -running = True -dt = 0 - -player_pos = pygame.Vector2(width / 2, height / 2) - -while running: - for event in pygame.event.get(): - if event.type == pygame.QUIT: - running = False - - - keys = pygame.key.get_pressed() - if keys[pygame.K_k]: - player_pos.y -= 300 * dt - if keys[pygame.K_j]: - player_pos.y += 300 * dt - if keys[pygame.K_h]: - player_pos.x -= 300 * dt - if keys[pygame.K_l]: - player_pos.x += 300 * dt - - screen.fill("purple") - pygame.draw.circle(screen, "red", player_pos, 40) - text = font.render("Hello world", True, "white") - screen.blit(text, player_pos) - pygame.display.flip() - - dt = clock.tick(60) / 1000 - -pygame.quit() -endsnippet - - -snippet clickio "Click command for input/output" b -@click.command() -@click.argument("input", type=click.File("r"), default="-") -@click.argument("output", type=click.File("w"), default="-") -def main(input, output): - ${0:${VISUAL:pass}} -endsnippet - snippet initpkg "Init file for package" b """${1:project_name} @@ -378,11 +252,13 @@ ${2:project_description} __version__ = "${3:0.1}" endsnippet + snippet ppe "ProcessPoolExecutor" b with concurrent.futures.ProcessPoolExecutor(max_workers=${1:4}) as executor: ${0:emap or cfac} endsnippet + snippet tpe "ThreadPoolExecutor" b with concurrent.futures.ThreadPoolExecutor(max_workers=${1:4}) as executor: ${0:emap or cfac} @@ -416,13 +292,6 @@ $0 endsnippet -snippet iterrows "pandas iterrows bucle" b -for i_$1, row_$1 in $2.iterrows(): - ${3:${VISUAL:pass}} -$0 -endsnippet - - snippet tempdir "tempfile.TemporaryDirectory()" b with tempfile.TemporaryDirectory() as ${1:tmpdirname}: ${2:${VISUAL:pass}} @@ -437,69 +306,27 @@ with zipfile.ZipFile(${1:zip_path},"r") as zip_ref: endsnippet -snippet pyside "pyside" b -import sys -from PySide6.QtWidgets import QApplication - - -app = QApplication(sys.argv) - -${0:${VISUAL:# ...}} - -sys.exit(app.exec()) -endsnippet - - -snippet QWidget "QWidget" b -from PySide6.QtWidgets import QWidget - -class ${1:MyWidget}(QWidget): - def __init__(self): - super().__init__() - - self.hello = ['uno', 'dos', 'tres'] - self.button = QPushButton('Click me!') - self.text = QLabel("Hello World") - - self.layout = QVBoxLayout() - self.layout.addWidget(self.text) - self.layout.addWidget(self.button) - - self.setLayout(self.layout) - - self.button.clicked.connect(self.magic) - - def magic(self): - self.text.setText(random.choice(self.hello)) +snippet ET "xml.etree.ElementTree" b +tree = ET.parse(${1:path}) +${2:root} = tree.getroot() endsnippet -snippet QUILoader "QUILoader" b -from PySide6.QtUiTools import QUiLoader -from PySide6.QtCore import QFile - -ui_file = QFile(${1:"mainwindow.ui"}) -ui_file.open(QFile.ReadOnly) - -loader = QUiLoader() -window = loader.load(ui_file) -ui_file.close() -window.show() +snippet printf "print(f'{value=}')" b +print(f"{${1:value}=}") endsnippet -snippet ET "xml.etree.ElementTree" b -tree = ET.parse(${1:path}) -${2:root} = tree.getroot() +snippet importlib "import file" b +spec = importlib.util.spec_from_file_location(${1:module_name}, ${2:file_path}) +${3:module} = importlib.util.module_from_spec(spec) +spec.loader.exec_module($3) +$0 endsnippet -snippet win32clipboard "win32clipboard" b -win32clipboard.OpenClipboard() -clipboard = win32clipboard.GetClipboardData() -win32clipboard.CloseClipboard() -endsnippet - -snippet printf "print(f'{value=}')" b -print(f"{${1:value}=}") +snippet argparse "argparse" b +parser = argparse.ArgumentParser() +parser.add_argument(${1:"arg1"}) +args = parser.parse_args() endsnippet diff --git a/UltiSnips/python/click.snippets b/UltiSnips/python/click.snippets @@ -0,0 +1,7 @@ +snippet clickio "Click command for input/output" b +@click.command() +@click.argument("input", type=click.File("r"), default="-") +@click.argument("output", type=click.File("w"), default="-") +def main(input, output): + ${0:${VISUAL:pass}} +endsnippet diff --git a/UltiSnips/python/gymnasium.snippets b/UltiSnips/python/gymnasium.snippets @@ -0,0 +1,34 @@ +snippet gym "gym loop" b +from itertools import count + +import gymnasium as gym + + +env = gym.make("${1:CartPole-v1}"`!p +snip.rv = ', render_mode="' if t[2] else "" +`${2:human}`!p +snip.rv = '"' if t[2] else "" +`) + +for episode in count(): + observation, info = env.reset(`!p snip.rv = "seed=" if t[3] else ""`${3:42}) + + for t in count(): + # Select an action + action = env.action_space.sample() + + # Perform action in the enviroment + next_observation, reward, terminated, truncated, info = env.step( + action + ) + + $0 + + if terminated or truncated: + break + observation = next_observation + + print(f"{episode=}, {t+1=}") + +env.close() +endsnippet diff --git a/UltiSnips/python/manim.snippets b/UltiSnips/python/manim.snippets @@ -0,0 +1,16 @@ +snippet scene "Manim scene" b +class ${1:DefaultScene}(Scene): + def construct(self): + ${0:${VISUAL:pass}} +endsnippet + +snippet tempconfig "Manim tempconfig" b +with tempconfig( + { + "quality": "low_quality", + "preview": True, + } +): + scene = ${1:DefaultScene}() + scene.render() +endsnippet diff --git a/UltiSnips/python/matplotlib.snippets b/UltiSnips/python/matplotlib.snippets @@ -0,0 +1,4 @@ +snippet plt "import matplotlib.pyplot as plt" b +import matplotlib.pyplot as plt +$0 +endsnippet diff --git a/UltiSnips/python/numpy.snippets b/UltiSnips/python/numpy.snippets @@ -0,0 +1,7 @@ +snippet np "import numpy as np" b +import numpy as np +from numpy.random import default_rng + +np.set_printoptions(linwidth=80, edgeitems=3) +$0 +endsnippet diff --git a/UltiSnips/python/pandas.snippets b/UltiSnips/python/pandas.snippets @@ -0,0 +1,6 @@ +snippet iterrows "pandas iterrows bucle" b +for i_$1, row_$1 in $2.iterrows(): + ${3:${VISUAL:pass}} +$0 +endsnippet + diff --git a/UltiSnips/python/pygame.snippets b/UltiSnips/python/pygame.snippets @@ -0,0 +1,42 @@ +snippet pygame "pygame template" b +import pygame + +pygame.init() +width, height = 640, 360 +screen = pygame.display.set_mode((width, height)) + +pygame.font.init() +font = pygame.font.Font(None, 20) + +clock = pygame.time.Clock() +running = True +dt = 0 + +player_pos = pygame.Vector2(width / 2, height / 2) + +while running: + for event in pygame.event.get(): + if event.type == pygame.QUIT: + running = False + + + keys = pygame.key.get_pressed() + if keys[pygame.K_k]: + player_pos.y -= 300 * dt + if keys[pygame.K_j]: + player_pos.y += 300 * dt + if keys[pygame.K_h]: + player_pos.x -= 300 * dt + if keys[pygame.K_l]: + player_pos.x += 300 * dt + + screen.fill("purple") + pygame.draw.circle(screen, "red", player_pos, 40) + text = font.render("Hello world", True, "white") + screen.blit(text, player_pos) + pygame.display.flip() + + dt = clock.tick(60) / 1000 + +pygame.quit() +endsnippet diff --git a/UltiSnips/python/pyside.snippets b/UltiSnips/python/pyside.snippets @@ -0,0 +1,49 @@ +snippet pyside "pyside" b +import sys +from PySide6.QtWidgets import QApplication + + +app = QApplication(sys.argv) + +${0:${VISUAL:# ...}} + +sys.exit(app.exec()) +endsnippet + + +snippet QWidget "QWidget" b +from PySide6.QtWidgets import QWidget + +class ${1:MyWidget}(QWidget): + def __init__(self): + super().__init__() + + self.hello = ['uno', 'dos', 'tres'] + self.button = QPushButton('Click me!') + self.text = QLabel("Hello World") + + self.layout = QVBoxLayout() + self.layout.addWidget(self.text) + self.layout.addWidget(self.button) + + self.setLayout(self.layout) + + self.button.clicked.connect(self.magic) + + def magic(self): + self.text.setText(random.choice(self.hello)) +endsnippet + + +snippet QUILoader "QUILoader" b +from PySide6.QtUiTools import QUiLoader +from PySide6.QtCore import QFile + +ui_file = QFile(${1:"mainwindow.ui"}) +ui_file.open(QFile.ReadOnly) + +loader = QUiLoader() +window = loader.load(ui_file) +ui_file.close() +window.show() +endsnippet diff --git a/UltiSnips/python/torch.snippets b/UltiSnips/python/torch.snippets @@ -0,0 +1,29 @@ +snippet torch "import torch" b +import torch +import torch.nn as nn +import torch.optim as optim +import torch.nn.functional as F +$0 +endsnippet + + +snippet device "device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')" b +device = torch.device("cuda" if not torch.cuda.is_available() else "cpu") +endsnippet + + +snippet no_grad "with torch.no_grad()" b +with torch.no_grad(): + ${0:${VISUAL:pass}} +endsnippet + + +snippet loss "zero_grad, backward, step" b +loss = criterion(${3:input}, ${4:target}) +optimizer.zero_grad() +loss.backward() +# nn.utils.clip_grad_norm_(${1:model}.parameters(), max_norm=${2:1}) +# nn.utils.clip_grad_value_($1.parameters(), clip_value=$2) +optimizer.step() +$0 +endsnippet diff --git a/UltiSnips/python/win32clipboard.py b/UltiSnips/python/win32clipboard.py @@ -0,0 +1,5 @@ +snippet win32clipboard "win32clipboard" b +win32clipboard.OpenClipboard() +clipboard = win32clipboard.GetClipboardData() +win32clipboard.CloseClipboard() +endsnippet diff --git a/UltiSnips/tex.snippets b/UltiSnips/tex.snippets @@ -65,6 +65,27 @@ snippet table "Table environment" b \end{table} endsnippet + +snippet svg "Figure SVG" b +\begin{figure}[${1:htpb}] + \centering + \def\svgwidth{0.8\linewidth} + \import{${2:img/}}{${3:name}.pdf_tex} + \caption{${4:$3}} + \label{fig:${5:${3/\W+/-/g}}} +\end{figure} + +endsnippet + +snippet xopp "Figure Xournalpp" b +\begin{figure}[${1:htpb}] + \centering + \includegraphics[width=0.8\textwidth]{${2:img/name}_annotated.pdf} + \caption{${3:$2}} + \label{fig:${4:${2/\W+/-/g}}} +\end{figure} +endsnippet + snippet fig "Figure environment" b \begin{figure}[${1:htpb}] \centering @@ -473,6 +494,11 @@ snippet "([a-zA-Z])(bf)" "\mathcal" rA \math`!p snip.rv = match.group(2)`{`!p snip.rv = match.group(1)`}$0 endsnippet +context "math()" +snippet "([0-9a-z])(vec|hat)" "\vec hat" rA +\\`!p snip.rv = match.group(2)`{`!p snip.rv = match.group(1)`}$0 +endsnippet + # --------------------------------------------- # context "math()" @@ -508,6 +534,11 @@ snippet fun "f: A -> B" w \(${1:f}\colon ${2:X} \to ${3:\mathbb{R}}\) endsnippet +context "not math()" +snippet func "f: A -> B" w +\(${1:f}\colon ${2:X} \stackrel{C^${4:0}}{\longrightarrow} ${3:\mathbb{R}}\) +endsnippet + # --------------------------------------------- # snippet h1 "section" bA diff --git a/ftplugin/asm.vim b/ftplugin/asm.vim @@ -0,0 +1 @@ +setlocal formatprg=asmfmt diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim @@ -1 +1 @@ -set foldmethod=syntax +setlocal foldmethod=syntax diff --git a/ftplugin/python.vim b/ftplugin/python.vim @@ -1,7 +1,8 @@ setlocal formatprg=black\ -ql79\ -\ \|\ reorder-python-imports\ - setlocal makeprg=flake8\ % -map <Leader>vr :call VimuxRunCommand("clear; source venv/bin/activate; python " . bufname("%"))<CR> -map <Leader>vo :call VimuxRunCommand("clear; source venv/bin/activate; python")<CR> - setlocal foldmethod=indent +setlocal nofoldenable + +nnoremap <silent> <LocalLeader>vs :set opfunc=TmuxSendNormal<cr>g@ +vnoremap <silent> <LocalLeader>vs :call TmuxSendVisual(visualmode())<cr> diff --git a/ftplugin/r.vim b/ftplugin/r.vim @@ -1,8 +1,9 @@ -map <Leader>vr :call VimuxRunCommand("clear; Rscript " . bufname("%"))<CR> -map <Leader>vo :call VimuxRunCommand("clear; R")<CR> set softtabstop=2 set shiftwidth=2 set expandtab set cindent set formatprg=Rscript\ --vanilla\ -e\ \"suppressPackageStartupMessages(library(styler));options(styler.colored_print.vertical=FALSE);con=file(\\\"stdin\\\");style_text(readLines(con),transformers=tidyverse_style());close(con)\" + +nnoremap <silent> <LocalLeader>vs :set opfunc=TmuxSendNormal<cr>g@ +vnoremap <silent> <LocalLeader>vs :<C-u>call TmuxSendVisual(visualmode())<cr> diff --git a/ftplugin/svg.vim b/ftplugin/svg.vim @@ -1,3 +1,3 @@ setlocal softtabstop=2 setlocal shiftwidth=2 -setlocal expandtabs +setlocal expandtab diff --git a/pack/pablo/start/vim-indent-object b/pack/pablo/start/vim-indent-object @@ -0,0 +1 @@ +Subproject commit 5c5b24c959478929b54a9e831a8e2e651a465965 diff --git a/plugin/pablo/vimux.vim b/plugin/pablo/vimux.vim @@ -1,39 +0,0 @@ -" Run the current file with rspec -map <Leader>vo :call VimuxOpenRunner<CR> - -" Prompt for a command to run -map <Leader>vp :VimuxPromptCommand<CR> - -" Run last command executed by VimuxRunCommand -map <Leader>vl :VimuxRunLastCommand<CR> - -" Inspect runner pane -map <Leader>vi :VimuxInspectRunner<CR> - -" Close vim tmux runner opened by VimuxRunCommand -map <Leader>vq :VimuxCloseRunner<CR> - -" Interrupt any command running in the runner pane -map <Leader>v<C-c> :VimuxInterruptRunner<CR> - -" Zoom the runner pane (use <bind-key> z to restore runner pane) -map <Leader>vz :call VimuxZoomRunner()<CR> - -" Clear the terminal screen of the runner pane -map <Leader>v<C-l> :VimuxClearTerminalScreen<CR> - -function! VimuxSlimeNormal() - call VimuxSendText(getline('.')) - call VimuxSendKeys("Enter") -endfunction - -function! VimuxSlimeVisual() - call VimuxSendText(@v) - call VimuxSendKeys("Enter") -endfunction - -" If text is selected, save it in the v buffer and send that buffer it to tmux -vmap <LocalLeader>vs "vy :call VimuxSlimeVisual()<CR> - -" Select current paragraph and send it to tmux -nmap <LocalLeader>vs :call VimuxSlimeNormal()<CR>j