vim | vimrc

.vimrc setup

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
" Enable syntax highlighting for better code readability
syntax on

" Display the current mode (e.g., INSERT, NORMAL) in the status line
set showmode

" Set file encoding to UTF-8 for broad character support
set encoding=utf-8

" Enable 256-color support for terminals (useful for modern terminals)
set t_Co=256

" Set the number of spaces a tab character represents
set tabstop=4

" Set the number of spaces for indentation (e.g., when using >> or <<)
set shiftwidth=4

" Convert tabs to spaces for consistent indentation
set expandtab

" Enable auto-indentation to match the previous line's indent level
set autoindent
" Enable smart indentation for language-specific indent rules (e.g., C, Python)
set smartindent

" Disable list mode (prevents showing special characters like tabs or EOL)
set nolist

" Display line numbers for easier navigation
set number
" Optional: Enable relative line numbers for faster jumping (e.g., 5j to move 5 lines down)
" set relativenumber

" Enable paste mode to prevent auto-indent issues when pasting text
set paste

" Highlight matching parentheses, brackets, or braces
set showmatch

" Automatically add a header to new Python and shell scripts
autocmd BufNewFile *.py,*.sh exec ":call SetTitle()"

func SetTitle()
if expand("%:e") == 'sh'
call setline(1,"#!/bin/bash")
call setline(2,"")
call setline(3,"#------------------------------------------------#")
call setline(4,"# Author: wpsze")
call setline(5,"# Email: wpsze@gmail.com")
call setline(6,"# File: ".expand("%"))
call setline(7,"# Date: ".strftime("%Y-%m-%d %H:%M:%S"))
call setline(8,"# Version: 0.0 ")
call setline(9,"# Description: The purpose of the script")
call setline(10,"# Copyright (C): ".strftime("%Y")." All rights reserved")
call setline(11,"#------------------------------------------------#")
call setline(12,"")
call setline(13,"set -e # stop the shell on first error")
call setline(14,"set -u # fail when using an undefined variable")
call setline(15,"set -x # echo script lines as they are executed")
call setline(16,"set -o pipefail")
call setline(17,"")
call setline(18,"")
call setline(19, "source /home/wpsze/micromamba/etc/profile.d/micromamba.sh")
call setline(20, "micromamba activate venv")
call setline(21, "export SCRIPT_DIR=\x22$( cd \x22$( dirname \x22${BASH_SOURCE[0]}\x22 )\x22 >/dev/null 2>&1 && pwd )\x22")
call setline(22,"")
call setline(23,"")
elseif expand("%:e") == 'py'
call setline(1, "#!/bin/python")
call setline(2, "# -*- coding: utf-8 -*-")
call setline(3, "#------------------------------------------------#")
call setline(4, "# Author: wpsze")
call setline(5, "# Email: wpsze@gmail.com")
call setline(6, "# File: ".expand("%"))
call setline(7, "# Date: ".strftime("%Y-%m-%d %H:%M:%S"))
call setline(8, "# Version: 0.0 ")
call setline(9, "# Description: The purpose of the script")
call setline(10,"# Copyright (C): ".strftime("%Y")." All rights reserved")
call setline(11,"#------------------------------------------------#")
call setline(12, "")
endif
endfunc

" Move cursor to the end of the file for new files
autocmd BufNewFile * normal G

" --- Additional Suggestions:

" Improve search functionality
set incsearch " Incremental search (highlight as you type)
set hlsearch " Highlight all search matches
set ignorecase " Case-insensitive search
set smartcase " Case-sensitive search if query contains uppercase letters
" Clear search highlights with <Esc>
" nnoremap <Esc> :noh<CR><Esc>

" Enable file type detection and plugin/indent support
" filetype plugin indent on

" Set a more informative status line
set laststatus=2
set statusline=%F%m%r%h%w\ [%Y]\ [Line:\ %l/%L][%p%%]\ [Col:\ %c]

vim | vimrc
https://waipangsze.github.io/2023/10/20/vim/
Author
wpsze
Posted on
October 20, 2023
Updated on
May 21, 2025
Licensed under