Fixing Vim Macros for Python in .exrc File

  • Thread starter GreenLRan
  • Start date
  • Tags
    Python
In summary, The conversation is about setting up a macro in vim's .exrc file to run python3 code when typing # in normal mode. The first line of the .exrc file is edited but when trying to open a .py file in vim, an error is received. Suggestions such as using @ instead of # and using "map" instead of "set" are made.
  • #1
GreenLRan
61
0
Hi, I am trying set a macro in vim's .exrc file such that when I type # in normal mode, vim will call python3 to run my code. I edited the first line of the .exrc file (which is all i need to do i believe), however when i try to open my .py code in vim I get this message:

ubuntu@ubuntu:~$ vim programs/name.py
Error detected while processing /home/ubuntu/.exrc:
line 1:
E518: Unknown option: #
Press ENTER or type command to continue

Thanks in advance!
Nick





.exrc CODE:

set # :!clear;python3 %

syntax enable
set nocompatible " use vim extensions

" Bells
set visualbell t_vb= " turn off error beep/flash
set novisualbell " turn off visual bell

" Editing info
"set number "[same as nu] show line numbers
set ruler "[same as ru] show cursor position
set showmode "[same as smd] show when in insert mode

" Search
set hlsearch " highlight searches
"set incsearch " do incremental searching

" Auxilary files
set nobackup " do not keep a backup file (ending in ~)
set noswapfile " do not write a swap file

" Smart editing
set showmatch "[same as sm] highlight matching (), {}, etc.
set nowrap " do not wrap lines

" Tabs and Indenting
set autoindent "[same as ai] always set autoindenting on
set shiftwidth=4 "[same as sw] number of spaces to (auto)indent
set tabstop=4 "[same as ts] number of spaces per tab
set expandtab "[same as et] use spaces instead of a tab
set softtabstop=4 "[same as sts] number of spaces to use instead of a tab
set smarttab "[same as sta] <BS> deletes shiftwidth spaces from the start of a line

" Syntax highlighting
syntax enable
 
Technology news on Phys.org
  • #2
I think # is a reserved word in execrc files - you generally use @ instead
 
  • #3
I get the same error when I try @. That can't be it.
 
  • #4
FIXED! should have been map instead of set
 

1. Why do my Vim macros not work in my .exrc file for Python?

Vim macros are designed to work within the Vim editor, but they may not work in other contexts, such as a .exrc file. This is because the .exrc file uses different syntax and commands than Vim, so the macros may not be recognized or executed properly.

2. How can I fix my Vim macros for Python in my .exrc file?

To fix your Vim macros for use in a .exrc file, you will need to convert them to use the correct syntax and commands. This may involve using different key mappings or referencing different functions. You can also consult the .exrc file documentation for more information on how to use macros in this context.

3. Can I use Vim macros in my .exrc file for other languages besides Python?

Yes, Vim macros can be used in .exrc files for other languages as well. However, you may need to adjust the macros to use the correct syntax and commands for that specific language. This may involve referencing different functions or using different key mappings.

4. Are there any alternative methods for automating tasks in a .exrc file besides using Vim macros?

Yes, there are other methods for automating tasks in a .exrc file. One option is to use shell commands, which can be executed using the "!" command in Vim. Another option is to use external scripts or plugins specifically designed for use with .exrc files.

5. How can I troubleshoot issues with my Vim macros in my .exrc file?

If you are experiencing issues with your Vim macros in a .exrc file, you can try debugging the macros by using the "echo" command to display the output of each step. You can also consult the .exrc file documentation or seek assistance from the Vim community for further troubleshooting guidance.

Similar threads

  • Programming and Computer Science
Replies
16
Views
3K
  • Programming and Computer Science
Replies
3
Views
307
  • Computing and Technology
Replies
8
Views
2K
  • Programming and Computer Science
Replies
1
Views
936
  • Programming and Computer Science
Replies
20
Views
1K
Replies
15
Views
5K
  • Programming and Computer Science
Replies
18
Views
5K
  • Programming and Computer Science
Replies
2
Views
3K
  • Computing and Technology
Replies
15
Views
4K
  • Programming and Computer Science
Replies
19
Views
3K
Back
Top