2009-02-26 9 views
32

विम में * सामान्य मोड में कुंजी कर्सर के नीचे शब्द की खोज करता है। जीएनयू Emacs में निकटतम देशी बराबर होगा:मैं जीएनयू एमएक्स में वीम की * खोज कैसे अनुकरण कर सकता हूं?

C-s C-w 

लेकिन वह काफी समान नहीं है। यह शब्द के अंत तक वर्तमान बफर में कर्सर से वृद्धिशील खोज मिनी बफर और प्रतियां खोलता है। विम में आप पूरे शब्द की खोज करेंगे, भले ही आप शब्द के बीच में हों जब भी आप दबाएंगे *।

(defun find-word-under-cursor (arg) 
    (interactive "p") 
    (if (looking-at "\\<")() (re-search-backward "\\<" (point-min))) 
    (isearch-forward)) 

कि iSearch ऊपर फायरिंग से पहले शब्द के आरंभ में पीछे की ओर trots:

मैं इसी तरह कुछ करने के लिए elisp का एक सा ऊपर पकाया गया है। मैंने इसे सी-+ तक सीमित कर दिया है, जो मेरे कीबोर्ड पर टाइप करना आसान है और * के समान है, इसलिए जब मैं C-+ C-w टाइप करता हूं तो यह शब्द की शुरुआत से मिनी-बफर में कॉपी करता है।

हालांकि, यह अभी भी सही नहीं है। आदर्श रूप से यह आंशिक मैचों को दिखाने के लिए "\<" word "\>" के लिए खोज regexp करेगा (शब्द "बार" खोजना "foobar" से मेल नहीं होना चाहिए, केवल "बार" ही नहीं)। मैंने सर्च-फॉरवर्ड-रेगेक्सपी और कॉन्सटिंग \ <> का उपयोग करने की कोशिश की लेकिन यह फ़ाइल में लपेट नहीं है, मैचों को हाइलाइट नहीं करता है और आमतौर पर सुंदर लंगड़ा होता है। एक खोज- * फ़ंक्शन सबसे अच्छा शर्त लगता है, लेकिन लिखित होने पर ये अच्छी तरह से व्यवहार नहीं करते हैं।

कोई विचार? क्या कोई कुरकुरा करने के लिए किसी भी सुधार की पेशकश कर सकता है? या क्या कोई अन्य तरीका है जिसे मैंने अनदेखा कर दिया है?

+0

हां, Emacs आपको ऐसा करने के लिए खोज में हुक करने देता है, लेकिन हाइलाइट-प्रतीक पैकेज भी बेहतर है। मुझे अपने वर्तमान विचार प्रक्रिया के लिए केंद्रीय प्रतीकों को केंद्रीय सहायक रखने में मदद मिलती है। साथ ही, आपको एक कुंजी खोज मिलती है और आपका बिंदु प्रतीक की शुरुआत के अनुरूप निरंतर रहता है। –

+0

http://stackoverflow.com/questions/1775005/super-star-or-find-the-word-under-the-cursor-equivalent-in-emacs – Neil

उत्तर

15

मेरा पहला जवाब देने के लिए आपकी प्रतिक्रिया, कैसे इस बारे में के आधार पर:

(defun my-isearch-word-at-point() 
    (interactive) 
    (call-interactively 'isearch-forward-regexp)) 

(defun my-isearch-yank-word-hook() 
    (when (equal this-command 'my-isearch-word-at-point) 
    (let ((string (concat "\\<" 
          (buffer-substring-no-properties 
          (progn (skip-syntax-backward "w_") (point)) 
          (progn (skip-syntax-forward "w_") (point))) 
          "\\>"))) 
     (if (and isearch-case-fold-search 
       (eq 'not-yanks search-upper-case)) 
      (setq string (downcase string))) 
     (setq isearch-string string 
      isearch-message 
      (concat isearch-message 
        (mapconcat 'isearch-text-char-description 
           string "")) 
      isearch-yank-flag t) 
     (isearch-search-and-update)))) 

(add-hook 'isearch-mode-hook 'my-isearch-yank-word-hook) 
+0

अगर मुझ पर फ़ाइल में बाद में कोई मिलान नहीं है तो मुझ पर निर्भर करता है। बैकट्रैक और रेपो निर्देश [यहां] (https://gist.github.com/mgalgs/5392566)। – mgalgs

+0

यह पर चलने पर विफल रहता है। –

+0

यह पहली बार अच्छी तरह से काम करता है, लेकिन बार-बार उपयोग पर त्रुटियां देता है: 'गलत प्रकार तर्क: arrayp, nil' – Dfr

1

मैंने कोशिश नहीं की है लेकिन कुछ कोड here है जिसे Grep-O-Matic कहा जाता है।

0

इसके साथ आप खोज मोड में सी-* करने में सक्षम होना चाहिए।

 
(define-key isearch-mode-map [?\C-*] 'kmk-isearch-yank-thing) 

(defun kmk-isearch-yank-thing() 
    "Pull next thing from buffer into search string." 
    (interactive) 
    (let ((string (regexp-quote (thing-at-point 'word)))) 
    (setq isearch-string 
     (concat isearch-string "\\") 
     isearch-message 
     (concat isearch-message 
      (mapconcat 'isearch-text-char-description 
       string "")) 
     ;; Don't move cursor in reverse search. 
     isearch-yank-flag t)) 
    (setq isearch-regexp t isearch-word nil isearch-success t isearch-adjusted t) 
    (isearch-search-and-update)) 
+0

यह बहुत समान है (फ़ंक्शन में, यदि फॉर्म नहीं है) मेरे पास एक बिंदु पर क्या था - समस्या यह है कि एकाधिक उपयोग आइसर्च के साथ अच्छी तरह से नहीं खेलते हैं। सी- * को फिर से चलाने से पहले "साफ" करने के लिए कोई रास्ता नहीं है। आप खोज 1search2search3 के साथ समाप्त होकर सभी रहस्यमय तरीके से मिलते हैं। – richq

5

तरीके यह करने के लिए की बहुत सारी हैं:

http://www.emacswiki.org/emacs/SearchAtPoint

+0

जिमबैंडी का समाधान बहुत करीब है, लेकिन यह वास्तव में "खोज" नहीं करता है, यह खोज इंटरफ़ेस पर हैक्स करता है। आप पिछले/अगले पर कूद नहीं सकते हैं और बफर में शब्द संग्रहीत नहीं करते हैं। अरे! – richq

3

scottfrazer का जवाब अच्छी तरह से करने के लिए काम करता है मैं, उन शब्दों को छोड़कर जो '_' (या शायद अन्य गैर-शब्द वर्ण?) में समाप्त होते हैं। मैंने पाया कि प्रकाश प्रतीक मोड के लिए कोड emacs के संस्करण के आधार पर शब्द सीमा के लिए एक अलग रेगेक्स का उपयोग कर रहा था, और यह मेरे लिए तय किया गया। यहाँ संशोधित कोड है:

(defconst my-isearch-rx-start 
    (if (< emacs-major-version 22) 
     "\\<" 
    "\\_<") 
    "Start-of-symbol regular expression marker.") 

(defconst my-isearch-rx-end 
    (if (< emacs-major-version 22) 
     "\\>" 
    "\\_>") 
    "End-of-symbol regular expression marker.") 

(defun my-isearch-word-at-point() 
    (interactive) 
    (call-interactively 'isearch-forward-regexp)) 

(defun my-isearch-yank-word-hook() 
    (when (equal this-command 'my-isearch-word-at-point) 
    (let ((string (concat my-isearch-rx-start 
          (buffer-substring-no-properties 
          (progn (skip-syntax-backward "w_") (point)) 
          (progn (skip-syntax-forward "w_") (point))) 
          my-isearch-rx-end))) 
     (if (and isearch-case-fold-search 
       (eq 'not-yanks search-upper-case)) 
      (setq string (downcase string))) 
     (setq isearch-string string 
      isearch-message 
      (concat isearch-message 
        (mapconcat 'isearch-text-char-description 
           string "")) 
      isearch-yank-flag t) 
     (isearch-search-and-update)))) 

(add-hook 'isearch-mode-hook 'my-isearch-yank-word-hook) 
0
;Here is my version: Emulates Visual Studio/Windows key bindings 
; C-F3 - Start searching the word at the point 
; F3 searches forward and Shift F3 goes reverse 

(setq my-search-wrap nil) 

(defun my-search-func (dir) 
    (interactive) 
    (let* ((text (car search-ring)) newpoint) 
     (when my-search-wrap 
      (goto-char (if (= dir 1) (point-min) (point-max))) 
      (setq my-search-wrap nil)) 
     (setq newpoint (search-forward text nil t dir)) 
     (if newpoint 
      (set-mark (if (= dir 1) (- newpoint (length text)) 
         (+ newpoint (length text)))) 
      (message "Search Failed: %s" text) (ding) 
      (setq my-search-wrap text)))) 

(defun my-search-fwd() (interactive) (my-search-func 1)) 
(defun my-search-bwd() (interactive) (my-search-func -1)) 

(defun yank-thing-into-search() 
    (interactive) 
    (let ((text (if mark-active 
      (buffer-substring-no-properties (region-beginning)(region-end)) 
       (or (current-word) "")))) 
    (when (> (length text) 0) (isearch-update-ring text) (setq my-search-wrap nil) 
      (my-search-fwd)))) 
(global-set-key (kbd "") 'my-search-fwd)   ; Visual Studio like search keys 
(global-set-key (kbd "") 'my-search-bwd) 
(global-set-key (kbd "") 'yank-thing-into-search) 

2

कैसे अंतर्निहित आदेशों के बारे एम बी सी एस सी डब्ल्यू

+1

यह वास्तव में केवल एक ही कीस्ट्रोक जितना अच्छा नहीं है, है ना? :-) – richq

7

highlight symbol Emacs विस्तार इस सुविधा प्रदान करता है (शब्द, खोज, शब्द खोज की शुरुआत)।

(require 'highlight-symbol) 

(global-set-key [(control f3)] 'highlight-symbol-at-point) 
(global-set-key [f3] 'highlight-symbol-next) 
(global-set-key [(shift f3)] 'highlight-symbol-prev) 

पिछले प्रतीक (Shift + F3) पर जाकर या कर्सर के तहत एक मिलान प्रतीकों पर प्रकाश डाला वर्तमान बिंदु (F3) पर अगले प्रतीक पर कूद की अनुमति देता है, (Ctrl: विशेष रूप से, .emacsrc सेटअप की सलाह देते हैं + F3)। यदि आपका कर्सर मध्य-शब्द है तो आदेश सही काम करना जारी रखते हैं।

विम के सुपर स्टार के विपरीत, प्रतीकों को हाइलाइट करना और प्रतीकों के बीच कूदना दो अलग-अलग आदेशों से बंधे हैं। मैं व्यक्तिगत रूप से अलगाव को ध्यान में रखता हूं, लेकिन यदि आप विम के व्यवहार से सटीक रूप से मेल खाना चाहते हैं तो आप उसी कुंजीस्ट्रोक के नीचे दो आदेशों को बाध्य कर सकते हैं।

2

Mastering Emacs ब्लॉग के मिकी एक कूल 'Smart Scan "lib कि बफर में कर्सर के तहत प्रतीकों नेविगेट करने के लिए M-n और M-p के वैश्विक बाइंडिंग देता पुनः शुरू किया। खोज रजिस्टर को प्रभावित नहीं करता है, इसलिए यह * प्रतिस्थापन नहीं है, लेकिन नेविगेशन समस्या के लिए एक चालाक और उपयोग करने योग्य विकल्प है।

संबंधित मुद्दे

 संबंधित मुद्दे