日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

pythonide机制_强化vim打造python的IDE

發布時間:2025/3/20 python 15 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pythonide机制_强化vim打造python的IDE 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、手動安裝vim

原因:構建出支持python的vim。

wget https://github.com/vim/vim/archive/master.zip

unzip master.zip

cd vim-master/

./configure --with-features=huge --enable-pythoninterp --enable-rubyinterp --with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu --enable-gui=gtk2 --enable-cscope --prefix=/usr

說明:

/usr/lib/python2.7/config-x86_64-linux-gnu是python-dev(ubuntu叫python-dev,其他系統可能叫python-devel,區別所在)安裝后的路徑。cd 到自己的python安裝目錄下,看下config*形式的基本就是。

–enable-pythoninterp、–enable-rubyinterp、–enable-perlinterp、–enable-luainterp 等分別表示支持 ruby、python編寫的插件,–enable-gui=gtk2 表示生成采用 GNOME2 風格的 gvim,–enable-cscope 支持 cscope。

執行上述命令,會提示系統缺失哪些必要環境。如我的:

checking for tgetent in -ltinfo... no

checking for tgetent in -lncurses... no

checking for tgetent in -ltermlib... no

checking for tgetent in -ltermcap... no

checking for tgetent in -lcurses... no

no terminal library found

checking for tgetent()... configure: error: NOT FOUND!

You need to install a terminal library; for example ncurses.

Or specify the name of the library with --with-tlib.

說我缺失tgetent,舉例說ncurses是一種tgetent,那么我就安裝它,百度后知道ncurses-devel包即可,ubuntu的命名規則自然使用:

sudo apt-get install ncurses-dev

然后再繼續剛才的安裝步驟,執行:

sudo make

sudo make install

構建完成之后執行:

vim

:echo has('python')

若輸出 1 則表示構建出的 vim 已支持 python,反之,0 則不支持。

2、vim的配置

vim的配置主要包括2個內容:

- .vimrc 文件

- .vim文件夾

是在用戶目錄下的2個隱藏文件。.vimrc 主管配置,是控制 vim 行為的配置文件,位于 ~/.vimrc,不論 vim 窗口外觀、顯示字體,還是操作方式、快捷鍵、插件屬性均可通過編輯該配置文件將 vim 調教成最適合你的編輯器。

.vimrc 常用的幾類基本配置:

文件類型偵測。允許基于不同語言加載不同插件(如,C++ 的語法高亮插件與 python 的不同):

" 開啟文件類型偵測

filetype on

" 根據偵測到的不同類型加載對應的插件

filetype plugin on

快捷鍵。把 vim(非插件)常用操作設定成快捷鍵,提升效率:

" 定義快捷鍵到行首和行尾

nmap LB 0

nmap LE $

" 設置快捷鍵將選中文本塊復制至系統剪貼板

vnoremap y "+y

" 設置快捷鍵將系統剪貼板內容粘貼至 vim

nmap p "+p

" 定義快捷鍵關閉當前分割窗口

nmap q :q

" 定義快捷鍵保存當前窗口內容

nmap w :w

" 定義快捷鍵保存所有窗口內容并退出 vim

nmap WQ :wa:q

" 不做任何保存,直接退出 vim

nmap Q :qa!

" 依次遍歷子窗口

nnoremap nw

" 跳轉至右方的窗口

nnoremap lw l

" 跳轉至左方的窗口

nnoremap hw h

" 跳轉至上方的子窗口

nnoremap kw k

" 跳轉至下方的子窗口

nnoremap jw j

" 定義快捷鍵在結對符之間跳轉

nmap M %

其他。搜索、vim 命令補全等設置:

" 開啟實時搜索功能

set incsearch

" 搜索時大小寫不敏感

set ignorecase

" 關閉兼容模式

set nocompatible

" vim 自身命令行模式智能補全

set wildmenu

.vim主要是存放各種插件。

.vim/ 目錄是存放所有插件的地方。vim 有一套自己的腳本語言 vimscript,通過這種腳本語言可以實現與 vim 交互,達到功能擴展的目的。一組 vimscript 就是一個 vim 插件,vim 的很多功能都由各式插件實現。vim.org 和 github.com 有豐富的插件資源,任何你想得到的功能,如果 vim 無法直接支持,那一般都有對應的插件為你服務,有需求時可以去逛逛。

vim 插件目前分為 .vim 和.vba 兩類,前者是傳統格式的插件,實際上就是一個文本文件,通常 someplugin.vim(插件腳本)與 someplugin.txt(插件幫助文件)并存在一個打包文件中,解包后將 someplugin.vim 拷貝到 ~/.vim/plugin/ 目錄,someplugin.txt 拷貝到 ~/.vim/doc/ 目錄即可完成安裝,重啟 vim 后剛安裝的插件就已經生效,但幫助文件需執行 :helptags ~/.vim/doc/ 才能生效,可通過 :h someplugin 查看插件幫助信息。

目前插件管理使用的vim的插件管理插件 vundle。

3、插件管理

使用vundle 接管 .vim/ 下的所有原生目錄,所以先清空該目錄,再通過如下命令安裝 vundle:

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

接下來在 .vimrc 增加相關配置信息:

" vundle 環境設置

filetype off

set rtp+=~/.vim/bundle/Vundle.vim

" vundle 管理的插件列表必須位于 vundle#begin() 和 vundle#end() 之間

call vundle#begin()

Plugin 'VundleVim/Vundle.vim'

Plugin 'altercation/vim-colors-solarized'

" 插件列表結束

call vundle#end()

filetype plugin indent on

其中,每項

Plugin 'altercation/vim-colors-solarized'

對應一個插件(這與 go 語言管理不同代碼庫的機制類似),后續若有新增插件,只需追加至該列表中即可。vundle 支持源碼托管在 https://github.com/ 的插件,具體而言,仍以 ctrlsf.vim 為例,它在 .vimrc 中配置信息為 dyng/ctrlsf.vim,vundle 很容易構造出其真實下載地址 https://github.com/dyng/ctrlsf.vim.git ,然后借助 git 工具進行下載及安裝。

此后,需要安裝插件,先找到其在 github.com 的地址,再將配置信息其加入 .vimrc 中的call vundle#begin() 和 call vundle#end() 之間,最后進入 vim 執行

:PluginInstall

要卸載插件,先在 .vimrc 中注釋或者刪除對應插件配置信息,然后在 vim 中執行:

:PluginClean

即可刪除對應插件。插件更新頻率較高,差不多每隔一個月你應該看看哪些插件有推出新版本,批量更新,只需執行

:PluginUpdate

4、python IDE的配置

"vundle

set nocompatible

filetype off

set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()

Plugin 'VundleVim/Vundle.vim'

"git interface

Plugin 'tpope/vim-fugitive'

"filesystem

Plugin 'scrooloose/nerdtree'

Plugin 'jistr/vim-nerdtree-tabs'

Plugin 'kien/ctrlp.vim'

"html

" isnowfy only compatible with python not python3

Plugin 'isnowfy/python-vim-instant-markdown'

Plugin 'jtratner/vim-flavored-markdown'

Plugin 'suan/vim-instant-markdown'

Plugin 'nelstrom/vim-markdown-preview'

"python sytax checker

Plugin 'nvie/vim-flake8'

Plugin 'vim-scripts/Pydiction'

Plugin 'vim-scripts/indentpython.vim'

Plugin 'scrooloose/syntastic'

"auto-completion stuff

"Plugin 'klen/python-mode'

Plugin 'Valloric/YouCompleteMe'

Plugin 'klen/rope-vim'

"Plugin 'davidhalter/jedi-vim'

Plugin 'ervandew/supertab'

""code folding

Plugin 'tmhedberg/SimpylFold'

"Colors!!!

Plugin 'altercation/vim-colors-solarized'

Plugin 'jnurmine/Zenburn'

call vundle#end()

filetype plugin indent on " enables filetype detection

let g:SimpylFold_docstring_preview = 1

"autocomplete

let g:ycm_autoclose_preview_window_after_completion=1

"custom keys

let mapleader=" "

map g :YcmCompleter GoToDefinitionElseDeclaration

"

call togglebg#map("")

"colorscheme zenburn

"set guifont=Monaco:h14

let NERDTreeIgnore=['\.pyc$', '\~$'] "ignore files in NERDTree

"I don't like swap files

set noswapfile

"turn on numbering

set nu

"python with virtualenv support

py << EOF

import os.path

import sys

import vim

if 'VIRTUA_ENV' in os.environ:

project_base_dir = os.environ['VIRTUAL_ENV']

sys.path.insert(0, project_base_dir)

activate_this = os.path.join(project_base_dir,'bin/activate_this.py')

execfile(activate_this, dict(__file__=activate_this))

EOF

"it would be nice to set tag files by the active virtualenv here

":set tags=~/mytags "tags for ctags and taglist

"omnicomplete

autocmd FileType python set omnifunc=pythoncomplete#Complete

"------------Start Python PEP 8 stuff----------------

" Number of spaces that a pre-existing tab is equal to.

au BufRead,BufNewFile *py,*pyw,*.c,*.h set tabstop=4

"spaces for indents

au BufRead,BufNewFile *.py,*pyw set shiftwidth=4

au BufRead,BufNewFile *.py,*.pyw set expandtab

au BufRead,BufNewFile *.py set softtabstop=4

" Use the below highlight group when displaying bad whitespace is desired.

highlight BadWhitespace ctermbg=red guibg=red

" Display tabs at the beginning of a line in Python mode as bad.

au BufRead,BufNewFile *.py,*.pyw match BadWhitespace /^\t\+/

" Make trailing whitespace be flagged as bad.

au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/

" Wrap text after a certain number of characters

au BufRead,BufNewFile *.py,*.pyw, set textwidth=100

" Use UNIX (\n) line endings.

au BufNewFile *.py,*.pyw,*.c,*.h set fileformat=unix

" Set the default file encoding to UTF-8:

set encoding=utf-8

" For full syntax highlighting:

let python_highlight_all=1

syntax on

" Keep indentation level from previous line:

autocmd FileType python set autoindent

" make backspaces more powerfull

set backspace=indent,eol,start

"Folding based on indentation:

autocmd FileType python set foldmethod=indent

"use space to open folds

nnoremap za

"----------Stop python PEP 8 stuff--------------

"js stuff"

autocmd FileType javascript setlocal shiftwidth=2 tabstop=2

在vim中執行:

:PluginInstall

總結

以上是生活随笔為你收集整理的pythonide机制_强化vim打造python的IDE的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。