vim Emacs - sgml/signature GitHub Wiki

Vim

Troubleshooting

  • sudo apt-get install vim-gui-common
set nocompatible
" set nocompatible fixes arrow keys in insert mode

set backspace=indent,eol,start
" set backspace fix backspace in normal mode
set bs=2
" set bs fixes backspace in insert mode

set autoindent
" set autoindent preseves indentation when pasting text

set exrc

set fileformats=unix,dos,mac

nmap k 
nmap j 
nmap h 
nmap l 
imap  

Vim Script

Registration

To register the Vim script with Vim, follow these steps:

  • Save the Script: Save the Vim script (the one I provided earlier) to a file with a .vim extension. For example, you can save it as fstring_conversion.vim.

  • Open Vim: Open Vim by running vim in your terminal.

  • Edit Your .vimrc File: Add the following line to your ~/.vimrc : source /path/to/your/fstring_conversion.vim

  • Replace /path/to/your/fstring_conversion.vim with the actual path to the script file.

  • Reload Your .vimrc:

  • After saving the changes to your .vimrc file, reload it in Vim by typing: :source ~/.vimrc

Usage

  • Open your Python file in Vim.

  • Place the cursor on the line with the f-string you want to convert.

  • execute the call command with the name of the function:

    :call ConvertFStringToPercentOperator()

Visual Mode Syntax

" Find variables within f-strings and rewrite using '%'
function! ConvertFStringToPercentOperator()
    let l:line_number = 1
    while l:line_number <= line('$')
        let l:line = getline(l:line_number)
        if l:line =~# "print(f'\([^']*\)')"
            let l:variable_name = matchstr(l:line, "'\([^']*\)'")
            let l:replacement = printf("'%s: %%s'", l:variable_name)
            let l:line = substitute(l:line, "'\([^']*\)'", l:replacement, "")
            call setline(l:line_number, l:line)
        endif
        let l:line_number += 1
    endwhile
endfunction

Standalone Syntax

" Open the file
edit path/to/your/file.txt

" Search for f-strings and replace them
%s/print(f'\([^']*\): \({[^}]*}\)')/print("\1: %s", \2)/g

" Save and close the file
wq

Run it as follows:

vim -c 'source example.vim' -c 'qa'

Deletion

Delete between quotes: d/' + enter

Delete all blank lines: g/^$/d

Delete without copying: _d + d or the number of lines

Delete the first character from diff formatted code: :1,$ s/^[+]//g

Search and Replace

To Search for all line beginnings and replace them with a single quote, do the following: :%s/^/'/g

Insertion

Insert p tags into blank lines: :1,$ s/^$/

\n/g

Matching Tags

  • Place the cursor on the tag.
  • Enter visual mode by pressing v then press eiter a+t or i+t for the outer/inner tag.
  • Press o or O to jump between the tags.

Emacs

Describe Bindings

C-h b

Sample files

Cheatsheet

Overrides

References

⚠️ **GitHub.com Fallback** ⚠️