Fix critical installation and configuration bugs

This commit addresses multiple issues discovered during code review:

1. Fix variable definition order in .vimrc
   - Move g:is_tty and g:has_true_color definitions to top of file
   - Previously used at line 32 but defined at line 263
   - Ensures variables are available before first use

2. Remove duplicate configuration settings in .vimrc
   - Remove duplicate set number, wildmenu, ruler
   - Remove duplicate search settings (ignorecase, smartcase, hlsearch, incsearch)
   - Remove duplicate backspace and wildignore settings
   - Reduces file size and eliminates confusion

3. Enhance install.sh reliability
   - Add directory validation to ensure script runs from ~/.vim
   - Add symlink validation after creation
   - Fix CoC installation command syntax (vim -c to vim +)
   - Move helper functions before usage
   - Prevents symlink-to-self errors

4. Improve installation documentation
   - Add warnings in README.md about running from correct directory
   - Add IMPORTANT notes in QUICKSTART.md
   - Update installation step descriptions
   - Prevents common user installation mistakes

These fixes improve installation reliability and prevent configuration errors.
This commit is contained in:
m1ngsama 2025-12-30 09:53:14 +08:00
parent 51ac142b39
commit 0e61537142
4 changed files with 40 additions and 48 deletions

46
.vimrc
View file

@ -10,6 +10,10 @@
" Disable compatibility with vi which can cause unexpected issues " Disable compatibility with vi which can cause unexpected issues
set nocompatible set nocompatible
" Detect terminal type and capabilities (must be early for conditional configs)
let g:is_tty = ($TERM =~ 'linux' || $TERM =~ 'screen' || &term =~ 'builtin')
let g:has_true_color = ($COLORTERM == 'truecolor' || $COLORTERM == '24bit')
" Enable type file detection. Vim will be able to try to detect the type of file in use " Enable type file detection. Vim will be able to try to detect the type of file in use
filetype on filetype on
@ -91,15 +95,6 @@ set mouse=a
" Set encoding " Set encoding
set encoding=utf-8 set encoding=utf-8
" Better command-line completion
set wildmenu
" Show cursor position
set ruler
" Display line numbers
set number
" Enable folding " Enable folding
set foldmethod=indent set foldmethod=indent
set foldlevel=99 set foldlevel=99
@ -114,42 +109,15 @@ set backspace=indent,eol,start
" Auto read when file is changed from outside " Auto read when file is changed from outside
set autoread set autoread
" Turn on the Wild menu for command completion
set wildmenu
" Ignore compiled files
set wildignore=*.o,*~,*.pyc
if has("win16") || has("win32")
set wildignore+=.git\*,.hg\*,.svn\*
else
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.DS_Store
endif
" Always show current position
set ruler
" Height of the command bar " Height of the command bar
set cmdheight=1 set cmdheight=1
" A buffer becomes hidden when it is abandoned " A buffer becomes hidden when it is abandoned
set hid set hid
" Configure backspace so it acts as it should act " Configure backspace so it acts as it should act (enhanced from earlier basic setting)
set backspace=eol,start,indent
set whichwrap+=<,>,h,l set whichwrap+=<,>,h,l
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
set smartcase
" Highlight search results
set hlsearch
" Makes search act like search in modern browsers
set incsearch
" Don't redraw while executing macros (good performance config) " Don't redraw while executing macros (good performance config)
set lazyredraw set lazyredraw
@ -259,10 +227,6 @@ call plug#end()
" => Colors and Fonts " => Colors and Fonts
" ============================================================================ " ============================================================================
" Detect terminal type and capabilities
let g:is_tty = ($TERM =~ 'linux' || $TERM =~ 'screen' || &term =~ 'builtin')
let g:has_true_color = ($COLORTERM == 'truecolor' || $COLORTERM == '24bit')
" Enable true colors support only if terminal supports it " Enable true colors support only if terminal supports it
if g:has_true_color && has('termguicolors') && !g:is_tty if g:has_true_color && has('termguicolors') && !g:is_tty
set termguicolors set termguicolors

View file

@ -10,9 +10,12 @@ Get up and running with this Vim configuration in 5 minutes!
git clone https://github.com/m1ngsama/chopsticks.git ~/.vim && cd ~/.vim && ./install.sh git clone https://github.com/m1ngsama/chopsticks.git ~/.vim && cd ~/.vim && ./install.sh
``` ```
**IMPORTANT:** Always run the install script from the `~/.vim` directory (where you cloned the repository). The script validates this to ensure correct symlink creation.
That's it! The script will: That's it! The script will:
- Verify it's being run from the correct directory
- Backup your existing .vimrc - Backup your existing .vimrc
- Create symlink to the new configuration - Create and validate symlink to the new configuration
- Install vim-plug - Install vim-plug
- Install all plugins automatically - Install all plugins automatically

View file

@ -10,7 +10,7 @@ A comprehensive, modern Vim configuration optimized for engineering workflows. T
git clone https://github.com/m1ngsama/chopsticks.git ~/.vim && cd ~/.vim && ./install.sh git clone https://github.com/m1ngsama/chopsticks.git ~/.vim && cd ~/.vim && ./install.sh
``` ```
See [QUICKSTART.md](QUICKSTART.md) for detailed getting started guide. **Note:** The installation script must be run from the cloned `~/.vim` directory. See [QUICKSTART.md](QUICKSTART.md) for detailed getting started guide.
## Features ## Features
@ -56,9 +56,13 @@ cd ~/.vim
./install.sh ./install.sh
``` ```
**IMPORTANT:** You must run the install script from the `~/.vim` directory (the cloned repository directory). Do not copy the script to another location and run it from there.
The installation script will: The installation script will:
- Verify it's being run from the correct directory
- Backup your existing configuration - Backup your existing configuration
- Create necessary symlinks - Create necessary symlinks
- Validate symlink creation
- Install vim-plug automatically - Install vim-plug automatically
- Install all plugins - Install all plugins
- Offer to install CoC language servers - Offer to install CoC language servers

View file

@ -13,10 +13,6 @@ YELLOW='\033[1;33m'
RED='\033[0;31m' RED='\033[0;31m'
NC='\033[0m' # No Color NC='\033[0m' # No Color
echo -e "${BOLD}========================================${NC}"
echo -e "${BOLD}Vim Configuration Installer${NC}"
echo -e "${BOLD}========================================${NC}\n"
# Function to print status messages # Function to print status messages
print_status() { print_status() {
echo -e "${GREEN}==>${NC} ${BOLD}$1${NC}" echo -e "${GREEN}==>${NC} ${BOLD}$1${NC}"
@ -30,6 +26,18 @@ print_error() {
echo -e "${RED}Error:${NC} $1" echo -e "${RED}Error:${NC} $1"
} }
echo -e "${BOLD}========================================${NC}"
echo -e "${BOLD}Vim Configuration Installer${NC}"
echo -e "${BOLD}========================================${NC}\n"
# Verify .vimrc exists in script directory
if [ ! -f "$SCRIPT_DIR/.vimrc" ]; then
print_error "Cannot find .vimrc in $SCRIPT_DIR"
echo "Please run this script from the chopsticks directory:"
echo " cd ~/.vim && ./install.sh"
exit 1
fi
# Check if vim is installed # Check if vim is installed
if ! command -v vim &> /dev/null; then if ! command -v vim &> /dev/null; then
print_error "Vim is not installed. Please install Vim first." print_error "Vim is not installed. Please install Vim first."
@ -52,6 +60,19 @@ fi
print_status "Creating symlink: $HOME/.vimrc -> $SCRIPT_DIR/.vimrc" print_status "Creating symlink: $HOME/.vimrc -> $SCRIPT_DIR/.vimrc"
ln -sf "$SCRIPT_DIR/.vimrc" "$HOME/.vimrc" ln -sf "$SCRIPT_DIR/.vimrc" "$HOME/.vimrc"
# Verify symlink was created correctly
if [ -L "$HOME/.vimrc" ]; then
LINK_TARGET=$(readlink "$HOME/.vimrc")
if [ "$LINK_TARGET" = "$SCRIPT_DIR/.vimrc" ]; then
echo -e "${GREEN}[OK]${NC} Symlink created successfully"
else
print_warning "Symlink points to unexpected target: $LINK_TARGET"
fi
else
print_error "Failed to create symlink"
exit 1
fi
# Install vim-plug if not already installed # Install vim-plug if not already installed
VIM_PLUG_PATH="$HOME/.vim/autoload/plug.vim" VIM_PLUG_PATH="$HOME/.vim/autoload/plug.vim"
if [ ! -f "$VIM_PLUG_PATH" ]; then if [ ! -f "$VIM_PLUG_PATH" ]; then
@ -100,7 +121,7 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
if ! command -v node &> /dev/null; then if ! command -v node &> /dev/null; then
print_error "Node.js is not installed. Please install Node.js first." print_error "Node.js is not installed. Please install Node.js first."
else else
vim -c "CocInstall -sync coc-json coc-tsserver coc-pyright coc-sh coc-html coc-css coc-yaml|q" vim +'CocInstall -sync coc-json coc-tsserver coc-pyright coc-sh coc-html coc-css coc-yaml' +qall
echo -e "${GREEN}[OK]${NC} CoC language servers installed" echo -e "${GREEN}[OK]${NC} CoC language servers installed"
fi fi
fi fi